mirror of
https://github.com/wgh136/nysoure.git
synced 2025-09-27 04:17:23 +00:00
Add resources_count to collection.
This commit is contained in:
@@ -4,28 +4,31 @@ import "gorm.io/gorm"
|
||||
|
||||
type Collection struct {
|
||||
gorm.Model
|
||||
Title string `gorm:"not null"`
|
||||
Article string `gorm:"not null"`
|
||||
UserID uint `gorm:"not null"`
|
||||
User User `gorm:"foreignKey:UserID;references:ID"`
|
||||
Images []Image `gorm:"many2many:collection_images;"`
|
||||
Resources []Resource `gorm:"many2many:collection_resources;"`
|
||||
Title string `gorm:"not null"`
|
||||
Article string `gorm:"not null"`
|
||||
UserID uint `gorm:"not null"`
|
||||
User User `gorm:"foreignKey:UserID;references:ID"`
|
||||
ResourcesCount int `gorm:"default:0"`
|
||||
Images []Image `gorm:"many2many:collection_images;"`
|
||||
Resources []Resource `gorm:"many2many:collection_resources;"`
|
||||
}
|
||||
|
||||
type CollectionView struct {
|
||||
ID uint `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Article string `json:"article"`
|
||||
User UserView `json:"user"`
|
||||
Images []Image `json:"images"`
|
||||
ID uint `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Article string `json:"article"`
|
||||
User UserView `json:"user"`
|
||||
ResourcesCount int `json:"resources_count"`
|
||||
Images []Image `json:"images"`
|
||||
}
|
||||
|
||||
func (c Collection) ToView() *CollectionView {
|
||||
return &CollectionView{
|
||||
ID: c.ID,
|
||||
Title: c.Title,
|
||||
Article: c.Article,
|
||||
User: c.User.ToView(),
|
||||
Images: c.Images,
|
||||
ID: c.ID,
|
||||
Title: c.Title,
|
||||
Article: c.Article,
|
||||
User: c.User.ToView(),
|
||||
ResourcesCount: c.ResourcesCount,
|
||||
Images: c.Images,
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user