146 lines
3.7 KiB
Go
146 lines
3.7 KiB
Go
package api
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"github.guxuan/haibei/internal/mods/point/biz"
|
|
"github.guxuan/haibei/internal/mods/point/schema"
|
|
"github.guxuan/haibei/pkg/util"
|
|
)
|
|
|
|
// Defining the `Grade` api.
|
|
type Grade struct {
|
|
GradeBIZ *biz.Grade
|
|
}
|
|
|
|
// @Tags 权益模块
|
|
// @Security ApiKeyAuth
|
|
// @Summary Query grade list
|
|
// @Param current query int true "pagination index" default(1)
|
|
// @Param pageSize query int true "pagination size" default(10)
|
|
// @Success 200 {object} util.ResponseResult{data=[]schema.Grade}
|
|
// @Failure 401 {object} util.ResponseResult
|
|
// @Failure 500 {object} util.ResponseResult
|
|
// @Router /api/v1/grades [get]
|
|
func (a *Grade) Query(c *gin.Context) {
|
|
ctx := c.Request.Context()
|
|
var params schema.GradeQueryParam
|
|
if err := util.ParseQuery(c, ¶ms); err != nil {
|
|
util.ResError(c, err)
|
|
return
|
|
}
|
|
|
|
result, err := a.GradeBIZ.Query(ctx, params)
|
|
if err != nil {
|
|
util.ResError(c, err)
|
|
return
|
|
}
|
|
util.ResPage(c, result.Data, result.PageResult)
|
|
}
|
|
|
|
// @Tags 权益模块
|
|
// @Security ApiKeyAuth
|
|
// @Summary Get grade record by ID
|
|
// @Param id path string true "unique id"
|
|
// @Success 200 {object} util.ResponseResult{data=schema.Grade}
|
|
// @Failure 401 {object} util.ResponseResult
|
|
// @Failure 500 {object} util.ResponseResult
|
|
// @Router /api/v1/grades/{id} [get]
|
|
func (a *Grade) Get(c *gin.Context) {
|
|
ctx := c.Request.Context()
|
|
id, err := util.GetQueryID(c)
|
|
if err != nil {
|
|
util.ResError(c, err)
|
|
return
|
|
}
|
|
item, err := a.GradeBIZ.Get(ctx, id)
|
|
if err != nil {
|
|
util.ResError(c, err)
|
|
return
|
|
}
|
|
util.ResSuccess(c, item)
|
|
}
|
|
|
|
// @Tags 权益模块
|
|
// @Security ApiKeyAuth
|
|
// @Summary Create grade record
|
|
// @Param body body schema.GradeForm true "Request body"
|
|
// @Success 200 {object} util.ResponseResult{data=schema.Grade}
|
|
// @Failure 400 {object} util.ResponseResult
|
|
// @Failure 401 {object} util.ResponseResult
|
|
// @Failure 500 {object} util.ResponseResult
|
|
// @Router /api/v1/grades [post]
|
|
func (a *Grade) Create(c *gin.Context) {
|
|
ctx := c.Request.Context()
|
|
item := new(schema.GradeForm)
|
|
if err := util.ParseJSON(c, item); err != nil {
|
|
util.ResError(c, err)
|
|
return
|
|
} else if err := item.Validate(); err != nil {
|
|
util.ResError(c, err)
|
|
return
|
|
}
|
|
|
|
result, err := a.GradeBIZ.Create(ctx, item)
|
|
if err != nil {
|
|
util.ResError(c, err)
|
|
return
|
|
}
|
|
util.ResSuccess(c, result)
|
|
}
|
|
|
|
// @Tags 权益模块
|
|
// @Security ApiKeyAuth
|
|
// @Summary Update grade record by ID
|
|
// @Param id path string true "unique id"
|
|
// @Param body body schema.GradeForm true "Request body"
|
|
// @Success 200 {object} util.ResponseResult
|
|
// @Failure 400 {object} util.ResponseResult
|
|
// @Failure 401 {object} util.ResponseResult
|
|
// @Failure 500 {object} util.ResponseResult
|
|
// @Router /api/v1/grades/{id} [put]
|
|
func (a *Grade) Update(c *gin.Context) {
|
|
ctx := c.Request.Context()
|
|
item := new(schema.GradeForm)
|
|
if err := util.ParseJSON(c, item); err != nil {
|
|
util.ResError(c, err)
|
|
return
|
|
} else if err := item.Validate(); err != nil {
|
|
util.ResError(c, err)
|
|
return
|
|
}
|
|
id, err := util.GetQueryID(c)
|
|
if err != nil {
|
|
util.ResError(c, err)
|
|
return
|
|
}
|
|
err = a.GradeBIZ.Update(ctx, id, item)
|
|
if err != nil {
|
|
util.ResError(c, err)
|
|
return
|
|
}
|
|
util.ResOK(c)
|
|
}
|
|
|
|
// @Tags 权益模块
|
|
// @Security ApiKeyAuth
|
|
// @Summary Delete grade record by ID
|
|
// @Param id path string true "unique id"
|
|
// @Success 200 {object} util.ResponseResult
|
|
// @Failure 401 {object} util.ResponseResult
|
|
// @Failure 500 {object} util.ResponseResult
|
|
// @Router /api/v1/grades/{id} [delete]
|
|
func (a *Grade) Delete(c *gin.Context) {
|
|
ctx := c.Request.Context()
|
|
id, err := util.GetQueryID(c)
|
|
if err != nil {
|
|
util.ResError(c, err)
|
|
return
|
|
}
|
|
err = a.GradeBIZ.Delete(ctx, id)
|
|
if err != nil {
|
|
util.ResError(c, err)
|
|
return
|
|
}
|
|
util.ResOK(c)
|
|
}
|