animal with like #2

This commit is contained in:
Havoc412 2024-10-23 12:57:53 +08:00
parent babd68def0
commit c863331243
3 changed files with 17 additions and 7 deletions

View File

@ -17,7 +17,7 @@ type List struct {
Status string `form:"status" json:"status"`
Num int `form:"num" json:"num"`
Skip int `form:"skip" json:"skip"`
UserId int `form:"user_id" json:"user_id" binding:"required,min=1"`
UserId int `form:"user_id" json:"user_id"`
}
func (l List) CheckParams(context *gin.Context) {

View File

@ -2,5 +2,5 @@ package model
type AnimalWithLikeList struct {
Animal Animal `json:"animal"`
Like bool `json:"like"`
Like bool `json:"like,omitempty"`
}

View File

@ -61,6 +61,7 @@ func (a *AnimalsCurd) List(attrs string, gender string, breed string, sterilzati
animals := model.CreateAnimalFactory("").Show(validSelectedFields, genderArray, breedArray, sterilzationArray, statusArray, num, skip)
if userId > 0 {
for i := range animals {
animalWithLike := model.AnimalWithLikeList{
Animal: animals[i],
@ -68,6 +69,15 @@ func (a *AnimalsCurd) List(attrs string, gender string, breed string, sterilzati
}
temp = append(temp, animalWithLike)
}
} else {
for i := range animals {
animalWithLike := model.AnimalWithLikeList{
Animal: animals[i],
}
temp = append(temp, animalWithLike)
}
}
return
}