Opt: search user and room default status query

pull/31/head
zijiren233 1 year ago
parent cb7c98adb8
commit 7c5a7e88aa

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

@ -195,6 +195,7 @@ type RoomInfo struct {
NeedPassword bool `json:"needPassword"`
Creator string `json:"creator"`
CreatedAt int64 `json:"createdAt"`
Status model.RoomStatus `json:"status"`
}
func GetRoomHeapInCacheWithoutHidden() []*RoomInfo {

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

Loading…
Cancel
Save