Make sheet not include composer
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -3,3 +3,4 @@ sheetless-server
|
|||||||
sheetless.db
|
sheetless.db
|
||||||
/result
|
/result
|
||||||
/.env
|
/.env
|
||||||
|
/src/vendor/
|
||||||
|
|||||||
@@ -25,24 +25,8 @@ func UploadSheet(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
composerUUIDStr := c.PostForm("composer_uuid")
|
// TODO: create new composer with this name if it does not exist here
|
||||||
if composerUUIDStr == "" {
|
composer := c.PostForm("composer")
|
||||||
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")
|
description := c.PostForm("description")
|
||||||
|
|
||||||
// Get uploaded file
|
// Get uploaded file
|
||||||
@@ -98,15 +82,15 @@ func UploadSheet(c *gin.Context) {
|
|||||||
|
|
||||||
// Create database record
|
// Create database record
|
||||||
sheet := models.Sheet{
|
sheet := models.Sheet{
|
||||||
Uuid: *uuid,
|
Uuid: *uuid,
|
||||||
Title: title,
|
Title: title,
|
||||||
Description: description,
|
Description: description,
|
||||||
FilePath: filePath,
|
FilePath: filePath,
|
||||||
FileSize: fileInfo.Size(),
|
FileSize: fileInfo.Size(),
|
||||||
FileHash: fileHash,
|
FileHash: fileHash,
|
||||||
ComposerUuid: composer.Uuid,
|
Composer: composer,
|
||||||
CreatedAt: time.Now(),
|
CreatedAt: time.Now(),
|
||||||
UpdatedAt: time.Now(),
|
UpdatedAt: time.Now(),
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := database.DB.Create(&sheet).Error; err != nil {
|
if err := database.DB.Create(&sheet).Error; err != nil {
|
||||||
@@ -125,7 +109,7 @@ func UploadSheet(c *gin.Context) {
|
|||||||
func ListSheets(c *gin.Context) {
|
func ListSheets(c *gin.Context) {
|
||||||
var sheets []models.Sheet
|
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"})
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to fetch sheets"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,15 +8,15 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Sheet struct {
|
type Sheet struct {
|
||||||
Uuid uuid.UUID `json:"uuid" gorm:"type:uuid;primaryKey"`
|
Uuid uuid.UUID `json:"uuid" gorm:"type:uuid;primaryKey"`
|
||||||
Title string `json:"title" gorm:"not null"`
|
Title string `json:"title" gorm:"not null"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
FilePath string `json:"file_path" gorm:"not null"`
|
FilePath string `json:"file_path" gorm:"not null"`
|
||||||
FileSize int64 `json:"file_size"`
|
FileSize int64 `json:"file_size"`
|
||||||
FileHash string `json:"file_hash"`
|
FileHash string `json:"file_hash"`
|
||||||
ComposerUuid uuid.UUID `json:"composer_uuid"`
|
Composer string `json:"composer"`
|
||||||
Composer Composer `json:"composer" gorm:"foreignKey:ComposerUuid"`
|
CreatedAt time.Time `json:"created_at"`
|
||||||
CreatedAt time.Time `json:"created_at"`
|
UpdatedAt time.Time `json:"updated_at"`
|
||||||
UpdatedAt time.Time `json:"updated_at"`
|
DeletedAt gorm.DeletedAt `json:"-" gorm:"index"`
|
||||||
DeletedAt gorm.DeletedAt `json:"-" gorm:"index"`
|
Annotations string `json:"annotations"`
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user