diff --git a/internal/db/db.go b/internal/db/db.go index 4cf061c..2f75b47 100644 --- a/internal/db/db.go +++ b/internal/db/db.go @@ -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) diff --git a/server/handlers/room.go b/server/handlers/room.go index f590caf..f3fc44e 100644 --- a/server/handlers/room.go +++ b/server/handlers/room.go @@ -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)) } }