Add link support to resource creation and editing, including validation

This commit is contained in:
2025-06-24 20:19:29 +08:00
parent 167cb617b8
commit c44d71b0da
8 changed files with 185 additions and 17 deletions

View File

@@ -10,6 +10,7 @@ type Resource struct {
gorm.Model
Title string
AlternativeTitles []string `gorm:"serializer:json"`
Links []Link `gorm:"serializer:json"`
Article string
Images []Image `gorm:"many2many:resource_images;"`
Tags []Tag `gorm:"many2many:resource_tags;"`
@@ -20,6 +21,11 @@ type Resource struct {
Downloads uint
}
type Link struct {
URL string `json:"url"`
Label string `json:"label"`
}
type ResourceView struct {
ID uint `json:"id"`
Title string `json:"title"`
@@ -33,6 +39,7 @@ type ResourceDetailView struct {
ID uint `json:"id"`
Title string `json:"title"`
AlternativeTitles []string `json:"alternativeTitles"`
Links []Link `json:"links"`
Article string `json:"article"`
CreatedAt time.Time `json:"createdAt"`
Tags []TagView `json:"tags"`
@@ -84,6 +91,7 @@ func (r *Resource) ToDetailView() ResourceDetailView {
ID: r.ID,
Title: r.Title,
AlternativeTitles: r.AlternativeTitles,
Links: r.Links,
Article: r.Article,
CreatedAt: r.CreatedAt,
Tags: tags,