Improve composer management
This commit is contained in:
@@ -33,7 +33,24 @@ func UploadSheet(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
composer := c.PostForm("composer")
|
||||
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
|
||||
}
|
||||
|
||||
description := c.PostForm("description")
|
||||
|
||||
// Get uploaded file
|
||||
@@ -91,11 +108,11 @@ func UploadSheet(c *gin.Context) {
|
||||
sheet := models.Sheet{
|
||||
Uuid: *uuid,
|
||||
Title: title,
|
||||
Composer: composer,
|
||||
Description: description,
|
||||
FilePath: filePath,
|
||||
FileSize: fileInfo.Size(),
|
||||
FileHash: fileHash,
|
||||
ComposerID: composer.Uuid,
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
}
|
||||
@@ -116,7 +133,7 @@ func UploadSheet(c *gin.Context) {
|
||||
func ListSheets(c *gin.Context) {
|
||||
var sheets []models.Sheet
|
||||
|
||||
if err := database.DB.Find(&sheets).Error; err != nil {
|
||||
if err := database.DB.Preload("Composer").Find(&sheets).Error; err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to fetch sheets"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -10,11 +10,12 @@ import (
|
||||
type Sheet struct {
|
||||
Uuid uuid.UUID `json:"uuid" gorm:"type:uuid;primaryKey"`
|
||||
Title string `json:"title" gorm:"not null"`
|
||||
Composer string `json:"composer"`
|
||||
Description string `json:"description"`
|
||||
FilePath string `json:"file_path" gorm:"not null"`
|
||||
FileSize int64 `json:"file_size"`
|
||||
FileHash uint64 `json:"file_hash"`
|
||||
ComposerId uuid.UUID `json:"composer_id"`
|
||||
Composer Composer `json:"composer" gorm:"foreignKey:ComposerId"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `json:"-" gorm:"index"`
|
||||
|
||||
Reference in New Issue
Block a user