分页查询

This commit is contained in:
2024-11-05 18:42:54 +08:00
parent 13ec042ddf
commit da6913eaba
7 changed files with 178 additions and 162 deletions

View File

@@ -55,30 +55,8 @@ func (images *ImageList) ToAllUserID() (uniqueIds IDS) {
return uniqueIds
}
// 为每个图像设置用户信息
func (images *ImageList) SetUser(userList []User) {
for i, image := range *images {
for _, user := range userList {
if image.UserID == user.ID {
(*images)[i].User = user
}
}
}
}
// 为每个图像设置文章信息
func (images *ImageList) SetArticle(articleList []Article) {
for i, image := range *images {
for _, article := range articleList {
if image.ArticleID == article.ID {
(*images)[i].Article = article
}
}
}
}
type Image struct {
ID int `json:"id" db:"id"`
ID int `json:"id" db:"id" gorm:"primaryKey"`
Width int `json:"width" db:"width"`
Height int `json:"height" db:"height"`
Content string `json:"content" db:"content"`
@@ -93,9 +71,13 @@ type Image struct {
UserID int `json:"user_id" db:"user_id"`
CreateTime time.Time `json:"create_time" db:"create_time"`
UpdateTime time.Time `json:"update_time" db:"update_time"`
Text TextList `json:"text" db:"text"`
User User `json:"user" db:"-"`
Article Article `json:"article" db:"-"`
Text TextList `json:"text" db:"text" gorm:"type:json"`
User User `json:"user" gorm:"foreignKey:UserID"`
Article Article `json:"article" gorm:"foreignKey:ArticleID"`
}
func (Image) TableName() string {
return "web_images"
}
type TextList []struct {
@@ -109,7 +91,7 @@ func (a *TextList) Scan(value interface{}) error {
}
type User struct {
ID int `json:"id" db:"id"`
ID int `json:"id" db:"id" gorm:"primaryKey"`
UserName *string `json:"user_name" db:"user_name"`
Avatar *string `json:"avatar" db:"avatar"`
Rank *string `json:"rank" db:"rank"`
@@ -117,12 +99,21 @@ type User struct {
UpdateTime time.Time `json:"update_time" db:"update_time"`
}
func (User) TableName() string {
return "web_member"
}
type Article struct {
ID int `json:"id" db:"id"`
Title string `json:"title" db:"title"`
Tags string `json:"tags" db:"tags"`
CreateTime time.Time `json:"create_time" db:"create_time"`
UpdateTime time.Time `json:"update_time" db:"update_time"`
ID int `json:"id" db:"id" gorm:"primaryKey"`
Title string `json:"title" db:"title"`
Orientation string `json:"orientation" db:"orientation"`
Tags string `json:"tags" db:"tags"`
CreateTime time.Time `json:"create_time" db:"create_time"`
UpdateTime time.Time `json:"update_time" db:"update_time"`
}
func (Article) TableName() string {
return "web_article"
}
type Category struct {