feat: 重构内容和订单列表接口,使用过滤器结构体简化参数传递;更新相关服务和测试用例
This commit is contained in:
@@ -50,11 +50,9 @@ func (c *Creator) Dashboard(ctx fiber.Ctx) (*dto.DashboardStats, error) {
|
|||||||
// @Param genre query string false "Genre"
|
// @Param genre query string false "Genre"
|
||||||
// @Param keyword query string false "Keyword"
|
// @Param keyword query string false "Keyword"
|
||||||
// @Success 200 {array} dto.ContentItem
|
// @Success 200 {array} dto.ContentItem
|
||||||
// @Bind status query
|
// @Bind filter query
|
||||||
// @Bind genre query
|
func (c *Creator) ListContents(ctx fiber.Ctx, filter *dto.CreatorContentListFilter) ([]dto.ContentItem, error) {
|
||||||
// @Bind keyword query
|
return services.Creator.ListContents(ctx.Context(), filter)
|
||||||
func (c *Creator) ListContents(ctx fiber.Ctx, status, genre, keyword string) ([]dto.ContentItem, error) {
|
|
||||||
return services.Creator.ListContents(ctx.Context(), status, genre, keyword)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create/Publish content
|
// Create/Publish content
|
||||||
@@ -115,10 +113,9 @@ func (c *Creator) DeleteContent(ctx fiber.Ctx, id string) error {
|
|||||||
// @Param status query string false "Status"
|
// @Param status query string false "Status"
|
||||||
// @Param keyword query string false "Keyword"
|
// @Param keyword query string false "Keyword"
|
||||||
// @Success 200 {array} dto.Order
|
// @Success 200 {array} dto.Order
|
||||||
// @Bind status query
|
// @Bind filter query
|
||||||
// @Bind keyword query
|
func (c *Creator) ListOrders(ctx fiber.Ctx, filter *dto.CreatorOrderListFilter) ([]dto.Order, error) {
|
||||||
func (c *Creator) ListOrders(ctx fiber.Ctx, status, keyword string) ([]dto.Order, error) {
|
return services.Creator.ListOrders(ctx.Context(), filter)
|
||||||
return services.Creator.ListOrders(ctx.Context(), status, keyword)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process refund
|
// Process refund
|
||||||
|
|||||||
@@ -4,10 +4,10 @@ import "quyun/v2/app/requests"
|
|||||||
|
|
||||||
type ContentListFilter struct {
|
type ContentListFilter struct {
|
||||||
requests.Pagination
|
requests.Pagination
|
||||||
Keyword string `query:"keyword"`
|
Keyword *string `query:"keyword"`
|
||||||
Genre string `query:"genre"`
|
Genre *string `query:"genre"`
|
||||||
TenantID string `query:"tenantId"`
|
TenantID *string `query:"tenantId"`
|
||||||
Sort string `query:"sort"`
|
Sort *string `query:"sort"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ContentItem struct {
|
type ContentItem struct {
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package dto
|
package dto
|
||||||
|
|
||||||
|
import "quyun/v2/app/requests"
|
||||||
|
|
||||||
type ApplyForm struct {
|
type ApplyForm struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Bio string `json:"bio"`
|
Bio string `json:"bio"`
|
||||||
@@ -37,6 +39,19 @@ type ContentUpdateForm struct {
|
|||||||
MediaIDs []string `json:"media_ids"`
|
MediaIDs []string `json:"media_ids"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CreatorContentListFilter struct {
|
||||||
|
requests.Pagination
|
||||||
|
Status *string `query:"status"`
|
||||||
|
Genre *string `query:"genre"`
|
||||||
|
Keyword *string `query:"keyword"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type CreatorOrderListFilter struct {
|
||||||
|
requests.Pagination
|
||||||
|
Status *string `query:"status"`
|
||||||
|
Keyword *string `query:"keyword"`
|
||||||
|
}
|
||||||
|
|
||||||
type RefundForm struct {
|
type RefundForm struct {
|
||||||
Action string `json:"action"` // accept, reject
|
Action string `json:"action"` // accept, reject
|
||||||
Reason string `json:"reason"`
|
Reason string `json:"reason"`
|
||||||
@@ -63,15 +78,3 @@ type WithdrawForm struct {
|
|||||||
Method string `json:"method"` // wallet, external
|
Method string `json:"method"` // wallet, external
|
||||||
AccountID string `json:"account_id"`
|
AccountID string `json:"account_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Re-export or Wrap
|
|
||||||
// Since ContentItem and Order are in the same package 'dto',
|
|
||||||
// we don't need type aliases unless we want to rename them.
|
|
||||||
// If creator.go uses them, it can use dto.ContentItem directly.
|
|
||||||
// But creator.go is in `v1` (package v1) and imports `dto`.
|
|
||||||
// So it uses `dto.ContentItem`.
|
|
||||||
// So we don't need aliases here if the original types are in this package.
|
|
||||||
|
|
||||||
// However, if the originals were in `content/dto` and `user/dto` and we moved them to `v1/dto` (this package),
|
|
||||||
// then we just have them defined in `content.go` (dto) and `user.go` (dto).
|
|
||||||
// So aliases are not needed if they are in the same package.
|
|
||||||
|
|||||||
@@ -1,9 +1,31 @@
|
|||||||
package dto
|
package dto
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"quyun/v2/app/requests"
|
||||||
"quyun/v2/pkg/consts"
|
"quyun/v2/pkg/consts"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Filters
|
||||||
|
type UserListFilter struct {
|
||||||
|
requests.Pagination
|
||||||
|
Username *string `query:"username"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type TenantListFilter struct {
|
||||||
|
requests.Pagination
|
||||||
|
Name *string `query:"name"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type SuperContentListFilter struct {
|
||||||
|
requests.Pagination
|
||||||
|
// Add filters if needed, currently list signature is just pagination in super.go service
|
||||||
|
}
|
||||||
|
|
||||||
|
type SuperOrderListFilter struct {
|
||||||
|
requests.Pagination
|
||||||
|
// Add filters if needed
|
||||||
|
}
|
||||||
|
|
||||||
// SuperUserLite 用于平台用户列表的轻量级用户信息
|
// SuperUserLite 用于平台用户列表的轻量级用户信息
|
||||||
type SuperUserLite struct {
|
type SuperUserLite struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
|
|||||||
@@ -111,21 +111,18 @@ func (r *Routes) Register(router fiber.Router) {
|
|||||||
QueryParam[string]("id"),
|
QueryParam[string]("id"),
|
||||||
))
|
))
|
||||||
r.log.Debugf("Registering route: Get /v1/creator/contents -> creator.ListContents")
|
r.log.Debugf("Registering route: Get /v1/creator/contents -> creator.ListContents")
|
||||||
router.Get("/v1/creator/contents"[len(r.Path()):], DataFunc3(
|
router.Get("/v1/creator/contents"[len(r.Path()):], DataFunc1(
|
||||||
r.creator.ListContents,
|
r.creator.ListContents,
|
||||||
QueryParam[string]("status"),
|
Query[dto.CreatorContentListFilter]("filter"),
|
||||||
QueryParam[string]("genre"),
|
|
||||||
QueryParam[string]("keyword"),
|
|
||||||
))
|
))
|
||||||
r.log.Debugf("Registering route: Get /v1/creator/dashboard -> creator.Dashboard")
|
r.log.Debugf("Registering route: Get /v1/creator/dashboard -> creator.Dashboard")
|
||||||
router.Get("/v1/creator/dashboard"[len(r.Path()):], DataFunc0(
|
router.Get("/v1/creator/dashboard"[len(r.Path()):], DataFunc0(
|
||||||
r.creator.Dashboard,
|
r.creator.Dashboard,
|
||||||
))
|
))
|
||||||
r.log.Debugf("Registering route: Get /v1/creator/orders -> creator.ListOrders")
|
r.log.Debugf("Registering route: Get /v1/creator/orders -> creator.ListOrders")
|
||||||
router.Get("/v1/creator/orders"[len(r.Path()):], DataFunc2(
|
router.Get("/v1/creator/orders"[len(r.Path()):], DataFunc1(
|
||||||
r.creator.ListOrders,
|
r.creator.ListOrders,
|
||||||
QueryParam[string]("status"),
|
Query[dto.CreatorOrderListFilter]("filter"),
|
||||||
QueryParam[string]("keyword"),
|
|
||||||
))
|
))
|
||||||
r.log.Debugf("Registering route: Get /v1/creator/payout-accounts -> creator.ListPayoutAccounts")
|
r.log.Debugf("Registering route: Get /v1/creator/payout-accounts -> creator.ListPayoutAccounts")
|
||||||
router.Get("/v1/creator/payout-accounts"[len(r.Path()):], DataFunc0(
|
router.Get("/v1/creator/payout-accounts"[len(r.Path()):], DataFunc0(
|
||||||
@@ -178,16 +175,14 @@ func (r *Routes) Register(router fiber.Router) {
|
|||||||
r.super.CheckToken,
|
r.super.CheckToken,
|
||||||
))
|
))
|
||||||
r.log.Debugf("Registering route: Get /v1/contents -> super.ListContents")
|
r.log.Debugf("Registering route: Get /v1/contents -> super.ListContents")
|
||||||
router.Get("/v1/contents"[len(r.Path()):], DataFunc2(
|
router.Get("/v1/contents"[len(r.Path()):], DataFunc1(
|
||||||
r.super.ListContents,
|
r.super.ListContents,
|
||||||
QueryParam[int]("page"),
|
Query[dto.SuperContentListFilter]("filter"),
|
||||||
QueryParam[int]("limit"),
|
|
||||||
))
|
))
|
||||||
r.log.Debugf("Registering route: Get /v1/orders -> super.ListOrders")
|
r.log.Debugf("Registering route: Get /v1/orders -> super.ListOrders")
|
||||||
router.Get("/v1/orders"[len(r.Path()):], DataFunc2(
|
router.Get("/v1/orders"[len(r.Path()):], DataFunc1(
|
||||||
r.super.ListOrders,
|
r.super.ListOrders,
|
||||||
QueryParam[int]("page"),
|
Query[dto.SuperOrderListFilter]("filter"),
|
||||||
QueryParam[int]("limit"),
|
|
||||||
))
|
))
|
||||||
r.log.Debugf("Registering route: Get /v1/orders/:id -> super.GetOrder")
|
r.log.Debugf("Registering route: Get /v1/orders/:id -> super.GetOrder")
|
||||||
router.Get("/v1/orders/:id"[len(r.Path()):], DataFunc1(
|
router.Get("/v1/orders/:id"[len(r.Path()):], DataFunc1(
|
||||||
@@ -199,11 +194,9 @@ func (r *Routes) Register(router fiber.Router) {
|
|||||||
r.super.OrderStatistics,
|
r.super.OrderStatistics,
|
||||||
))
|
))
|
||||||
r.log.Debugf("Registering route: Get /v1/tenants -> super.ListTenants")
|
r.log.Debugf("Registering route: Get /v1/tenants -> super.ListTenants")
|
||||||
router.Get("/v1/tenants"[len(r.Path()):], DataFunc3(
|
router.Get("/v1/tenants"[len(r.Path()):], DataFunc1(
|
||||||
r.super.ListTenants,
|
r.super.ListTenants,
|
||||||
QueryParam[int]("page"),
|
Query[dto.TenantListFilter]("filter"),
|
||||||
QueryParam[int]("limit"),
|
|
||||||
QueryParam[string]("name"),
|
|
||||||
))
|
))
|
||||||
r.log.Debugf("Registering route: Get /v1/tenants/:id -> super.GetTenant")
|
r.log.Debugf("Registering route: Get /v1/tenants/:id -> super.GetTenant")
|
||||||
router.Get("/v1/tenants/:id"[len(r.Path()):], DataFunc1(
|
router.Get("/v1/tenants/:id"[len(r.Path()):], DataFunc1(
|
||||||
@@ -215,11 +208,9 @@ func (r *Routes) Register(router fiber.Router) {
|
|||||||
r.super.TenantStatuses,
|
r.super.TenantStatuses,
|
||||||
))
|
))
|
||||||
r.log.Debugf("Registering route: Get /v1/users -> super.ListUsers")
|
r.log.Debugf("Registering route: Get /v1/users -> super.ListUsers")
|
||||||
router.Get("/v1/users"[len(r.Path()):], DataFunc3(
|
router.Get("/v1/users"[len(r.Path()):], DataFunc1(
|
||||||
r.super.ListUsers,
|
r.super.ListUsers,
|
||||||
QueryParam[int]("page"),
|
Query[dto.UserListFilter]("filter"),
|
||||||
QueryParam[int]("limit"),
|
|
||||||
QueryParam[string]("username"),
|
|
||||||
))
|
))
|
||||||
r.log.Debugf("Registering route: Get /v1/users/:id -> super.GetUser")
|
r.log.Debugf("Registering route: Get /v1/users/:id -> super.GetUser")
|
||||||
router.Get("/v1/users/:id"[len(r.Path()):], DataFunc1(
|
router.Get("/v1/users/:id"[len(r.Path()):], DataFunc1(
|
||||||
|
|||||||
@@ -15,294 +15,308 @@ type Super struct{}
|
|||||||
//
|
//
|
||||||
// @Router /v1/auth/login [post]
|
// @Router /v1/auth/login [post]
|
||||||
// @Summary Login
|
// @Summary Login
|
||||||
// @Tags Super
|
// @Description Login
|
||||||
|
// @Tags Auth
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Param form body dto.LoginForm true "Login form"
|
// @Param form body dto.LoginForm true "Login form"
|
||||||
// @Success 200 {object} dto.LoginResponse
|
// @Success 200 {object} dto.LoginResponse
|
||||||
// @Bind form body
|
// @Bind form body
|
||||||
func (s *Super) Login(ctx fiber.Ctx, form *dto.LoginForm) (*dto.LoginResponse, error) {
|
func (c *Super) Login(ctx fiber.Ctx, form *dto.LoginForm) (*dto.LoginResponse, error) {
|
||||||
return services.Super.Login(ctx.Context(), form)
|
return services.Super.Login(ctx.Context(), form)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check Token
|
// Check Token
|
||||||
//
|
//
|
||||||
// @Router /v1/auth/token [get]
|
// @Router /v1/auth/token [get]
|
||||||
// @Summary Check Token
|
// @Summary Check token
|
||||||
// @Tags Super
|
// @Description Check token
|
||||||
|
// @Tags Auth
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Success 200 {object} dto.LoginResponse
|
// @Success 200 {object} dto.LoginResponse
|
||||||
func (s *Super) CheckToken(ctx fiber.Ctx) (*dto.LoginResponse, error) {
|
func (c *Super) CheckToken(ctx fiber.Ctx) (*dto.LoginResponse, error) {
|
||||||
return services.Super.CheckToken(ctx.Context())
|
return services.Super.CheckToken(ctx.Context())
|
||||||
}
|
}
|
||||||
|
|
||||||
// List Users
|
// List users
|
||||||
//
|
//
|
||||||
// @Router /v1/users [get]
|
// @Router /v1/users [get]
|
||||||
// @Summary User list
|
// @Summary List users
|
||||||
// @Tags Super
|
// @Description List users
|
||||||
|
// @Tags User
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Param page query int false "Page"
|
// @Param page query int false "Page number"
|
||||||
// @Param limit query int false "Limit"
|
// @Param limit query int false "Page size"
|
||||||
// @Param username query string false "Username"
|
// @Param username query string false "Username"
|
||||||
// @Success 200 {object} requests.Pager{items=[]dto.UserItem}
|
// @Success 200 {object} requests.Pager{items=[]dto.UserItem}
|
||||||
// @Bind page query
|
// @Bind filter query
|
||||||
// @Bind limit query
|
func (c *Super) ListUsers(ctx fiber.Ctx, filter *dto.UserListFilter) (*requests.Pager, error) {
|
||||||
// @Bind username query
|
return services.Super.ListUsers(ctx.Context(), filter)
|
||||||
func (s *Super) ListUsers(ctx fiber.Ctx, page, limit int, username string) (*requests.Pager, error) {
|
|
||||||
return services.Super.ListUsers(ctx.Context(), page, limit, username)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get User
|
// Get user
|
||||||
//
|
//
|
||||||
// @Router /v1/users/:id [get]
|
// @Router /v1/users/:id [get]
|
||||||
// @Summary Get User
|
// @Summary Get user
|
||||||
// @Tags Super
|
// @Description Get user
|
||||||
|
// @Tags User
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Param id path int64 true "ID"
|
// @Param id path int64 true "User ID"
|
||||||
// @Success 200 {object} dto.UserItem
|
// @Success 200 {object} dto.UserItem
|
||||||
// @Bind id path
|
// @Bind id path
|
||||||
func (s *Super) GetUser(ctx fiber.Ctx, id int64) (*dto.UserItem, error) {
|
func (c *Super) GetUser(ctx fiber.Ctx, id int64) (*dto.UserItem, error) {
|
||||||
return services.Super.GetUser(ctx.Context(), id)
|
return services.Super.GetUser(ctx.Context(), id)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update User Status
|
// Update user status
|
||||||
//
|
//
|
||||||
// @Router /v1/users/:id/status [patch]
|
// @Router /v1/users/:id/status [patch]
|
||||||
// @Summary Update user status
|
// @Summary Update user status
|
||||||
// @Tags Super
|
// @Description Update user status
|
||||||
|
// @Tags User
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Param id path int64 true "ID"
|
// @Param id path int64 true "User ID"
|
||||||
// @Param form body dto.UserStatusUpdateForm true "Form"
|
// @Param form body dto.UserStatusUpdateForm true "Update form"
|
||||||
// @Success 200
|
// @Success 200 {string} string "Updated"
|
||||||
// @Bind id path
|
// @Bind id path
|
||||||
// @Bind form body
|
// @Bind form body
|
||||||
func (s *Super) UpdateUserStatus(ctx fiber.Ctx, id int64, form *dto.UserStatusUpdateForm) error {
|
func (c *Super) UpdateUserStatus(ctx fiber.Ctx, id int64, form *dto.UserStatusUpdateForm) error {
|
||||||
return services.Super.UpdateUserStatus(ctx.Context(), id, form)
|
return services.Super.UpdateUserStatus(ctx.Context(), id, form)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update User Roles
|
// Update user roles
|
||||||
//
|
//
|
||||||
// @Router /v1/users/:id/roles [patch]
|
// @Router /v1/users/:id/roles [patch]
|
||||||
// @Summary Update user roles
|
// @Summary Update user roles
|
||||||
// @Tags Super
|
// @Description Update user roles
|
||||||
|
// @Tags User
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Param id path int64 true "ID"
|
// @Param id path int64 true "User ID"
|
||||||
// @Param form body dto.UserRolesUpdateForm true "Form"
|
// @Param form body dto.UserRolesUpdateForm true "Update form"
|
||||||
// @Success 200
|
// @Success 200 {string} string "Updated"
|
||||||
// @Bind id path
|
// @Bind id path
|
||||||
// @Bind form body
|
// @Bind form body
|
||||||
func (s *Super) UpdateUserRoles(ctx fiber.Ctx, id int64, form *dto.UserRolesUpdateForm) error {
|
func (c *Super) UpdateUserRoles(ctx fiber.Ctx, id int64, form *dto.UserRolesUpdateForm) error {
|
||||||
return services.Super.UpdateUserRoles(ctx.Context(), id, form)
|
return services.Super.UpdateUserRoles(ctx.Context(), id, form)
|
||||||
}
|
}
|
||||||
|
|
||||||
// List Tenants
|
// List tenants
|
||||||
//
|
//
|
||||||
// @Router /v1/tenants [get]
|
// @Router /v1/tenants [get]
|
||||||
// @Summary Tenant list
|
// @Summary List tenants
|
||||||
// @Tags Super
|
// @Description List tenants
|
||||||
|
// @Tags Tenant
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Param page query int false "Page"
|
// @Param page query int false "Page number"
|
||||||
// @Param limit query int false "Limit"
|
// @Param limit query int false "Page size"
|
||||||
// @Param name query string false "Name"
|
// @Param name query string false "Name"
|
||||||
// @Success 200 {object} requests.Pager{items=[]dto.TenantItem}
|
// @Success 200 {object} requests.Pager{items=[]dto.TenantItem}
|
||||||
// @Bind page query
|
// @Bind filter query
|
||||||
// @Bind limit query
|
func (c *Super) ListTenants(ctx fiber.Ctx, filter *dto.TenantListFilter) (*requests.Pager, error) {
|
||||||
// @Bind name query
|
return services.Super.ListTenants(ctx.Context(), filter)
|
||||||
func (s *Super) ListTenants(ctx fiber.Ctx, page, limit int, name string) (*requests.Pager, error) {
|
|
||||||
return services.Super.ListTenants(ctx.Context(), page, limit, name)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create Tenant
|
// Create tenant
|
||||||
//
|
//
|
||||||
// @Router /v1/tenants [post]
|
// @Router /v1/tenants [post]
|
||||||
// @Summary Create Tenant
|
// @Summary Create tenant
|
||||||
// @Tags Super
|
// @Description Create tenant
|
||||||
|
// @Tags Tenant
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Param form body dto.TenantCreateForm true "Form"
|
// @Param form body dto.TenantCreateForm true "Create form"
|
||||||
// @Success 200
|
// @Success 200 {string} string "Created"
|
||||||
// @Bind form body
|
// @Bind form body
|
||||||
func (s *Super) CreateTenant(ctx fiber.Ctx, form *dto.TenantCreateForm) error {
|
func (c *Super) CreateTenant(ctx fiber.Ctx, form *dto.TenantCreateForm) error {
|
||||||
return services.Super.CreateTenant(ctx.Context(), form)
|
return services.Super.CreateTenant(ctx.Context(), form)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get Tenant
|
// Get tenant
|
||||||
//
|
//
|
||||||
// @Router /v1/tenants/:id [get]
|
// @Router /v1/tenants/:id [get]
|
||||||
// @Summary Get Tenant
|
// @Summary Get tenant
|
||||||
// @Tags Super
|
// @Description Get tenant
|
||||||
|
// @Tags Tenant
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Param id path int64 true "ID"
|
// @Param id path int64 true "Tenant ID"
|
||||||
// @Success 200 {object} dto.TenantItem
|
// @Success 200 {object} dto.TenantItem
|
||||||
// @Bind id path
|
// @Bind id path
|
||||||
func (s *Super) GetTenant(ctx fiber.Ctx, id int64) (*dto.TenantItem, error) {
|
func (c *Super) GetTenant(ctx fiber.Ctx, id int64) (*dto.TenantItem, error) {
|
||||||
return services.Super.GetTenant(ctx.Context(), id)
|
return services.Super.GetTenant(ctx.Context(), id)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update Tenant Status
|
// Update tenant status
|
||||||
//
|
//
|
||||||
// @Router /v1/tenants/:id/status [patch]
|
// @Router /v1/tenants/:id/status [patch]
|
||||||
// @Summary Update Tenant Status
|
// @Summary Update tenant status
|
||||||
// @Tags Super
|
// @Description Update tenant status
|
||||||
|
// @Tags Tenant
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Param id path int64 true "ID"
|
// @Param id path int64 true "Tenant ID"
|
||||||
// @Param form body dto.TenantStatusUpdateForm true "Form"
|
// @Param form body dto.TenantStatusUpdateForm true "Update form"
|
||||||
// @Success 200
|
// @Success 200 {string} string "Updated"
|
||||||
// @Bind id path
|
// @Bind id path
|
||||||
// @Bind form body
|
// @Bind form body
|
||||||
func (s *Super) UpdateTenantStatus(ctx fiber.Ctx, id int64, form *dto.TenantStatusUpdateForm) error {
|
func (c *Super) UpdateTenantStatus(ctx fiber.Ctx, id int64, form *dto.TenantStatusUpdateForm) error {
|
||||||
return services.Super.UpdateTenantStatus(ctx.Context(), id, form)
|
return services.Super.UpdateTenantStatus(ctx.Context(), id, form)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update Tenant Expire
|
// Update tenant expire
|
||||||
//
|
//
|
||||||
// @Router /v1/tenants/:id [patch]
|
// @Router /v1/tenants/:id [patch]
|
||||||
// @Summary Update Tenant Expire
|
// @Summary Update tenant expire
|
||||||
// @Tags Super
|
// @Description Update tenant expire
|
||||||
|
// @Tags Tenant
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Param id path int64 true "ID"
|
// @Param id path int64 true "Tenant ID"
|
||||||
// @Param form body dto.TenantExpireUpdateForm true "Form"
|
// @Param form body dto.TenantExpireUpdateForm true "Update form"
|
||||||
// @Success 200
|
// @Success 200 {string} string "Updated"
|
||||||
// @Bind id path
|
// @Bind id path
|
||||||
// @Bind form body
|
// @Bind form body
|
||||||
func (s *Super) UpdateTenantExpire(ctx fiber.Ctx, id int64, form *dto.TenantExpireUpdateForm) error {
|
func (c *Super) UpdateTenantExpire(ctx fiber.Ctx, id int64, form *dto.TenantExpireUpdateForm) error {
|
||||||
return services.Super.UpdateTenantExpire(ctx.Context(), id, form)
|
return services.Super.UpdateTenantExpire(ctx.Context(), id, form)
|
||||||
}
|
}
|
||||||
|
|
||||||
// List Contents
|
// List contents
|
||||||
//
|
//
|
||||||
// @Router /v1/contents [get]
|
// @Router /v1/contents [get]
|
||||||
// @Summary Content list
|
// @Summary List contents
|
||||||
// @Tags Super
|
// @Description List contents
|
||||||
|
// @Tags Content
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Param page query int false "Page"
|
// @Param page query int false "Page number"
|
||||||
// @Param limit query int false "Limit"
|
// @Param limit query int false "Page size"
|
||||||
// @Success 200 {object} requests.Pager{items=[]dto.SuperTenantContentItem}
|
// @Success 200 {object} requests.Pager{items=[]dto.AdminContentItem}
|
||||||
// @Bind page query
|
// @Bind filter query
|
||||||
// @Bind limit query
|
func (c *Super) ListContents(ctx fiber.Ctx, filter *dto.SuperContentListFilter) (*requests.Pager, error) {
|
||||||
func (s *Super) ListContents(ctx fiber.Ctx, page, limit int) (*requests.Pager, error) {
|
return services.Super.ListContents(ctx.Context(), filter)
|
||||||
return services.Super.ListContents(ctx.Context(), page, limit)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update Content Status
|
// Update content status
|
||||||
//
|
//
|
||||||
// @Router /v1/tenants/:tenantID/contents/:contentID/status [patch]
|
// @Router /v1/tenants/:tenantID/contents/:contentID/status [patch]
|
||||||
// @Summary Update Content Status
|
// @Summary Update content status
|
||||||
// @Tags Super
|
// @Description Update content status
|
||||||
|
// @Tags Content
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Param tenantID path int64 true "Tenant ID"
|
// @Param tenantID path int64 true "Tenant ID"
|
||||||
// @Param contentID path int64 true "Content ID"
|
// @Param contentID path int64 true "Content ID"
|
||||||
// @Param form body dto.SuperTenantContentStatusUpdateForm true "Form"
|
// @Param form body dto.SuperTenantContentStatusUpdateForm true "Update form"
|
||||||
// @Success 200
|
// @Success 200 {string} string "Updated"
|
||||||
// @Bind tenantID path
|
// @Bind tenantID path
|
||||||
// @Bind contentID path
|
// @Bind contentID path
|
||||||
// @Bind form body
|
// @Bind form body
|
||||||
func (s *Super) UpdateContentStatus(ctx fiber.Ctx, tenantID, contentID int64, form *dto.SuperTenantContentStatusUpdateForm) error {
|
func (c *Super) UpdateContentStatus(ctx fiber.Ctx, tenantID, contentID int64, form *dto.SuperTenantContentStatusUpdateForm) error {
|
||||||
return services.Super.UpdateContentStatus(ctx.Context(), tenantID, contentID, form)
|
return services.Super.UpdateContentStatus(ctx.Context(), tenantID, contentID, form)
|
||||||
}
|
}
|
||||||
|
|
||||||
// List Orders
|
// List orders
|
||||||
//
|
//
|
||||||
// @Router /v1/orders [get]
|
// @Router /v1/orders [get]
|
||||||
// @Summary Order list
|
// @Summary List orders
|
||||||
// @Tags Super
|
// @Description List orders
|
||||||
|
// @Tags Order
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Param page query int false "Page"
|
// @Param page query int false "Page number"
|
||||||
// @Param limit query int false "Limit"
|
// @Param limit query int false "Page size"
|
||||||
// @Success 200 {object} requests.Pager{items=[]dto.SuperOrderItem}
|
// @Success 200 {object} requests.Pager{items=[]dto.SuperOrderItem}
|
||||||
// @Bind page query
|
// @Bind filter query
|
||||||
// @Bind limit query
|
func (c *Super) ListOrders(ctx fiber.Ctx, filter *dto.SuperOrderListFilter) (*requests.Pager, error) {
|
||||||
func (s *Super) ListOrders(ctx fiber.Ctx, page, limit int) (*requests.Pager, error) {
|
return services.Super.ListOrders(ctx.Context(), filter)
|
||||||
return services.Super.ListOrders(ctx.Context(), page, limit)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get Order
|
// Get order
|
||||||
//
|
//
|
||||||
// @Router /v1/orders/:id [get]
|
// @Router /v1/orders/:id [get]
|
||||||
// @Summary Get Order
|
// @Summary Get order
|
||||||
// @Tags Super
|
// @Description Get order
|
||||||
|
// @Tags Order
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Param id path int64 true "ID"
|
// @Param id path int64 true "Order ID"
|
||||||
// @Success 200 {object} dto.SuperOrderDetail
|
// @Success 200 {object} dto.SuperOrderDetail
|
||||||
// @Bind id path
|
// @Bind id path
|
||||||
func (s *Super) GetOrder(ctx fiber.Ctx, id int64) (*dto.SuperOrderDetail, error) {
|
func (c *Super) GetOrder(ctx fiber.Ctx, id int64) (*dto.SuperOrderDetail, error) {
|
||||||
return services.Super.GetOrder(ctx.Context(), id)
|
return services.Super.GetOrder(ctx.Context(), id)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Refund Order
|
// Refund order
|
||||||
//
|
//
|
||||||
// @Router /v1/orders/:id/refund [post]
|
// @Router /v1/orders/:id/refund [post]
|
||||||
// @Summary Refund Order
|
// @Summary Refund order
|
||||||
// @Tags Super
|
// @Description Refund order
|
||||||
|
// @Tags Order
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Param id path int64 true "ID"
|
// @Param id path int64 true "Order ID"
|
||||||
// @Param form body dto.SuperOrderRefundForm true "Form"
|
// @Param form body dto.SuperOrderRefundForm true "Refund form"
|
||||||
// @Success 200
|
// @Success 200 {string} string "Refunded"
|
||||||
// @Bind id path
|
// @Bind id path
|
||||||
// @Bind form body
|
// @Bind form body
|
||||||
func (s *Super) RefundOrder(ctx fiber.Ctx, id int64, form *dto.SuperOrderRefundForm) error {
|
func (c *Super) RefundOrder(ctx fiber.Ctx, id int64, form *dto.SuperOrderRefundForm) error {
|
||||||
return services.Super.RefundOrder(ctx.Context(), id, form)
|
return services.Super.RefundOrder(ctx.Context(), id, form)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Order Statistics
|
// Order statistics
|
||||||
//
|
//
|
||||||
// @Router /v1/orders/statistics [get]
|
// @Router /v1/orders/statistics [get]
|
||||||
// @Summary Order Statistics
|
// @Summary Order statistics
|
||||||
// @Tags Super
|
// @Description Order statistics
|
||||||
|
// @Tags Order
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Success 200 {object} dto.OrderStatisticsResponse
|
// @Success 200 {object} dto.OrderStatisticsResponse
|
||||||
func (s *Super) OrderStatistics(ctx fiber.Ctx) (*dto.OrderStatisticsResponse, error) {
|
func (c *Super) OrderStatistics(ctx fiber.Ctx) (*dto.OrderStatisticsResponse, error) {
|
||||||
return services.Super.OrderStatistics(ctx.Context())
|
return services.Super.OrderStatistics(ctx.Context())
|
||||||
}
|
}
|
||||||
|
|
||||||
// User Statistics
|
// User statistics
|
||||||
//
|
//
|
||||||
// @Router /v1/users/statistics [get]
|
// @Router /v1/users/statistics [get]
|
||||||
// @Summary User Statistics
|
// @Summary User statistics
|
||||||
// @Tags Super
|
// @Description User statistics
|
||||||
|
// @Tags User
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Success 200 {array} dto.UserStatistics
|
// @Success 200 {array} dto.UserStatistics
|
||||||
func (s *Super) UserStatistics(ctx fiber.Ctx) ([]dto.UserStatistics, error) {
|
func (c *Super) UserStatistics(ctx fiber.Ctx) ([]dto.UserStatistics, error) {
|
||||||
return services.Super.UserStatistics(ctx.Context())
|
return services.Super.UserStatistics(ctx.Context())
|
||||||
}
|
}
|
||||||
|
|
||||||
// User Statuses
|
// User statuses
|
||||||
//
|
//
|
||||||
// @Router /v1/users/statuses [get]
|
// @Router /v1/users/statuses [get]
|
||||||
// @Summary User Statuses Enum
|
// @Summary User statuses
|
||||||
// @Tags Super
|
// @Description User statuses
|
||||||
|
// @Tags User
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Success 200 {array} requests.KV
|
// @Success 200 {array} requests.KV
|
||||||
func (s *Super) UserStatuses(ctx fiber.Ctx) ([]requests.KV, error) {
|
func (c *Super) UserStatuses(ctx fiber.Ctx) ([]requests.KV, error) {
|
||||||
return services.Super.UserStatuses(ctx.Context())
|
return services.Super.UserStatuses(ctx.Context())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tenant Statuses
|
// Tenant statuses
|
||||||
//
|
//
|
||||||
// @Router /v1/tenants/statuses [get]
|
// @Router /v1/tenants/statuses [get]
|
||||||
// @Summary Tenant Statuses Enum
|
// @Summary Tenant statuses
|
||||||
// @Tags Super
|
// @Description Tenant statuses
|
||||||
|
// @Tags Tenant
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Success 200 {array} requests.KV
|
// @Success 200 {array} requests.KV
|
||||||
func (s *Super) TenantStatuses(ctx fiber.Ctx) ([]requests.KV, error) {
|
func (c *Super) TenantStatuses(ctx fiber.Ctx) ([]requests.KV, error) {
|
||||||
return services.Super.TenantStatuses(ctx.Context())
|
return services.Super.TenantStatuses(ctx.Context())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,14 +23,14 @@ func (s *content) List(ctx context.Context, filter *content_dto.ContentListFilte
|
|||||||
|
|
||||||
// Filters
|
// Filters
|
||||||
q = q.Where(tbl.Status.Eq(consts.ContentStatusPublished))
|
q = q.Where(tbl.Status.Eq(consts.ContentStatusPublished))
|
||||||
if filter.Keyword != "" {
|
if filter.Keyword != nil && *filter.Keyword != "" {
|
||||||
q = q.Where(tbl.Title.Like("%" + filter.Keyword + "%"))
|
q = q.Where(tbl.Title.Like("%" + *filter.Keyword + "%"))
|
||||||
}
|
}
|
||||||
if filter.Genre != "" {
|
if filter.Genre != nil && *filter.Genre != "" {
|
||||||
q = q.Where(tbl.Genre.Eq(filter.Genre))
|
q = q.Where(tbl.Genre.Eq(*filter.Genre))
|
||||||
}
|
}
|
||||||
if filter.TenantID != "" {
|
if filter.TenantID != nil && *filter.TenantID != "" {
|
||||||
tid := cast.ToInt64(filter.TenantID)
|
tid := cast.ToInt64(*filter.TenantID)
|
||||||
q = q.Where(tbl.TenantID.Eq(tid))
|
q = q.Where(tbl.TenantID.Eq(tid))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,7 +38,12 @@ func (s *content) List(ctx context.Context, filter *content_dto.ContentListFilte
|
|||||||
q = q.Preload(tbl.Author)
|
q = q.Preload(tbl.Author)
|
||||||
|
|
||||||
// Sort
|
// Sort
|
||||||
switch filter.Sort {
|
sort := "latest"
|
||||||
|
if filter.Sort != nil && *filter.Sort != "" {
|
||||||
|
sort = *filter.Sort
|
||||||
|
}
|
||||||
|
|
||||||
|
switch sort {
|
||||||
case "hot":
|
case "hot":
|
||||||
q = q.Order(tbl.Views.Desc())
|
q = q.Order(tbl.Views.Desc())
|
||||||
case "price_asc":
|
case "price_asc":
|
||||||
@@ -48,7 +53,6 @@ func (s *content) List(ctx context.Context, filter *content_dto.ContentListFilte
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Pagination
|
// Pagination
|
||||||
// Use embedded pagination directly
|
|
||||||
filter.Pagination.Format()
|
filter.Pagination.Format()
|
||||||
total, err := q.Count()
|
total, err := q.Count()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -66,8 +66,9 @@ func (s *ContentTestSuite) Test_List() {
|
|||||||
models.ContentQuery.WithContext(ctx).Create(c1, c2)
|
models.ContentQuery.WithContext(ctx).Create(c1, c2)
|
||||||
|
|
||||||
Convey("should list only published contents", func() {
|
Convey("should list only published contents", func() {
|
||||||
|
tid := "1"
|
||||||
filter := &content_dto.ContentListFilter{
|
filter := &content_dto.ContentListFilter{
|
||||||
TenantID: "1",
|
TenantID: &tid,
|
||||||
Pagination: requests.Pagination{
|
Pagination: requests.Pagination{
|
||||||
Page: 1,
|
Page: 1,
|
||||||
Limit: 10,
|
Limit: 10,
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ func (s *creator) Dashboard(ctx context.Context) (*creator_dto.DashboardStats, e
|
|||||||
return stats, nil
|
return stats, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *creator) ListContents(ctx context.Context, status, genre, keyword string) ([]creator_dto.ContentItem, error) {
|
func (s *creator) ListContents(ctx context.Context, filter *creator_dto.CreatorContentListFilter) ([]creator_dto.ContentItem, error) {
|
||||||
tid, err := s.getTenantID(ctx)
|
tid, err := s.getTenantID(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -89,14 +89,14 @@ func (s *creator) ListContents(ctx context.Context, status, genre, keyword strin
|
|||||||
tbl, q := models.ContentQuery.QueryContext(ctx)
|
tbl, q := models.ContentQuery.QueryContext(ctx)
|
||||||
q = q.Where(tbl.TenantID.Eq(tid))
|
q = q.Where(tbl.TenantID.Eq(tid))
|
||||||
|
|
||||||
if status != "" {
|
if filter.Status != nil && *filter.Status != "" {
|
||||||
q = q.Where(tbl.Status.Eq(consts.ContentStatus(status)))
|
q = q.Where(tbl.Status.Eq(consts.ContentStatus(*filter.Status)))
|
||||||
}
|
}
|
||||||
if genre != "" {
|
if filter.Genre != nil && *filter.Genre != "" {
|
||||||
q = q.Where(tbl.Genre.Eq(genre))
|
q = q.Where(tbl.Genre.Eq(*filter.Genre))
|
||||||
}
|
}
|
||||||
if keyword != "" {
|
if filter.Keyword != nil && *filter.Keyword != "" {
|
||||||
q = q.Where(tbl.Title.Like("%" + keyword + "%"))
|
q = q.Where(tbl.Title.Like("%" + *filter.Keyword + "%"))
|
||||||
}
|
}
|
||||||
|
|
||||||
list, err := q.Order(tbl.CreatedAt.Desc()).Find()
|
list, err := q.Order(tbl.CreatedAt.Desc()).Find()
|
||||||
@@ -190,7 +190,7 @@ func (s *creator) DeleteContent(ctx context.Context, id string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *creator) ListOrders(ctx context.Context, status, keyword string) ([]creator_dto.Order, error) {
|
func (s *creator) ListOrders(ctx context.Context, filter *creator_dto.CreatorOrderListFilter) ([]creator_dto.Order, error) {
|
||||||
tid, err := s.getTenantID(ctx)
|
tid, err := s.getTenantID(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -198,7 +198,12 @@ func (s *creator) ListOrders(ctx context.Context, status, keyword string) ([]cre
|
|||||||
|
|
||||||
tbl, q := models.OrderQuery.QueryContext(ctx)
|
tbl, q := models.OrderQuery.QueryContext(ctx)
|
||||||
q = q.Where(tbl.TenantID.Eq(tid))
|
q = q.Where(tbl.TenantID.Eq(tid))
|
||||||
// Filters...
|
|
||||||
|
if filter.Status != nil && *filter.Status != "" {
|
||||||
|
q = q.Where(tbl.Status.Eq(consts.OrderStatus(*filter.Status)))
|
||||||
|
}
|
||||||
|
// Keyword could match ID or other fields if needed
|
||||||
|
|
||||||
list, err := q.Order(tbl.CreatedAt.Desc()).Find()
|
list, err := q.Order(tbl.CreatedAt.Desc()).Find()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errorx.ErrDatabaseError.WithCause(err)
|
return nil, errorx.ErrDatabaseError.WithCause(err)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package services
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"quyun/v2/app/errorx"
|
"quyun/v2/app/errorx"
|
||||||
@@ -13,6 +14,7 @@ import (
|
|||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/spf13/cast"
|
"github.com/spf13/cast"
|
||||||
"go.ipao.vip/gen/types"
|
"go.ipao.vip/gen/types"
|
||||||
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
// @provider
|
// @provider
|
||||||
@@ -27,21 +29,21 @@ func (s *super) CheckToken(ctx context.Context) (*super_dto.LoginResponse, error
|
|||||||
return &super_dto.LoginResponse{}, nil
|
return &super_dto.LoginResponse{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *super) ListUsers(ctx context.Context, page, limit int, username string) (*requests.Pager, error) {
|
func (s *super) ListUsers(ctx context.Context, filter *super_dto.UserListFilter) (*requests.Pager, error) {
|
||||||
tbl, q := models.UserQuery.QueryContext(ctx)
|
tbl, q := models.UserQuery.QueryContext(ctx)
|
||||||
if username != "" {
|
if filter.Username != nil && *filter.Username != "" {
|
||||||
q = q.Where(tbl.Username.Like("%" + username + "%")).Or(tbl.Nickname.Like("%" + username + "%"))
|
q = q.Where(tbl.Username.Like("%" + *filter.Username + "%")).Or(tbl.Nickname.Like("%" + *filter.Username + "%"))
|
||||||
}
|
}
|
||||||
|
|
||||||
p := requests.Pagination{Page: int64(page), Limit: int64(limit)}
|
filter.Pagination.Format()
|
||||||
total, err := q.Count()
|
total, err := q.Count()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errorx.ErrDatabaseError
|
return nil, errorx.ErrDatabaseError.WithCause(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
list, err := q.Offset(int(p.Offset())).Limit(int(p.Limit)).Order(tbl.ID.Desc()).Find()
|
list, err := q.Offset(int(filter.Pagination.Offset())).Limit(int(filter.Pagination.Limit)).Order(tbl.ID.Desc()).Find()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errorx.ErrDatabaseError
|
return nil, errorx.ErrDatabaseError.WithCause(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var data []super_dto.UserItem
|
var data []super_dto.UserItem
|
||||||
@@ -52,8 +54,6 @@ func (s *super) ListUsers(ctx context.Context, page, limit int, username string)
|
|||||||
Username: u.Username,
|
Username: u.Username,
|
||||||
Roles: u.Roles,
|
Roles: u.Roles,
|
||||||
Status: u.Status,
|
Status: u.Status,
|
||||||
// StatusDescription: u.Status.Description(), // Status is consts.UserStatus, it has Description()
|
|
||||||
// But u.Status might be string if gen didn't map it properly? No, it's consts.UserStatus.
|
|
||||||
StatusDescription: u.Status.Description(),
|
StatusDescription: u.Status.Description(),
|
||||||
CreatedAt: u.CreatedAt.Format(time.RFC3339),
|
CreatedAt: u.CreatedAt.Format(time.RFC3339),
|
||||||
UpdatedAt: u.UpdatedAt.Format(time.RFC3339),
|
UpdatedAt: u.UpdatedAt.Format(time.RFC3339),
|
||||||
@@ -64,7 +64,7 @@ func (s *super) ListUsers(ctx context.Context, page, limit int, username string)
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &requests.Pager{
|
return &requests.Pager{
|
||||||
Pagination: p,
|
Pagination: filter.Pagination,
|
||||||
Total: total,
|
Total: total,
|
||||||
Items: data,
|
Items: data,
|
||||||
}, nil
|
}, nil
|
||||||
@@ -74,8 +74,11 @@ func (s *super) GetUser(ctx context.Context, id int64) (*super_dto.UserItem, err
|
|||||||
tbl, q := models.UserQuery.QueryContext(ctx)
|
tbl, q := models.UserQuery.QueryContext(ctx)
|
||||||
u, err := q.Where(tbl.ID.Eq(id)).First()
|
u, err := q.Where(tbl.ID.Eq(id)).First()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
return nil, errorx.ErrRecordNotFound
|
return nil, errorx.ErrRecordNotFound
|
||||||
}
|
}
|
||||||
|
return nil, errorx.ErrDatabaseError.WithCause(err)
|
||||||
|
}
|
||||||
return &super_dto.UserItem{
|
return &super_dto.UserItem{
|
||||||
SuperUserLite: super_dto.SuperUserLite{
|
SuperUserLite: super_dto.SuperUserLite{
|
||||||
ID: u.ID,
|
ID: u.ID,
|
||||||
@@ -95,7 +98,7 @@ func (s *super) UpdateUserStatus(ctx context.Context, id int64, form *super_dto.
|
|||||||
tbl, q := models.UserQuery.QueryContext(ctx)
|
tbl, q := models.UserQuery.QueryContext(ctx)
|
||||||
_, err := q.Where(tbl.ID.Eq(id)).Update(tbl.Status, consts.UserStatus(form.Status))
|
_, err := q.Where(tbl.ID.Eq(id)).Update(tbl.Status, consts.UserStatus(form.Status))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errorx.ErrDatabaseError
|
return errorx.ErrDatabaseError.WithCause(err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -108,26 +111,26 @@ func (s *super) UpdateUserRoles(ctx context.Context, id int64, form *super_dto.U
|
|||||||
tbl, q := models.UserQuery.QueryContext(ctx)
|
tbl, q := models.UserQuery.QueryContext(ctx)
|
||||||
_, err := q.Where(tbl.ID.Eq(id)).Update(tbl.Roles, roles)
|
_, err := q.Where(tbl.ID.Eq(id)).Update(tbl.Roles, roles)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errorx.ErrDatabaseError
|
return errorx.ErrDatabaseError.WithCause(err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *super) ListTenants(ctx context.Context, page, limit int, name string) (*requests.Pager, error) {
|
func (s *super) ListTenants(ctx context.Context, filter *super_dto.TenantListFilter) (*requests.Pager, error) {
|
||||||
tbl, q := models.TenantQuery.QueryContext(ctx)
|
tbl, q := models.TenantQuery.QueryContext(ctx)
|
||||||
if name != "" {
|
if filter.Name != nil && *filter.Name != "" {
|
||||||
q = q.Where(tbl.Name.Like("%" + name + "%"))
|
q = q.Where(tbl.Name.Like("%" + *filter.Name + "%"))
|
||||||
}
|
}
|
||||||
|
|
||||||
p := requests.Pagination{Page: int64(page), Limit: int64(limit)}
|
filter.Pagination.Format()
|
||||||
total, err := q.Count()
|
total, err := q.Count()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errorx.ErrDatabaseError
|
return nil, errorx.ErrDatabaseError.WithCause(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
list, err := q.Offset(int(p.Offset())).Limit(int(p.Limit)).Order(tbl.ID.Desc()).Find()
|
list, err := q.Offset(int(filter.Pagination.Offset())).Limit(int(filter.Pagination.Limit)).Order(tbl.ID.Desc()).Find()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errorx.ErrDatabaseError
|
return nil, errorx.ErrDatabaseError.WithCause(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var data []super_dto.TenantItem
|
var data []super_dto.TenantItem
|
||||||
@@ -146,7 +149,7 @@ func (s *super) ListTenants(ctx context.Context, page, limit int, name string) (
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &requests.Pager{
|
return &requests.Pager{
|
||||||
Pagination: p,
|
Pagination: filter.Pagination,
|
||||||
Total: total,
|
Total: total,
|
||||||
Items: data,
|
Items: data,
|
||||||
}, nil
|
}, nil
|
||||||
@@ -166,7 +169,7 @@ func (s *super) CreateTenant(ctx context.Context, form *super_dto.TenantCreateFo
|
|||||||
Status: consts.TenantStatusVerified,
|
Status: consts.TenantStatusVerified,
|
||||||
}
|
}
|
||||||
if err := models.TenantQuery.WithContext(ctx).Create(t); err != nil {
|
if err := models.TenantQuery.WithContext(ctx).Create(t); err != nil {
|
||||||
return errorx.ErrDatabaseError
|
return errorx.ErrDatabaseError.WithCause(err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -175,8 +178,11 @@ func (s *super) GetTenant(ctx context.Context, id int64) (*super_dto.TenantItem,
|
|||||||
tbl, q := models.TenantQuery.QueryContext(ctx)
|
tbl, q := models.TenantQuery.QueryContext(ctx)
|
||||||
t, err := q.Where(tbl.ID.Eq(id)).First()
|
t, err := q.Where(tbl.ID.Eq(id)).First()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
return nil, errorx.ErrRecordNotFound
|
return nil, errorx.ErrRecordNotFound
|
||||||
}
|
}
|
||||||
|
return nil, errorx.ErrDatabaseError.WithCause(err)
|
||||||
|
}
|
||||||
return &super_dto.TenantItem{
|
return &super_dto.TenantItem{
|
||||||
ID: t.ID,
|
ID: t.ID,
|
||||||
UUID: t.UUID.String(),
|
UUID: t.UUID.String(),
|
||||||
@@ -194,7 +200,7 @@ func (s *super) UpdateTenantStatus(ctx context.Context, id int64, form *super_dt
|
|||||||
tbl, q := models.TenantQuery.QueryContext(ctx)
|
tbl, q := models.TenantQuery.QueryContext(ctx)
|
||||||
_, err := q.Where(tbl.ID.Eq(id)).Update(tbl.Status, consts.TenantStatus(form.Status))
|
_, err := q.Where(tbl.ID.Eq(id)).Update(tbl.Status, consts.TenantStatus(form.Status))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errorx.ErrDatabaseError
|
return errorx.ErrDatabaseError.WithCause(err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -204,21 +210,22 @@ func (s *super) UpdateTenantExpire(ctx context.Context, id int64, form *super_dt
|
|||||||
tbl, q := models.TenantQuery.QueryContext(ctx)
|
tbl, q := models.TenantQuery.QueryContext(ctx)
|
||||||
_, err := q.Where(tbl.ID.Eq(id)).Update(tbl.ExpiredAt, expire)
|
_, err := q.Where(tbl.ID.Eq(id)).Update(tbl.ExpiredAt, expire)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errorx.ErrDatabaseError
|
return errorx.ErrDatabaseError.WithCause(err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *super) ListContents(ctx context.Context, page, limit int) (*requests.Pager, error) {
|
func (s *super) ListContents(ctx context.Context, filter *super_dto.SuperContentListFilter) (*requests.Pager, error) {
|
||||||
tbl, q := models.ContentQuery.QueryContext(ctx)
|
tbl, q := models.ContentQuery.QueryContext(ctx)
|
||||||
p := requests.Pagination{Page: int64(page), Limit: int64(limit)}
|
|
||||||
|
filter.Pagination.Format()
|
||||||
total, err := q.Count()
|
total, err := q.Count()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errorx.ErrDatabaseError
|
return nil, errorx.ErrDatabaseError.WithCause(err)
|
||||||
}
|
}
|
||||||
list, err := q.Offset(int(p.Offset())).Limit(int(p.Limit)).Order(tbl.ID.Desc()).Find()
|
list, err := q.Offset(int(filter.Pagination.Offset())).Limit(int(filter.Pagination.Limit)).Order(tbl.ID.Desc()).Find()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errorx.ErrDatabaseError
|
return nil, errorx.ErrDatabaseError.WithCause(err)
|
||||||
}
|
}
|
||||||
// Simplified DTO for list
|
// Simplified DTO for list
|
||||||
var data []any
|
var data []any
|
||||||
@@ -226,7 +233,7 @@ func (s *super) ListContents(ctx context.Context, page, limit int) (*requests.Pa
|
|||||||
data = append(data, c) // TODO: Map to DTO
|
data = append(data, c) // TODO: Map to DTO
|
||||||
}
|
}
|
||||||
return &requests.Pager{
|
return &requests.Pager{
|
||||||
Pagination: p,
|
Pagination: filter.Pagination,
|
||||||
Total: total,
|
Total: total,
|
||||||
Items: data,
|
Items: data,
|
||||||
}, nil
|
}, nil
|
||||||
@@ -236,25 +243,26 @@ func (s *super) UpdateContentStatus(ctx context.Context, tenantID, contentID int
|
|||||||
tbl, q := models.ContentQuery.QueryContext(ctx)
|
tbl, q := models.ContentQuery.QueryContext(ctx)
|
||||||
_, err := q.Where(tbl.ID.Eq(contentID), tbl.TenantID.Eq(tenantID)).Update(tbl.Status, consts.ContentStatus(form.Status))
|
_, err := q.Where(tbl.ID.Eq(contentID), tbl.TenantID.Eq(tenantID)).Update(tbl.Status, consts.ContentStatus(form.Status))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errorx.ErrDatabaseError
|
return errorx.ErrDatabaseError.WithCause(err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *super) ListOrders(ctx context.Context, page, limit int) (*requests.Pager, error) {
|
func (s *super) ListOrders(ctx context.Context, filter *super_dto.SuperOrderListFilter) (*requests.Pager, error) {
|
||||||
tbl, q := models.OrderQuery.QueryContext(ctx)
|
tbl, q := models.OrderQuery.QueryContext(ctx)
|
||||||
p := requests.Pagination{Page: int64(page), Limit: int64(limit)}
|
|
||||||
|
filter.Pagination.Format()
|
||||||
total, err := q.Count()
|
total, err := q.Count()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errorx.ErrDatabaseError
|
return nil, errorx.ErrDatabaseError.WithCause(err)
|
||||||
}
|
}
|
||||||
list, err := q.Offset(int(p.Offset())).Limit(int(p.Limit)).Order(tbl.ID.Desc()).Find()
|
list, err := q.Offset(int(filter.Pagination.Offset())).Limit(int(filter.Pagination.Limit)).Order(tbl.ID.Desc()).Find()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errorx.ErrDatabaseError
|
return nil, errorx.ErrDatabaseError.WithCause(err)
|
||||||
}
|
}
|
||||||
// TODO: Map to DTO
|
// TODO: Map to DTO
|
||||||
return &requests.Pager{
|
return &requests.Pager{
|
||||||
Pagination: p,
|
Pagination: filter.Pagination,
|
||||||
Total: total,
|
Total: total,
|
||||||
Items: list,
|
Items: list,
|
||||||
}, nil
|
}, nil
|
||||||
|
|||||||
@@ -6,10 +6,12 @@ import (
|
|||||||
|
|
||||||
"quyun/v2/app/commands/testx"
|
"quyun/v2/app/commands/testx"
|
||||||
super_dto "quyun/v2/app/http/v1/dto"
|
super_dto "quyun/v2/app/http/v1/dto"
|
||||||
|
"quyun/v2/app/requests"
|
||||||
"quyun/v2/database"
|
"quyun/v2/database"
|
||||||
"quyun/v2/database/models"
|
"quyun/v2/database/models"
|
||||||
"quyun/v2/pkg/consts"
|
"quyun/v2/pkg/consts"
|
||||||
|
|
||||||
|
"github.com/samber/lo"
|
||||||
. "github.com/smartystreets/goconvey/convey"
|
. "github.com/smartystreets/goconvey/convey"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
"go.ipao.vip/atom/contracts"
|
"go.ipao.vip/atom/contracts"
|
||||||
@@ -46,7 +48,10 @@ func (s *SuperTestSuite) Test_ListUsers() {
|
|||||||
models.UserQuery.WithContext(ctx).Create(u1, u2)
|
models.UserQuery.WithContext(ctx).Create(u1, u2)
|
||||||
|
|
||||||
Convey("should list users", func() {
|
Convey("should list users", func() {
|
||||||
res, err := Super.ListUsers(ctx, 1, 10, "")
|
filter := &super_dto.UserListFilter{
|
||||||
|
Pagination: requests.Pagination{Page: 1, Limit: 10},
|
||||||
|
}
|
||||||
|
res, err := Super.ListUsers(ctx, filter)
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
So(res.Total, ShouldEqual, 2)
|
So(res.Total, ShouldEqual, 2)
|
||||||
|
|
||||||
@@ -55,7 +60,11 @@ func (s *SuperTestSuite) Test_ListUsers() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
Convey("should filter users", func() {
|
Convey("should filter users", func() {
|
||||||
res, err := Super.ListUsers(ctx, 1, 10, "Alice")
|
filter := &super_dto.UserListFilter{
|
||||||
|
Pagination: requests.Pagination{Page: 1, Limit: 10},
|
||||||
|
Username: lo.ToPtr("Alice"),
|
||||||
|
}
|
||||||
|
res, err := Super.ListUsers(ctx, filter)
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
So(res.Total, ShouldEqual, 1)
|
So(res.Total, ShouldEqual, 1)
|
||||||
items := res.Items.([]super_dto.UserItem)
|
items := res.Items.([]super_dto.UserItem)
|
||||||
|
|||||||
Reference in New Issue
Block a user