diff --git a/server/handlers/admin.go b/server/handlers/admin.go index ba71774..da2a1ad 100644 --- a/server/handlers/admin.go +++ b/server/handlers/admin.go @@ -80,7 +80,7 @@ func Users(ctx *gin.Context) { return } - switch ctx.DefaultQuery("order", "createdAt") { + switch ctx.DefaultQuery("order", "name") { case "createdAt": if desc { scopes = append(scopes, db.OrderByCreatedAtDesc) @@ -93,12 +93,6 @@ func Users(ctx *gin.Context) { } else { scopes = append(scopes, db.OrderByAsc("username")) } - case "id": - if desc { - scopes = append(scopes, db.OrderByIDDesc) - } else { - scopes = append(scopes, db.OrderByIDAsc) - } default: ctx.AbortWithStatusJSON(http.StatusBadRequest, model.NewApiErrorStringResp("not support order")) return @@ -206,11 +200,6 @@ func BanUser(ctx *gin.Context) { func Rooms(ctx *gin.Context) { // user := ctx.MustGet("user").(*op.User) - order := ctx.Query("order") - if order == "" { - ctx.AbortWithStatusJSON(http.StatusBadRequest, model.NewApiErrorStringResp("order is required")) - return - } page, pageSize, err := GetPageAndPageSize(ctx) if err != nil { @@ -234,7 +223,7 @@ func Rooms(ctx *gin.Context) { return } - switch order { + switch ctx.DefaultQuery("order", "name") { case "createdAt": if desc { scopes = append(scopes, db.OrderByCreatedAtDesc) @@ -247,12 +236,6 @@ func Rooms(ctx *gin.Context) { } else { scopes = append(scopes, db.OrderByAsc("name")) } - case "id": - if desc { - scopes = append(scopes, db.OrderByIDDesc) - } else { - scopes = append(scopes, db.OrderByIDAsc) - } default: ctx.AbortWithStatusJSON(http.StatusBadRequest, model.NewApiErrorStringResp("not support order")) return diff --git a/server/handlers/room.go b/server/handlers/room.go index 7b15f7d..f06ca68 100644 --- a/server/handlers/room.go +++ b/server/handlers/room.go @@ -92,25 +92,19 @@ func RoomList(ctx *gin.Context) { db.WhereStatus(dbModel.RoomStatusActive), } - switch ctx.DefaultQuery("order", "createdAt") { + switch ctx.DefaultQuery("order", "name") { case "createdAt": if desc { scopes = append(scopes, db.OrderByCreatedAtDesc) } else { scopes = append(scopes, db.OrderByCreatedAtAsc) } - case "roomName": + case "name": if desc { scopes = append(scopes, db.OrderByDesc("name")) } else { scopes = append(scopes, db.OrderByAsc("name")) } - case "roomId": - if desc { - scopes = append(scopes, db.OrderByIDDesc) - } else { - scopes = append(scopes, db.OrderByIDAsc) - } default: ctx.AbortWithStatusJSON(http.StatusBadRequest, model.NewApiErrorStringResp("not support order")) return diff --git a/server/handlers/user.go b/server/handlers/user.go index 2e8737d..d16ef34 100644 --- a/server/handlers/user.go +++ b/server/handlers/user.go @@ -36,11 +36,7 @@ func LogoutUser(ctx *gin.Context) { func UserRooms(ctx *gin.Context) { user := ctx.MustGet("user").(*op.User) - order := ctx.Query("order") - if order == "" { - ctx.AbortWithStatusJSON(http.StatusBadRequest, model.NewApiErrorStringResp("order is required")) - return - } + page, pageSize, err := GetPageAndPageSize(ctx) if err != nil { ctx.AbortWithStatusJSON(http.StatusBadRequest, model.NewApiErrorResp(err)) @@ -62,25 +58,19 @@ func UserRooms(ctx *gin.Context) { scopes = append(scopes, db.WhereStatus(dbModel.RoomStatusBanned)) } - switch order { + switch ctx.DefaultQuery("order", "name") { case "createdAt": if desc { scopes = append(scopes, db.OrderByCreatedAtDesc) } else { scopes = append(scopes, db.OrderByCreatedAtAsc) } - case "roomName": + case "name": if desc { scopes = append(scopes, db.OrderByDesc("name")) } else { scopes = append(scopes, db.OrderByAsc("name")) } - case "roomId": - if desc { - scopes = append(scopes, db.OrderByIDDesc) - } else { - scopes = append(scopes, db.OrderByIDAsc) - } default: ctx.AbortWithStatusJSON(http.StatusBadRequest, model.NewApiErrorStringResp("not support order")) return