Skip to content

Commit

Permalink
refactor(userpoint): remove unnecessary GetUserPointDetail related api
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayanami1314 committed Nov 12, 2024
1 parent 8cc7371 commit 2fa6769
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 46 deletions.
38 changes: 0 additions & 38 deletions handler/userpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,44 +47,6 @@ func AdminTransferUserPoint(c *gin.Context) {
c.JSON(http.StatusOK, dto.BaseResponse{Message: "用户积分转账成功。"})
}

func GetUserPointDetailHandler(c *gin.Context) {
var request dto.UserPointDetailRequest
if err := c.ShouldBindUri(&request); err != nil {
c.JSON(http.StatusNotFound, dto.BaseResponse{Message: "参数错误"})
return
}
user := middleware.GetCurrentUser(c)
filter := model.UserPointDetailFilter{UserPointDetailID: request.DetailID, UserID: user.ID}
userPointDetails, err := service.GetUserPointDetailList(c, filter)
if err != nil {
c.JSON(http.StatusInternalServerError, dto.BaseResponse{Message: "内部错误。"})
return
}
if len(userPointDetails) == 0 {
c.JSON(http.StatusNotFound, dto.BaseResponse{Message: "该积分明细不存在。"})
return
}
c.JSON(http.StatusOK, userPointDetails[0])
}
func AdminGetUserPointDetail(c *gin.Context) {
var request dto.UserPointDetailRequest
if err := c.ShouldBindUri(&request); err != nil {
c.JSON(http.StatusNotFound, dto.BaseResponse{Message: "参数错误"})
return
}
filter := model.UserPointDetailFilter{UserPointDetailID: request.DetailID}
userPointDetails, err := service.GetUserPointDetailList(c, filter)
if err != nil {
c.JSON(http.StatusInternalServerError, dto.BaseResponse{Message: "内部错误。"})
return
}
if len(userPointDetails) == 0 {
c.JSON(http.StatusNotFound, dto.BaseResponse{Message: "该积分明细不存在。"})
return
}
c.JSON(http.StatusOK, userPointDetails[0])
}

func GetUserPointDetailListHandler(c *gin.Context) {
var request dto.UserPointDetailListRequest
if err := c.ShouldBind(&request); err != nil {
Expand Down
2 changes: 2 additions & 0 deletions model/dto/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ type UserProfileDTO struct {
type UserListRequest struct {
model.PaginationFilterForQuery
}

type UserListResponse = BasePaginateResponse[model.UserMinimal]
6 changes: 0 additions & 6 deletions model/dto/userpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@ package dto

import "jcourse_go/model/model"

type UserListResponse = BasePaginateResponse[model.UserMinimal]

type UserPointDetailRequest struct {
DetailID int64 `uri:"detailID" binding:"required"`
}
type UserPointDetailResponse = BaseResponse
type UserPointDetailListRequest struct {
StartTime int64 `json:"start_time" form:"start_time"` // unix timestamp, 单位秒
EndTime int64 `json:"end_time" form:"end_time"`
Expand Down
2 changes: 0 additions & 2 deletions router.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,13 @@ func registerRouter(r *gin.Engine) {

userPointGroup := userGroup.Group("/point")
userPointGroup.GET("", handler.GetUserPointDetailListHandler)
userPointGroup.GET("/:detailID", handler.GetUserPointDetailHandler)
userPointGroup.POST("/transfer", handler.TransferUserPointHandler)

adminGroup := needAuthGroup.Group("/admin")
adminGroup.Use(middleware.RequireAdmin())
adminGroup.GET("/user", handler.AdminGetUserList)
adminGroup.POST("/user/point/change", handler.AdminChangeUserPoint)
adminGroup.GET("/user/point/detail", handler.AdminGetUserPointDetailList)
adminGroup.GET("/user/point/detail/:detailID", handler.AdminGetUserPointDetail)
adminGroup.GET("/user/point/transfer", handler.AdminTransferUserPoint)

llmGroup := needAuthGroup.Group(("/llm"))
Expand Down

0 comments on commit 2fa6769

Please sign in to comment.