Add gallery

This commit is contained in:
2025-11-01 17:12:06 +08:00
parent f84bcbdadc
commit 3e7ce7b4cd
6 changed files with 185 additions and 2 deletions

View File

@@ -21,6 +21,7 @@ type Resource struct {
Downloads uint
Comments uint
ModifiedTime time.Time
Gallery []uint `gorm:"serializer:json"`
}
type Link struct {
@@ -52,6 +53,7 @@ type ResourceDetailView struct {
Downloads uint `json:"downloads"`
Comments uint `json:"comments"`
Related []ResourceView `json:"related"`
Gallery []uint `json:"gallery"`
}
func (r *Resource) ToView() ResourceView {
@@ -104,5 +106,6 @@ func (r *Resource) ToDetailView() ResourceDetailView {
Views: r.Views,
Downloads: r.Downloads,
Comments: r.Comments,
Gallery: r.Gallery,
}
}

View File

@@ -27,6 +27,7 @@ type ResourceParams struct {
Tags []uint `json:"tags"`
Article string `json:"article"`
Images []uint `json:"images"`
Gallery []uint `json:"gallery"`
}
func CreateResource(uid uint, params *ResourceParams) (uint, error) {
@@ -62,6 +63,7 @@ func CreateResource(uid uint, params *ResourceParams) (uint, error) {
Images: images,
Tags: tags,
UserID: uid,
Gallery: params.Gallery,
}
if r, err = dao.CreateResource(r); err != nil {
return 0, err
@@ -452,6 +454,7 @@ func EditResource(uid, rid uint, params *ResourceParams) error {
r.AlternativeTitles = params.AlternativeTitles
r.Article = params.Article
r.Links = params.Links
r.Gallery = params.Gallery
images := make([]model.Image, len(params.Images))
for i, id := range params.Images {