Opt: search user and room default status query

pull/31/head
zijiren233 2 years ago
parent cb7c98adb8
commit 7c5a7e88aa

@ -9,7 +9,7 @@ import (
"gorm.io/gorm" "gorm.io/gorm"
) )
type RoomStatus uint type RoomStatus uint64
const ( const (
RoomStatusBanned RoomStatus = 1 RoomStatusBanned RoomStatus = 1

@ -189,12 +189,13 @@ func GetAllRoomsInCacheWithoutHidden() []*Room {
} }
type RoomInfo struct { type RoomInfo struct {
RoomId string `json:"roomId"` RoomId string `json:"roomId"`
RoomName string `json:"roomName"` RoomName string `json:"roomName"`
PeopleNum int64 `json:"peopleNum"` PeopleNum int64 `json:"peopleNum"`
NeedPassword bool `json:"needPassword"` NeedPassword bool `json:"needPassword"`
Creator string `json:"creator"` Creator string `json:"creator"`
CreatedAt int64 `json:"createdAt"` CreatedAt int64 `json:"createdAt"`
Status model.RoomStatus `json:"status"`
} }
func GetRoomHeapInCacheWithoutHidden() []*RoomInfo { func GetRoomHeapInCacheWithoutHidden() []*RoomInfo {

@ -65,7 +65,7 @@ func Users(ctx *gin.Context) {
scopes := []func(db *gorm.DB) *gorm.DB{} scopes := []func(db *gorm.DB) *gorm.DB{}
switch ctx.DefaultQuery("role", "user") { switch ctx.Query("role") {
case "admin": case "admin":
scopes = append(scopes, db.WhereRole(dbModel.RoleAdmin)) scopes = append(scopes, db.WhereRole(dbModel.RoleAdmin))
case "user": case "user":
@ -74,9 +74,8 @@ func Users(ctx *gin.Context) {
scopes = append(scopes, db.WhereRole(dbModel.RolePending)) scopes = append(scopes, db.WhereRole(dbModel.RolePending))
case "banned": case "banned":
scopes = append(scopes, db.WhereRole(dbModel.RoleBanned)) scopes = append(scopes, db.WhereRole(dbModel.RoleBanned))
default: case "root":
ctx.AbortWithStatusJSON(http.StatusBadRequest, model.NewApiErrorStringResp("not support role")) scopes = append(scopes, db.WhereRole(dbModel.RoleRoot))
return
} }
switch ctx.DefaultQuery("order", "name") { switch ctx.DefaultQuery("order", "name") {
@ -201,16 +200,13 @@ func Rooms(ctx *gin.Context) {
scopes := []func(db *gorm.DB) *gorm.DB{} scopes := []func(db *gorm.DB) *gorm.DB{}
switch ctx.DefaultQuery("status", "active") { switch ctx.Query("status") {
case "active": case "active":
scopes = append(scopes, db.WhereStatus(dbModel.RoomStatusActive)) scopes = append(scopes, db.WhereStatus(dbModel.RoomStatusActive))
case "pending": case "pending":
scopes = append(scopes, db.WhereStatus(dbModel.RoomStatusPending)) scopes = append(scopes, db.WhereStatus(dbModel.RoomStatusPending))
case "banned": case "banned":
scopes = append(scopes, db.WhereStatus(dbModel.RoomStatusBanned)) scopes = append(scopes, db.WhereStatus(dbModel.RoomStatusBanned))
default:
ctx.AbortWithStatusJSON(http.StatusBadRequest, model.NewApiErrorStringResp("not support status"))
return
} }
switch ctx.DefaultQuery("order", "name") { switch ctx.DefaultQuery("order", "name") {

@ -147,6 +147,7 @@ func genRoomListResp(scopes ...func(db *gorm.DB) *gorm.DB) []*model.RoomListResp
NeedPassword: len(r.HashedPassword) != 0, NeedPassword: len(r.HashedPassword) != 0,
Creator: op.GetUserName(r.CreatorID), Creator: op.GetUserName(r.CreatorID),
CreatedAt: r.CreatedAt.UnixMilli(), CreatedAt: r.CreatedAt.UnixMilli(),
Status: r.Status,
} }
} }
return resp return resp

Loading…
Cancel
Save