add Department Field to Animal
This commit is contained in:
parent
2d0478d917
commit
9d1f5f8e62
@ -26,11 +26,12 @@ func (a *Animals) List(context *gin.Context) {
|
||||
breed := context.GetString(consts.ValidatorPrefix + "breed")
|
||||
sterilization := context.GetString(consts.ValidatorPrefix + "sterilization")
|
||||
status := context.GetString(consts.ValidatorPrefix + "status")
|
||||
department := context.GetString(consts.ValidatorPrefix + "department")
|
||||
num := context.GetFloat64(consts.ValidatorPrefix + "num")
|
||||
skip := context.GetFloat64(consts.ValidatorPrefix + "skip")
|
||||
userId := context.GetFloat64(consts.ValidatorPrefix + "user_id")
|
||||
|
||||
animals := curd.CreateAnimalsCurdFactory().List(attrs, gender, breed, sterilization, status, int(num), int(skip), int(userId))
|
||||
animals := curd.CreateAnimalsCurdFactory().List(attrs, gender, breed, sterilization, status, department, int(num), int(skip), int(userId))
|
||||
if animals != nil {
|
||||
response.Success(context, consts.CurdStatusOkMsg, animals)
|
||||
} else {
|
||||
|
@ -15,6 +15,7 @@ type List struct {
|
||||
Breed string `form:"breed" json:"breed"`
|
||||
Sterilization string `form:"sterilization" json:"sterilization"`
|
||||
Status string `form:"status" json:"status"`
|
||||
Department string `form:"department" json:"department"`
|
||||
Num int `form:"num" json:"num"`
|
||||
Skip int `form:"skip" json:"skip"`
|
||||
UserId int `form:"user_id" json:"user_id"`
|
||||
|
@ -34,7 +34,7 @@ type Animal struct {
|
||||
HeadImg string `gorm:"type:varchar(50)" json:"head_img,omitempty"` // Head 默认处理为正方形。
|
||||
Photos string `gorm:"type:varchar(255)" json:"photos,omitempty"` // 图片数组
|
||||
// TAG POI
|
||||
Department uint8 `gorm:"column:department" json:"department"`
|
||||
Department uint8 `gorm:"column:department" json:"department,omitempty"`
|
||||
Latitude float64 `json:"latitude,omitempty"` // POI 位置相关
|
||||
Longitude float64 `json:"longitude,omitempty"` // POI 位置相关
|
||||
ActivityRadius uint64 `json:"activity_radius,omitempty"` // 活动半径
|
||||
@ -43,7 +43,7 @@ type Animal struct {
|
||||
FaceBreeds string `json:"face_breeds,omitempty" gorm:"size:20"`
|
||||
FaceBreedProbs string `json:"face_breed_probs,omitempty" gorm:"size:20"`
|
||||
// 上传者 ID
|
||||
UsersModelId int64 `gorm:"column:user_id" json:"user_id"` // 上传者 ID
|
||||
UsersModelId int64 `gorm:"column:user_id" json:"user_id,omitempty"` // 上传者 ID
|
||||
UsersModel *UsersModel `json:"users_model,omitempty"`
|
||||
}
|
||||
|
||||
@ -51,7 +51,7 @@ func (a *Animal) TableName() string {
|
||||
return "animals"
|
||||
}
|
||||
|
||||
func (a *Animal) Show(attrs []string, gender []uint8, breed []uint8, sterilization []uint8, status []uint8, num int, skip int) (temp []Animal) {
|
||||
func (a *Animal) Show(attrs []string, gender []uint8, breed []uint8, sterilization []uint8, status []uint8, department []uint8, num int, skip int) (temp []Animal) {
|
||||
db := a.DB.Table(a.TableName()).Limit(int(num)).Offset(int(skip)).Select(attrs)
|
||||
|
||||
// 创建条件映射
|
||||
@ -60,9 +60,10 @@ func (a *Animal) Show(attrs []string, gender []uint8, breed []uint8, sterilizati
|
||||
"breed": breed,
|
||||
"sterilization": sterilization,
|
||||
"status": status,
|
||||
"department": department,
|
||||
}
|
||||
|
||||
db = gorm_v2.BuildWhere(db, conditions)
|
||||
db = gorm_v2.BuildWhere(db, conditions) // TIP 这里的 Where 条件连接就很方便了。
|
||||
|
||||
err := db.Find(&temp).Error
|
||||
if err != nil {
|
||||
|
@ -6,7 +6,6 @@ import (
|
||||
"catface/app/utils/query_handler"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
)
|
||||
|
||||
func CreateAnimalsCurdFactory() *AnimalsCurd {
|
||||
@ -49,18 +48,19 @@ func getSelectAttrs(attrs string) (validSelectedFields []string) {
|
||||
return
|
||||
}
|
||||
|
||||
func (a *AnimalsCurd) List(attrs string, gender string, breed string, sterilization string, status string, num int, skip int, userId int) (temp []model.AnimalWithLikeList) {
|
||||
func (a *AnimalsCurd) List(attrs string, gender string, breed string, sterilization string, status string, department string, num int, skip int, userId int) (temp []model.AnimalWithLikeList) {
|
||||
validSelectedFields := getSelectAttrs(attrs)
|
||||
genderArray := query_handler.StringToUint8Array(gender)
|
||||
breedArray := query_handler.StringToUint8Array(breed)
|
||||
sterilizationArray := query_handler.StringToUint8Array(sterilization)
|
||||
statusArray := query_handler.StringToUint8Array(status)
|
||||
departmentArray := query_handler.StringToUint8Array(department)
|
||||
|
||||
if num == 0 {
|
||||
num = 10
|
||||
}
|
||||
|
||||
animals := model.CreateAnimalFactory("").Show(validSelectedFields, genderArray, breedArray, sterilizationArray, statusArray, num, skip)
|
||||
animals := model.CreateAnimalFactory("").Show(validSelectedFields, genderArray, breedArray, sterilizationArray, statusArray, departmentArray, num, skip)
|
||||
|
||||
// 状态记录
|
||||
var likeRes []bool
|
||||
|
Loading…
x
Reference in New Issue
Block a user