feat: 添加音乐键位字段,更新相关数据结构和接口

This commit is contained in:
2025-12-31 16:01:20 +08:00
parent 984770c6a1
commit b82a69689d
11 changed files with 89 additions and 51 deletions

2
backend/.gitignore vendored
View File

@@ -27,3 +27,5 @@ go.work.sum
# Dependency directories (remove the comment below to include it)
# vendor/
quyun

View File

@@ -75,7 +75,7 @@ func (c *Creator) ListContents(
ctx fiber.Ctx,
user *models.User,
filter *dto.CreatorContentListFilter,
) ([]dto.ContentItem, error) {
) ([]dto.CreatorContentItem, error) {
return services.Creator.ListContents(ctx, user.ID, filter)
}

View File

@@ -28,6 +28,7 @@ type FloatStatItem struct {
type ContentCreateForm struct {
Title string `json:"title"`
Genre string `json:"genre"`
Key string `json:"key"`
Price float64 `json:"price"`
MediaIDs []string `json:"media_ids"`
}
@@ -35,6 +36,7 @@ type ContentCreateForm struct {
type ContentUpdateForm struct {
Title string `json:"title"`
Genre string `json:"genre"`
Key string `json:"key"`
Price float64 `json:"price"`
MediaIDs []string `json:"media_ids"`
}
@@ -43,6 +45,7 @@ type ContentEditDTO struct {
ID string `json:"id"`
Title string `json:"title"`
Genre string `json:"genre"`
Key string `json:"key"`
Description string `json:"description"`
Status string `json:"status"`
Price float64 `json:"price"`
@@ -51,6 +54,16 @@ type ContentEditDTO struct {
Assets []AssetDTO `json:"assets"`
}
type CreatorContentItem struct {
ID string `json:"id"`
Title string `json:"title"`
Genre string `json:"genre"`
Key string `json:"key"`
Views int `json:"views"`
Likes int `json:"likes"`
IsPurchased bool `json:"is_purchased"`
}
type AssetDTO struct {
ID string `json:"id"`
Role string `json:"role"`

View File

@@ -160,6 +160,7 @@ func (s *content) Get(ctx context.Context, userID int64, id string) (*content_dt
Description: item.Description,
Body: item.Body,
MediaUrls: s.toMediaURLs(accessibleAssets),
Meta: content_dto.Meta{Key: item.Key},
IsLiked: isLiked,
IsFavorited: isFavorited,
}

View File

@@ -98,7 +98,7 @@ func (s *creator) ListContents(
ctx context.Context,
userID int64,
filter *creator_dto.CreatorContentListFilter,
) ([]creator_dto.ContentItem, error) {
) ([]creator_dto.CreatorContentItem, error) {
tid, err := s.getTenantID(ctx, userID)
if err != nil {
return nil, err
@@ -122,12 +122,13 @@ func (s *creator) ListContents(
return nil, errorx.ErrDatabaseError.WithCause(err)
}
var data []creator_dto.ContentItem
var data []creator_dto.CreatorContentItem
for _, item := range list {
data = append(data, creator_dto.ContentItem{
data = append(data, creator_dto.CreatorContentItem{
ID: cast.ToString(item.ID),
Title: item.Title,
Genre: item.Genre,
Key: item.Key,
Views: int(item.Views),
Likes: int(item.Likes),
IsPurchased: false,
@@ -150,6 +151,7 @@ func (s *creator) CreateContent(ctx context.Context, userID int64, form *creator
UserID: uid,
Title: form.Title,
Genre: form.Genre,
Key: form.Key,
Status: consts.ContentStatusPublished,
}
if err := tx.Content.WithContext(ctx).Create(content); err != nil {
@@ -214,6 +216,7 @@ func (s *creator) UpdateContent(
_, err = tx.Content.WithContext(ctx).Where(tx.Content.ID.Eq(cid)).Updates(&models.Content{
Title: form.Title,
Genre: form.Genre,
Key: form.Key,
})
if err != nil {
return err
@@ -318,6 +321,7 @@ func (s *creator) GetContent(ctx context.Context, userID int64, id string) (*cre
ID: cast.ToString(c.ID),
Title: c.Title,
Genre: c.Genre,
Key: c.Key,
Description: c.Description,
Status: string(c.Status),
Price: price,

View File

@@ -0,0 +1,6 @@
-- +goose Up
ALTER TABLE contents ADD COLUMN key VARCHAR(32) DEFAULT '';
COMMENT ON COLUMN contents.key IS 'Musical key/tone';
-- +goose Down
ALTER TABLE contents DROP COLUMN key;

View File

@@ -38,6 +38,7 @@ type Content struct {
CreatedAt time.Time `gorm:"column:created_at;type:timestamp with time zone;default:now()" json:"created_at"`
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp with time zone;default:now()" json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:timestamp with time zone" json:"deleted_at"`
Key string `gorm:"column:key;type:character varying(32);comment:Musical key/tone" json:"key"` // Musical key/tone
Author *User `gorm:"foreignKey:UserID;references:ID" json:"author,omitempty"`
ContentAssets []*ContentAsset `gorm:"foreignKey:ContentID;references:ID" json:"content_assets,omitempty"`
Comments []*Comment `gorm:"foreignKey:ContentID;references:ID" json:"comments,omitempty"`

View File

@@ -44,6 +44,7 @@ func newContent(db *gorm.DB, opts ...gen.DOOption) contentQuery {
_contentQuery.CreatedAt = field.NewTime(tableName, "created_at")
_contentQuery.UpdatedAt = field.NewTime(tableName, "updated_at")
_contentQuery.DeletedAt = field.NewField(tableName, "deleted_at")
_contentQuery.Key = field.NewString(tableName, "key")
_contentQuery.Author = contentQueryBelongsToAuthor{
db: db.Session(&gorm.Session{}),
@@ -90,6 +91,7 @@ type contentQuery struct {
CreatedAt field.Time
UpdatedAt field.Time
DeletedAt field.Field
Key field.String // Musical key/tone
Author contentQueryBelongsToAuthor
ContentAssets contentQueryHasManyContentAssets
@@ -130,6 +132,7 @@ func (c *contentQuery) updateTableName(table string) *contentQuery {
c.CreatedAt = field.NewTime(table, "created_at")
c.UpdatedAt = field.NewTime(table, "updated_at")
c.DeletedAt = field.NewField(table, "deleted_at")
c.Key = field.NewString(table, "key")
c.fillFieldMap()
@@ -162,7 +165,7 @@ func (c *contentQuery) GetFieldByName(fieldName string) (field.OrderExpr, bool)
}
func (c *contentQuery) fillFieldMap() {
c.fieldMap = make(map[string]field.Expr, 22)
c.fieldMap = make(map[string]field.Expr, 23)
c.fieldMap["id"] = c.ID
c.fieldMap["tenant_id"] = c.TenantID
c.fieldMap["user_id"] = c.UserID
@@ -182,6 +185,7 @@ func (c *contentQuery) fillFieldMap() {
c.fieldMap["created_at"] = c.CreatedAt
c.fieldMap["updated_at"] = c.UpdatedAt
c.fieldMap["deleted_at"] = c.DeletedAt
c.fieldMap["key"] = c.Key
}