mirror of
https://github.com/wgh136/nysoure.git
synced 2025-12-16 15:51:14 +00:00
Add charactor api.
This commit is contained in:
44
server/model/charactor.go
Normal file
44
server/model/charactor.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package model
|
||||
|
||||
type Charactor struct {
|
||||
ID uint `gorm:"primaryKey;autoIncrement"`
|
||||
Name string `gorm:"type:varchar(100);not null"`
|
||||
Alias []string `gorm:"serializer:json"`
|
||||
CV string `gorm:"type:varchar(100)"`
|
||||
ImageID uint
|
||||
ResourceID uint
|
||||
Image *Image `gorm:"foreignKey:ImageID;constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"`
|
||||
}
|
||||
|
||||
type CharactorView struct {
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Alias []string `json:"alias"`
|
||||
CV string `json:"cv"`
|
||||
Image uint `json:"image"`
|
||||
}
|
||||
|
||||
func (c *Charactor) ToView() *CharactorView {
|
||||
return &CharactorView{
|
||||
Id: c.ID,
|
||||
Name: c.Name,
|
||||
Alias: c.Alias,
|
||||
CV: c.CV,
|
||||
Image: c.ImageID,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Charactor) Equal(other *Charactor) bool {
|
||||
if c.Name != other.Name || c.CV != other.CV || c.ImageID != other.ImageID {
|
||||
return false
|
||||
}
|
||||
if len(c.Alias) != len(other.Alias) {
|
||||
return false
|
||||
}
|
||||
for i := range c.Alias {
|
||||
if c.Alias[i] != other.Alias[i] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
@@ -21,8 +21,9 @@ type Resource struct {
|
||||
Downloads uint
|
||||
Comments uint
|
||||
ModifiedTime time.Time
|
||||
Gallery []uint `gorm:"serializer:json"`
|
||||
GalleryNsfw []uint `gorm:"serializer:json"`
|
||||
Gallery []uint `gorm:"serializer:json"`
|
||||
GalleryNsfw []uint `gorm:"serializer:json"`
|
||||
Charactors []Charactor `gorm:"foreignKey:ResourceID"`
|
||||
}
|
||||
|
||||
type Link struct {
|
||||
@@ -40,22 +41,23 @@ type ResourceView struct {
|
||||
}
|
||||
|
||||
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"`
|
||||
Images []ImageView `json:"images"`
|
||||
Files []FileView `json:"files"`
|
||||
Author UserView `json:"author"`
|
||||
Views uint `json:"views"`
|
||||
Downloads uint `json:"downloads"`
|
||||
Comments uint `json:"comments"`
|
||||
Related []ResourceView `json:"related"`
|
||||
Gallery []uint `json:"gallery"`
|
||||
GalleryNsfw []uint `json:"galleryNsfw"`
|
||||
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"`
|
||||
Images []ImageView `json:"images"`
|
||||
Files []FileView `json:"files"`
|
||||
Author UserView `json:"author"`
|
||||
Views uint `json:"views"`
|
||||
Downloads uint `json:"downloads"`
|
||||
Comments uint `json:"comments"`
|
||||
Related []ResourceView `json:"related"`
|
||||
Gallery []uint `json:"gallery"`
|
||||
GalleryNsfw []uint `json:"galleryNsfw"`
|
||||
Charactors []CharactorView `json:"charactors"`
|
||||
}
|
||||
|
||||
func (r *Resource) ToView() ResourceView {
|
||||
@@ -94,6 +96,10 @@ func (r *Resource) ToDetailView() ResourceDetailView {
|
||||
for i, file := range r.Files {
|
||||
files[i] = *file.ToView()
|
||||
}
|
||||
charactors := make([]CharactorView, len(r.Charactors))
|
||||
for i, charactor := range r.Charactors {
|
||||
charactors[i] = *charactor.ToView()
|
||||
}
|
||||
return ResourceDetailView{
|
||||
ID: r.ID,
|
||||
Title: r.Title,
|
||||
@@ -110,5 +116,6 @@ func (r *Resource) ToDetailView() ResourceDetailView {
|
||||
Comments: r.Comments,
|
||||
Gallery: r.Gallery,
|
||||
GalleryNsfw: r.GalleryNsfw,
|
||||
Charactors: charactors,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user