fix(park):修复园区不能搜索的问题。
This commit is contained in:
parent
954285e426
commit
8aa4e38760
|
@ -49,7 +49,8 @@ func listAllParksUnderSessionUser(c *gin.Context) {
|
|||
result.Unauthorized(err.Error())
|
||||
return
|
||||
}
|
||||
parks, err := service.ParkService.ListAllParkBelongsTo(userSession.Uid)
|
||||
keyword := c.DefaultQuery("keyword", "")
|
||||
parks, err := service.ParkService.ListAllParkBelongsTo(userSession.Uid, keyword)
|
||||
if err != nil {
|
||||
result.Error(http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
|
@ -60,7 +61,8 @@ func listAllParksUnderSessionUser(c *gin.Context) {
|
|||
func listAllParksUnderSpecificUser(c *gin.Context) {
|
||||
result := response.NewResult(c)
|
||||
requestUserId := c.Param("uid")
|
||||
parks, err := service.ParkService.ListAllParkBelongsTo(requestUserId)
|
||||
keyword := c.DefaultQuery("keyword", "")
|
||||
parks, err := service.ParkService.ListAllParkBelongsTo(requestUserId, keyword)
|
||||
if err != nil {
|
||||
result.Error(http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
|
|
|
@ -73,19 +73,29 @@ func (_ParkService) DeletePark(uid, pid string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (_ParkService) ListAllParkBelongsTo(uid string) ([]model.Park, error) {
|
||||
if parks, _ := cache.RetreiveSearch[[]model.Park]("park", "belong", uid); parks != nil {
|
||||
func (_ParkService) ListAllParkBelongsTo(uid, keyword string) ([]model.Park, error) {
|
||||
if parks, _ := cache.RetreiveSearch[[]model.Park]("park", "belong", uid, keyword); parks != nil {
|
||||
return *parks, nil
|
||||
}
|
||||
cond := builder.NewCond().And(builder.Eq{"user_id": uid})
|
||||
if len(keyword) > 0 {
|
||||
cond = cond.And(
|
||||
builder.Like{"name", keyword}.
|
||||
Or(builder.Like{"abbr", keyword}).
|
||||
Or(builder.Like{"address", keyword}).
|
||||
Or(builder.Like{"contact", keyword}).
|
||||
Or(builder.Like{"phone", keyword}),
|
||||
)
|
||||
}
|
||||
parks := make([]model.Park, 0)
|
||||
err := global.DBConn.
|
||||
Where(builder.Eq{"user_id": uid}).
|
||||
Where(cond).
|
||||
NoAutoCondition().
|
||||
Find(&parks)
|
||||
if err != nil {
|
||||
return make([]model.Park, 0), err
|
||||
}
|
||||
cache.CacheSearch(parks, []string{"park"}, "park", "belong", uid)
|
||||
cache.CacheSearch(parks, []string{"park"}, "park", "belong", uid, keyword)
|
||||
return parks, nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user