From 3ae2eacb6b6cd16eab3751e614327072472b2136 Mon Sep 17 00:00:00 2001 From: Julian Mutter Date: Fri, 6 Feb 2026 16:33:29 +0100 Subject: [PATCH] Make sheet not include composer --- .gitignore | 1 + src/handlers/sheets.go | 40 ++++++++++++---------------------------- src/models/sheet.go | 22 +++++++++++----------- 3 files changed, 24 insertions(+), 39 deletions(-) diff --git a/.gitignore b/.gitignore index 3360daf..928de01 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ sheetless-server sheetless.db /result /.env +/src/vendor/ diff --git a/src/handlers/sheets.go b/src/handlers/sheets.go index 03ba492..a0f50d5 100644 --- a/src/handlers/sheets.go +++ b/src/handlers/sheets.go @@ -25,24 +25,8 @@ func UploadSheet(c *gin.Context) { return } - composerUUIDStr := c.PostForm("composer_uuid") - if composerUUIDStr == "" { - c.JSON(http.StatusBadRequest, gin.H{"error": "Composer UUID is required"}) - return - } - - composerUUID, err := uuid.Parse(composerUUIDStr) - if err != nil { - c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid composer UUID"}) - return - } - - var composer models.Composer - if err := database.DB.First(&composer, composerUUID).Error; err != nil { - c.JSON(http.StatusBadRequest, gin.H{"error": "Composer not found"}) - return - } - + // TODO: create new composer with this name if it does not exist here + composer := c.PostForm("composer") description := c.PostForm("description") // Get uploaded file @@ -98,15 +82,15 @@ func UploadSheet(c *gin.Context) { // Create database record sheet := models.Sheet{ - Uuid: *uuid, - Title: title, - Description: description, - FilePath: filePath, - FileSize: fileInfo.Size(), - FileHash: fileHash, - ComposerUuid: composer.Uuid, - CreatedAt: time.Now(), - UpdatedAt: time.Now(), + Uuid: *uuid, + Title: title, + Description: description, + FilePath: filePath, + FileSize: fileInfo.Size(), + FileHash: fileHash, + Composer: composer, + CreatedAt: time.Now(), + UpdatedAt: time.Now(), } if err := database.DB.Create(&sheet).Error; err != nil { @@ -125,7 +109,7 @@ func UploadSheet(c *gin.Context) { func ListSheets(c *gin.Context) { var sheets []models.Sheet - if err := database.DB.Preload("Composer").Find(&sheets).Error; err != nil { + if err := database.DB.Find(&sheets).Error; err != nil { c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to fetch sheets"}) return } diff --git a/src/models/sheet.go b/src/models/sheet.go index 49b38b8..f9cc182 100644 --- a/src/models/sheet.go +++ b/src/models/sheet.go @@ -8,15 +8,15 @@ import ( ) type Sheet struct { - Uuid uuid.UUID `json:"uuid" gorm:"type:uuid;primaryKey"` - Title string `json:"title" gorm:"not null"` - Description string `json:"description"` - FilePath string `json:"file_path" gorm:"not null"` - FileSize int64 `json:"file_size"` - FileHash string `json:"file_hash"` - ComposerUuid uuid.UUID `json:"composer_uuid"` - Composer Composer `json:"composer" gorm:"foreignKey:ComposerUuid"` - CreatedAt time.Time `json:"created_at"` - UpdatedAt time.Time `json:"updated_at"` - DeletedAt gorm.DeletedAt `json:"-" gorm:"index"` + Uuid uuid.UUID `json:"uuid" gorm:"type:uuid;primaryKey"` + Title string `json:"title" gorm:"not null"` + Description string `json:"description"` + FilePath string `json:"file_path" gorm:"not null"` + FileSize int64 `json:"file_size"` + FileHash string `json:"file_hash"` + Composer string `json:"composer"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` + DeletedAt gorm.DeletedAt `json:"-" gorm:"index"` + Annotations string `json:"annotations"` }