animal with like #2
This commit is contained in:
parent
babd68def0
commit
c863331243
@ -17,7 +17,7 @@ type List struct {
|
|||||||
Status string `form:"status" json:"status"`
|
Status string `form:"status" json:"status"`
|
||||||
Num int `form:"num" json:"num"`
|
Num int `form:"num" json:"num"`
|
||||||
Skip int `form:"skip" json:"skip"`
|
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) {
|
func (l List) CheckParams(context *gin.Context) {
|
||||||
|
@ -2,5 +2,5 @@ package model
|
|||||||
|
|
||||||
type AnimalWithLikeList struct {
|
type AnimalWithLikeList struct {
|
||||||
Animal Animal `json:"animal"`
|
Animal Animal `json:"animal"`
|
||||||
Like bool `json:"like"`
|
Like bool `json:"like,omitempty"`
|
||||||
}
|
}
|
||||||
|
@ -61,13 +61,23 @@ func (a *AnimalsCurd) List(attrs string, gender string, breed string, sterilzati
|
|||||||
|
|
||||||
animals := model.CreateAnimalFactory("").Show(validSelectedFields, genderArray, breedArray, sterilzationArray, statusArray, num, skip)
|
animals := model.CreateAnimalFactory("").Show(validSelectedFields, genderArray, breedArray, sterilzationArray, statusArray, num, skip)
|
||||||
|
|
||||||
for i := range animals {
|
if userId > 0 {
|
||||||
animalWithLike := model.AnimalWithLikeList{
|
for i := range animals {
|
||||||
Animal: animals[i],
|
animalWithLike := model.AnimalWithLikeList{
|
||||||
Like: model.CreateAnimalLikeFactory("").Liked(userId, int(animals[i].Id)),
|
Animal: animals[i],
|
||||||
|
Like: model.CreateAnimalLikeFactory("").Liked(userId, int(animals[i].Id)),
|
||||||
|
}
|
||||||
|
temp = append(temp, animalWithLike)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for i := range animals {
|
||||||
|
animalWithLike := model.AnimalWithLikeList{
|
||||||
|
Animal: animals[i],
|
||||||
|
}
|
||||||
|
temp = append(temp, animalWithLike)
|
||||||
}
|
}
|
||||||
temp = append(temp, animalWithLike)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user