From b82a69689d950bb901853491298caca30ba8e611 Mon Sep 17 00:00:00 2001 From: Rogee Date: Wed, 31 Dec 2025 16:01:20 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E9=9F=B3=E4=B9=90?= =?UTF-8?q?=E9=94=AE=E4=BD=8D=E5=AD=97=E6=AE=B5=EF=BC=8C=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E6=95=B0=E6=8D=AE=E7=BB=93=E6=9E=84=E5=92=8C?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/.gitignore | 2 + backend/app/http/v1/creator.go | 2 +- backend/app/http/v1/dto/creator.go | 13 +++ backend/app/services/content.go | 1 + backend/app/services/creator.go | 10 +- .../20251231120000_add_key_to_contents.sql | 6 ++ backend/database/models/contents.gen.go | 1 + backend/database/models/contents.query.gen.go | 6 +- frontend/portal/src/layout/LayoutCreator.vue | 2 +- .../src/views/creator/ContentsEditView.vue | 2 + .../portal/src/views/creator/ContentsView.vue | 95 ++++++++++--------- 11 files changed, 89 insertions(+), 51 deletions(-) create mode 100644 backend/database/migrations/20251231120000_add_key_to_contents.sql diff --git a/backend/.gitignore b/backend/.gitignore index ae3e86d..92a87e1 100644 --- a/backend/.gitignore +++ b/backend/.gitignore @@ -27,3 +27,5 @@ go.work.sum # Dependency directories (remove the comment below to include it) # vendor/ + +quyun diff --git a/backend/app/http/v1/creator.go b/backend/app/http/v1/creator.go index ee1330f..84e80d4 100644 --- a/backend/app/http/v1/creator.go +++ b/backend/app/http/v1/creator.go @@ -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) } diff --git a/backend/app/http/v1/dto/creator.go b/backend/app/http/v1/dto/creator.go index 86582aa..6dc8990 100644 --- a/backend/app/http/v1/dto/creator.go +++ b/backend/app/http/v1/dto/creator.go @@ -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"` diff --git a/backend/app/services/content.go b/backend/app/services/content.go index 74c0c0c..a84c4e7 100644 --- a/backend/app/services/content.go +++ b/backend/app/services/content.go @@ -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, } diff --git a/backend/app/services/creator.go b/backend/app/services/creator.go index a69f6a7..5e6719c 100644 --- a/backend/app/services/creator.go +++ b/backend/app/services/creator.go @@ -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, diff --git a/backend/database/migrations/20251231120000_add_key_to_contents.sql b/backend/database/migrations/20251231120000_add_key_to_contents.sql new file mode 100644 index 0000000..0b4e5b8 --- /dev/null +++ b/backend/database/migrations/20251231120000_add_key_to_contents.sql @@ -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; diff --git a/backend/database/models/contents.gen.go b/backend/database/models/contents.gen.go index 34e6a1c..2b5d324 100644 --- a/backend/database/models/contents.gen.go +++ b/backend/database/models/contents.gen.go @@ -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"` diff --git a/backend/database/models/contents.query.gen.go b/backend/database/models/contents.query.gen.go index 9467606..3da7fe0 100644 --- a/backend/database/models/contents.query.gen.go +++ b/backend/database/models/contents.query.gen.go @@ -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 } diff --git a/frontend/portal/src/layout/LayoutCreator.vue b/frontend/portal/src/layout/LayoutCreator.vue index b22aba8..6b1896f 100644 --- a/frontend/portal/src/layout/LayoutCreator.vue +++ b/frontend/portal/src/layout/LayoutCreator.vue @@ -2,7 +2,7 @@
-
+
@@ -40,7 +41,8 @@
- +
- [{{ item.genre }}] -

{{ + item.genre }} + {{ item.key + }} +

{{ item.title }}

@@ -83,16 +87,17 @@
- + - +
@@ -101,10 +106,10 @@ \ No newline at end of file