实现基本管理员数据访问接口
This commit is contained in:
@@ -15,8 +15,8 @@ import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
// ListResourceShort 分页短效套餐
|
||||
func ListResourceShort(c *fiber.Ctx) error {
|
||||
// PageResourceShort 分页查询当前用户短效套餐
|
||||
func PageResourceShort(c *fiber.Ctx) error {
|
||||
// 检查权限
|
||||
authCtx, err := auth.GetAuthCtx(c).PermitUser()
|
||||
if err != nil {
|
||||
@@ -24,7 +24,7 @@ func ListResourceShort(c *fiber.Ctx) error {
|
||||
}
|
||||
|
||||
// 解析请求参数
|
||||
req := new(ListResourceShortReq)
|
||||
req := new(PageResourceShortReq)
|
||||
if err := c.BodyParser(req); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -86,7 +86,7 @@ func ListResourceShort(c *fiber.Ctx) error {
|
||||
})
|
||||
}
|
||||
|
||||
type ListResourceShortReq struct {
|
||||
type PageResourceShortReq struct {
|
||||
core.PageReq
|
||||
ResourceNo *string `json:"resource_no"`
|
||||
Active *bool `json:"active"`
|
||||
@@ -97,8 +97,8 @@ type ListResourceShortReq struct {
|
||||
ExpireBefore *time.Time `json:"expire_before"`
|
||||
}
|
||||
|
||||
// ListResourceLong 分页长效套餐
|
||||
func ListResourceLong(c *fiber.Ctx) error {
|
||||
// PageResourceLong 分页查询当前用户长效套餐
|
||||
func PageResourceLong(c *fiber.Ctx) error {
|
||||
// 检查权限
|
||||
authCtx, err := auth.GetAuthCtx(c).PermitUser()
|
||||
if err != nil {
|
||||
@@ -106,7 +106,7 @@ func ListResourceLong(c *fiber.Ctx) error {
|
||||
}
|
||||
|
||||
// 解析请求参数
|
||||
req := new(ListResourceLongReq)
|
||||
req := new(PageResourceLongReq)
|
||||
if err := c.BodyParser(req); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -168,7 +168,7 @@ func ListResourceLong(c *fiber.Ctx) error {
|
||||
})
|
||||
}
|
||||
|
||||
type ListResourceLongReq struct {
|
||||
type PageResourceLongReq struct {
|
||||
core.PageReq
|
||||
ResourceNo *string `json:"resource_no"`
|
||||
Active *bool `json:"active"`
|
||||
@@ -179,6 +179,56 @@ type ListResourceLongReq struct {
|
||||
ExpireBefore *time.Time `json:"expire_before"`
|
||||
}
|
||||
|
||||
// PageResourceShortByAdmin 分页查询全部短效套餐
|
||||
func PageResourceShortByAdmin(c *fiber.Ctx) error {
|
||||
_, err := auth.GetAuthCtx(c).PermitAdmin()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
req := new(struct{ core.PageReq })
|
||||
if err = g.Validator.ParseBody(c, req); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
list, total, err := q.Resource.Debug().
|
||||
LeftJoin(q.ResourceShort, q.ResourceShort.ResourceID.EqCol(q.Resource.ID)).
|
||||
Where(q.Resource.Type.Eq(int(m.ResourceTypeShort))).
|
||||
FindByPage(req.GetOffset(), req.GetLimit())
|
||||
|
||||
return c.JSON(core.PageResp{
|
||||
List: list,
|
||||
Total: int(total),
|
||||
Page: req.GetPage(),
|
||||
Size: req.GetSize(),
|
||||
})
|
||||
}
|
||||
|
||||
// PageResourceLongByAdmin 分页查询全部短效套餐
|
||||
func PageResourceLongByAdmin(c *fiber.Ctx) error {
|
||||
_, err := auth.GetAuthCtx(c).PermitAdmin()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
req := new(struct{ core.PageReq })
|
||||
if err = g.Validator.ParseBody(c, req); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
list, total, err := q.Resource.
|
||||
LeftJoin(q.ResourceLong, q.ResourceLong.ResourceID.EqCol(q.Resource.ID)).
|
||||
Where(q.Resource.Type.Eq(int(m.ResourceTypeLong))).
|
||||
FindByPage(req.GetOffset(), req.GetLimit())
|
||||
|
||||
return c.JSON(core.PageResp{
|
||||
List: list,
|
||||
Total: int(total),
|
||||
Page: req.GetPage(),
|
||||
Size: req.GetSize(),
|
||||
})
|
||||
}
|
||||
|
||||
// AllActiveResource 所有可用套餐
|
||||
func AllActiveResource(c *fiber.Ctx) error {
|
||||
// 检查权限
|
||||
|
||||
Reference in New Issue
Block a user