Fix: search room

pull/134/head
zijiren233 1 year ago
parent 28b3977f28
commit abc193f5d6

@ -195,6 +195,17 @@ func WhereRoomNameLikeOrCreatorInOrIDLike(name string, ids []string, id string)
}
}
func WhereRoomNameLikeOrCreatorInOrRoomsIDLike(name string, ids []string, id string) func(db *gorm.DB) *gorm.DB {
return func(db *gorm.DB) *gorm.DB {
switch dbType {
case conf.DatabaseTypePostgres:
return db.Where("name ILIKE ? OR creator_id IN ? OR rooms.id ILIKE ?", utils.LIKE(name), ids, id)
default:
return db.Where("name LIKE ? OR creator_id IN ? OR rooms.id LIKE ?", utils.LIKE(name), ids, id)
}
}
}
func WhereRoomNameLikeOrIDLike(name string, id string) func(db *gorm.DB) *gorm.DB {
return func(db *gorm.DB) *gorm.DB {
switch dbType {
@ -286,6 +297,17 @@ func WhereIDLike(id string) func(db *gorm.DB) *gorm.DB {
}
}
func WhereRoomsIDLike(id string) func(db *gorm.DB) *gorm.DB {
return func(db *gorm.DB) *gorm.DB {
switch dbType {
case conf.DatabaseTypePostgres:
return db.Where("rooms.id ILIKE ?", utils.LIKE(id))
default:
return db.Where("rooms.id LIKE ?", utils.LIKE(id))
}
}
}
func WhereRoomMemberStatus(status model.RoomMemberStatus) func(db *gorm.DB) *gorm.DB {
return func(db *gorm.DB) *gorm.DB {
return db.Where("room_members.status = ?", status)

@ -202,7 +202,7 @@ func RoomList(ctx *gin.Context) {
ctx.AbortWithStatusJSON(http.StatusInternalServerError, model.NewApiErrorResp(err))
return
}
scopes = append(scopes, db.WhereRoomNameLikeOrCreatorInOrIDLike(keyword, ids, keyword))
scopes = append(scopes, db.WhereRoomNameLikeOrCreatorInOrRoomsIDLike(keyword, ids, keyword))
case "name":
scopes = append(scopes, db.WhereRoomNameLike(keyword))
case "creator":
@ -214,7 +214,7 @@ func RoomList(ctx *gin.Context) {
}
scopes = append(scopes, db.WhereCreatorIDIn(ids))
case "id":
scopes = append(scopes, db.WhereIDLike(keyword))
scopes = append(scopes, db.WhereRoomsIDLike(keyword))
}
}

Loading…
Cancel
Save