API分页

This commit is contained in:
2024-12-02 06:53:52 +08:00
parent 520e3bade6
commit f4bec98b7a
10 changed files with 1385 additions and 1446 deletions

View File

@@ -1,11 +1,9 @@
package api
import (
"encoding/json"
"fmt"
"strconv"
"strings"
"time"
)
type IDS []int
@@ -54,160 +52,3 @@ func (images *ImageList) ToAllUserID() (uniqueIds IDS) {
}
return uniqueIds
}
type Image struct {
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"`
Remark string `json:"remark" db:"remark"`
Description string `json:"description" db:"description"`
Tags string `json:"tags" db:"tags"`
Rank string `json:"rank" db:"rank"`
CommentNum int `json:"comment_num" db:"comment_num"`
PraiseCount int `json:"praise_count" gorm:"column:praise"`
CollectCount int `json:"collect_count" db:"collect_count"`
ArticleID int `json:"article_id" db:"article_id"`
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" gorm:"type:json"`
User User `json:"user" gorm:"foreignKey:UserID"`
Article Article `json:"article" gorm:"foreignKey:ArticleID"`
Activity bool `json:"activity"`
}
func (Image) TableName() string {
return "web_images"
}
type TextList []struct {
Text string `json:"text"`
Confidence float64 `json:"confidence"`
Coordinate [][]float64 `json:"coordinate"`
}
func (a *TextList) Scan(value interface{}) error {
// 如果数据库中的值为NULL则返回nil
if value == nil || len(value.([]byte)) == 0 {
*a = TextList{}
return nil
}
return json.Unmarshal(value.([]byte), a)
}
type User struct {
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"`
Price int `json:"price" db:"price"`
CreateTime time.Time `json:"create_time" db:"create_time"`
UpdateTime time.Time `json:"update_time" db:"update_time"`
}
func (User) TableName() string {
return "web_member"
}
type Work struct {
ID int `json:"id" gorm:"primaryKey"`
Title string `json:"title"`
Orientation string `json:"orientation"`
Device string `json:"device"`
Era string `json:"era"`
Tags string `json:"tags"`
UserId int `json:"user_id"`
Content string `json:"content"`
Image string `json:"image"`
Images string `json:"images"`
User User `json:"user" gorm:"foreignKey:UserId"`
CreateTime time.Time `json:"create_time"`
UpdateTime time.Time `json:"update_time"`
}
func (Work) TableName() string {
return "web_article"
}
type Game struct {
ID int `json:"id" gorm:"primaryKey"`
Title string `json:"title"`
Orientation string `json:"orientation"`
Device string `json:"device"`
Era string `json:"era"`
Tags string `json:"tags"`
UserId int `json:"user_id"`
Content string `json:"content"`
Image string `json:"image"`
Images string `json:"images"`
User User `json:"user" gorm:"foreignKey:UserId"`
CreateTime time.Time `json:"create_time"`
UpdateTime time.Time `json:"update_time"`
}
func (Game) TableName() string {
return "web_article"
}
type Article struct {
ID int `json:"id" db:"id" gorm:"primaryKey"`
Title string `json:"title" db:"title"`
Orientation string `json:"orientation" db:"orientation"`
Device string `json:"device" db:"device"`
Era string `json:"era" db:"era"`
Tags string `json:"tags" db:"tags"`
UserId int `json:"user_id" db:"user_id"`
User User `json:"user" gorm:"foreignKey:UserId"`
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 {
ID int `json:"id"`
Title string `json:"title"`
Keyword string `json:"keyword"`
ParentID int `json:"parent_id"`
Status int `json:"status"`
Content string `json:"content"`
Sort int `json:"sort"`
Image string `json:"image"`
ImageNum int `json:"image_num"`
ArticleNum int `json:"article_num"`
CreateTime time.Time `json:"create_time"`
UpdateTime time.Time `json:"update_time"`
}
// TableName 方法用于自定义表名
func (Category) TableName() string {
return "web_article_category"
}
// 输入配置
type MysqlConfig struct {
Host string
Port int
Database string
UserName string
Password string
}
type Oss struct {
Local bool
}
type GorseConfig struct {
Host string
Port int
Open bool
}
type Config struct {
Mysql MysqlConfig
Gorse GorseConfig
Oss
}