Refactor super module: Move HTTP handlers to new super/v1 package

- Deleted old super.go file and moved all related HTTP handlers to new package structure under backend/app/http/super/v1.
- Updated service imports in super.go and super_test.go to reflect new DTO paths.
- Created new auth, contents, orders, tenants, and users handlers with corresponding routes and methods.
- Added new DTO definitions for authentication and content management in the super/v1/dto directory.
- Implemented new migration for content_access table and created model for it.
This commit is contained in:
2025-12-29 17:17:07 +08:00
parent bdf20fb0c6
commit 33e1921e17
18 changed files with 665 additions and 443 deletions

View File

@@ -0,0 +1,39 @@
package v1
import (
dto "quyun/v2/app/http/super/v1/dto"
"quyun/v2/app/services"
"github.com/gofiber/fiber/v3"
)
// @provider
type auth struct{}
// Login
//
// @Router /super/v1/auth/login [post]
// @Summary Login
// @Description Login
// @Tags Auth
// @Accept json
// @Produce json
// @Param form body dto.LoginForm true "Login form"
// @Success 200 {object} dto.LoginResponse
// @Bind form body
func (c *auth) Login(ctx fiber.Ctx, form *dto.LoginForm) (*dto.LoginResponse, error) {
return services.Super.Login(ctx.Context(), form)
}
// Check Token
//
// @Router /super/v1/auth/token [get]
// @Summary Check token
// @Description Check token
// @Tags Auth
// @Accept json
// @Produce json
// @Success 200 {object} dto.LoginResponse
func (c *auth) CheckToken(ctx fiber.Ctx) (*dto.LoginResponse, error) {
return services.Super.CheckToken(ctx.Context())
}

View File

@@ -0,0 +1,47 @@
package v1
import (
dto "quyun/v2/app/http/super/v1/dto"
"quyun/v2/app/requests"
"quyun/v2/app/services"
"github.com/gofiber/fiber/v3"
)
// @provider
type contents struct{}
// List contents
//
// @Router /super/v1/contents [get]
// @Summary List contents
// @Description List contents
// @Tags Content
// @Accept json
// @Produce json
// @Param page query int false "Page number"
// @Param limit query int false "Page size"
// @Success 200 {object} requests.Pager{items=[]dto.AdminContentItem}
// @Bind filter query
func (c *contents) List(ctx fiber.Ctx, filter *dto.SuperContentListFilter) (*requests.Pager, error) {
return services.Super.ListContents(ctx.Context(), filter)
}
// Update content status
//
// @Router /super/v1/tenants/:tenantID/contents/:contentID/status [patch]
// @Summary Update content status
// @Description Update content status
// @Tags Content
// @Accept json
// @Produce json
// @Param tenantID path int64 true "Tenant ID"
// @Param contentID path int64 true "Content ID"
// @Param form body dto.SuperTenantContentStatusUpdateForm true "Update form"
// @Success 200 {string} string "Updated"
// @Bind tenantID path
// @Bind contentID path
// @Bind form body
func (c *contents) UpdateStatus(ctx fiber.Ctx, tenantID, contentID int64, form *dto.SuperTenantContentStatusUpdateForm) error {
return services.Super.UpdateContentStatus(ctx.Context(), tenantID, contentID, form)
}

View File

@@ -0,0 +1,32 @@
package dto
import "quyun/v2/pkg/consts"
type LoginForm struct {
Phone string `json:"phone"`
OTP string `json:"otp"`
}
type LoginResponse struct {
Token string `json:"token"`
User *User `json:"user"`
}
type User struct {
ID string `json:"id"`
Phone string `json:"phone"`
Nickname string `json:"nickname"`
Avatar string `json:"avatar"`
Gender consts.Gender `json:"gender"`
Bio string `json:"bio"`
Birthday string `json:"birthday"` // YYYY-MM-DD
Location *Location `json:"location"`
Balance float64 `json:"balance"`
Points int64 `json:"points"`
IsRealNameVerified bool `json:"is_real_name_verified"`
}
type Location struct {
Province string `json:"province"`
City string `json:"city"`
}

View File

@@ -0,0 +1,225 @@
package dto
import (
v1_dto "quyun/v2/app/http/v1/dto"
"quyun/v2/app/requests"
"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 用于平台用户列表的轻量级用户信息
type SuperUserLite struct {
ID int64 `json:"id"`
Username string `json:"username"`
Roles []consts.Role `json:"roles"`
Status consts.UserStatus `json:"status"`
StatusDescription string `json:"status_description"`
VerifiedAt string `json:"verified_at"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
}
type UserItem struct {
SuperUserLite
Balance int64 `json:"balance"`
BalanceFrozen int64 `json:"balance_frozen"`
OwnedTenantCount int64 `json:"owned_tenant_count"`
JoinedTenantCount int64 `json:"joined_tenant_count"`
}
type UserStatistics struct {
Status consts.UserStatus `json:"status"`
StatusDescription string `json:"status_description"`
Count int64 `json:"count"`
}
type UserStatusUpdateForm struct {
Status consts.UserStatus `json:"status" validate:"required"`
}
type UserRolesUpdateForm struct {
Roles []consts.Role `json:"roles" validate:"required,min=1"`
}
type UserTenantItem struct {
TenantID int64 `json:"tenant_id"`
TenantStatus consts.TenantStatus `json:"tenant_status"`
TenantStatusDescription string `json:"tenant_status_description"`
Name string `json:"name"`
Code string `json:"code"`
Owner *TenantOwnerUserLite `json:"owner"`
Role []consts.TenantUserRole `json:"role"`
MemberStatus consts.UserStatus `json:"member_status"`
MemberStatusDescription string `json:"member_status_description"`
JoinedAt string `json:"joined_at"`
ExpiredAt string `json:"expired_at"`
}
// Tenant Related
type TenantCreateForm struct {
Name string `json:"name" validate:"required,max=128"`
Code string `json:"code" validate:"required,max=64"`
AdminUserID int64 `json:"admin_user_id" validate:"required"`
Duration int `json:"duration" validate:"required,oneof=7 30 90 180 365"`
}
type TenantItem struct {
ID int64 `json:"id"`
UUID string `json:"uuid"`
Code string `json:"code"`
Name string `json:"name"`
Status consts.TenantStatus `json:"status"`
StatusDescription string `json:"status_description"`
Config []int `json:"config"` // Replace with actual config struct if needed
Owner *TenantOwnerUserLite `json:"owner"`
AdminUsers []*TenantAdminUserLite `json:"admin_users"`
UserCount int64 `json:"user_count"`
IncomeAmountPaidSum int64 `json:"income_amount_paid_sum"`
ExpiredAt string `json:"expired_at"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
UserID int64 `json:"user_id"`
Users []*SuperUserLite `json:"users"`
}
type TenantOwnerUserLite struct {
ID int64 `json:"id"`
Username string `json:"username"`
}
type TenantAdminUserLite struct {
ID int64 `json:"id"`
Username string `json:"username"`
}
type TenantExpireUpdateForm struct {
Duration int `json:"duration" validate:"required,oneof=7 30 90 180 365"`
}
type TenantStatusUpdateForm struct {
Status consts.TenantStatus `json:"status" validate:"required"`
}
type SuperTenantContentItem struct {
Content *v1_dto.ContentItem `json:"content"`
StatusDescription string `json:"status_description"`
VisibilityDescription string `json:"visibility_description"`
Tenant *SuperContentTenantLite `json:"tenant"`
Owner *SuperUserLite `json:"owner"`
Price *v1_dto.ContentPrice `json:"price"`
}
type SuperContentTenantLite struct {
ID int64 `json:"id"`
Code string `json:"code"`
Name string `json:"name"`
}
type SuperTenantContentStatusUpdateForm struct {
Status consts.ContentStatus `json:"status" validate:"required,oneof=unpublished blocked"`
}
type SuperTenantUserItem struct {
User *SuperUserLite `json:"user"`
TenantUser *TenantUser `json:"tenant_user"`
}
type TenantUser struct {
ID int64 `json:"id"`
TenantID int64 `json:"tenant_id"`
UserID int64 `json:"user_id"`
Role []consts.TenantUserRole `json:"role"`
Status consts.UserStatus `json:"status"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
}
// Order Related
type SuperOrderItem struct {
ID int64 `json:"id"`
Type consts.OrderType `json:"type"`
Status consts.OrderStatus `json:"status"`
StatusDescription string `json:"status_description"`
Currency consts.Currency `json:"currency"`
AmountOriginal int64 `json:"amount_original"`
AmountDiscount int64 `json:"amount_discount"`
AmountPaid int64 `json:"amount_paid"`
Tenant *OrderTenantLite `json:"tenant"`
Buyer *OrderBuyerLite `json:"buyer"`
PaidAt string `json:"paid_at"`
RefundedAt string `json:"refunded_at"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
}
type OrderTenantLite struct {
ID int64 `json:"id"`
Code string `json:"code"`
Name string `json:"name"`
}
type OrderBuyerLite struct {
ID int64 `json:"id"`
Username string `json:"username"`
}
type OrderStatisticsResponse struct {
TotalCount int64 `json:"total_count"`
TotalAmountPaidSum int64 `json:"total_amount_paid_sum"`
ByStatus []OrderStatisticsRow `json:"by_status"`
}
type OrderStatisticsRow struct {
Status consts.OrderStatus `json:"status"`
StatusDescription string `json:"status_description"`
Count int64 `json:"count"`
AmountPaidSum int64 `json:"amount_paid_sum"`
}
type SuperOrderDetail struct {
Order *SuperOrderItem `json:"order"` // Using SuperOrderItem as base, extend if needed
Tenant *OrderTenantLite `json:"tenant"`
Buyer *OrderBuyerLite `json:"buyer"`
}
type SuperOrderRefundForm struct {
Force bool `json:"force"`
Reason string `json:"reason"`
IdempotencyKey string `json:"idempotency_key"`
}
// AdminContentItem for super admin view
type AdminContentItem struct {
Content *v1_dto.ContentItem `json:"content"`
Owner *AdminContentOwnerLite `json:"owner"`
Price *v1_dto.ContentPrice `json:"price"`
StatusDescription string `json:"status_description"`
VisibilityDescription string `json:"visibility_description"`
}
type AdminContentOwnerLite struct {
ID int64 `json:"id"`
Username string `json:"username"`
Roles []consts.Role `json:"roles"`
Status consts.UserStatus `json:"status"`
}

View File

@@ -0,0 +1,73 @@
package v1
import (
dto "quyun/v2/app/http/super/v1/dto"
"quyun/v2/app/requests"
"quyun/v2/app/services"
"github.com/gofiber/fiber/v3"
)
// @provider
type orders struct{}
// List orders
//
// @Router /super/v1/orders [get]
// @Summary List orders
// @Description List orders
// @Tags Order
// @Accept json
// @Produce json
// @Param page query int false "Page number"
// @Param limit query int false "Page size"
// @Success 200 {object} requests.Pager{items=[]dto.SuperOrderItem}
// @Bind filter query
func (c *orders) List(ctx fiber.Ctx, filter *dto.SuperOrderListFilter) (*requests.Pager, error) {
return services.Super.ListOrders(ctx.Context(), filter)
}
// Get order
//
// @Router /super/v1/orders/:id [get]
// @Summary Get order
// @Description Get order
// @Tags Order
// @Accept json
// @Produce json
// @Param id path int64 true "Order ID"
// @Success 200 {object} dto.SuperOrderDetail
// @Bind id path
func (c *orders) Get(ctx fiber.Ctx, id int64) (*dto.SuperOrderDetail, error) {
return services.Super.GetOrder(ctx.Context(), id)
}
// Refund order
//
// @Router /super/v1/orders/:id/refund [post]
// @Summary Refund order
// @Description Refund order
// @Tags Order
// @Accept json
// @Produce json
// @Param id path int64 true "Order ID"
// @Param form body dto.SuperOrderRefundForm true "Refund form"
// @Success 200 {string} string "Refunded"
// @Bind id path
// @Bind form body
func (c *orders) Refund(ctx fiber.Ctx, id int64, form *dto.SuperOrderRefundForm) error {
return services.Super.RefundOrder(ctx.Context(), id, form)
}
// Order statistics
//
// @Router /super/v1/orders/statistics [get]
// @Summary Order statistics
// @Description Order statistics
// @Tags Order
// @Accept json
// @Produce json
// @Success 200 {object} dto.OrderStatisticsResponse
func (c *orders) Statistics(ctx fiber.Ctx) (*dto.OrderStatisticsResponse, error) {
return services.Super.OrderStatistics(ctx.Context())
}

View File

@@ -0,0 +1,73 @@
package v1
import (
"quyun/v2/app/middlewares"
"go.ipao.vip/atom"
"go.ipao.vip/atom/container"
"go.ipao.vip/atom/contracts"
"go.ipao.vip/atom/opt"
)
func Provide(opts ...opt.Option) error {
if err := container.Container.Provide(func() (*auth, error) {
obj := &auth{}
return obj, nil
}); err != nil {
return err
}
if err := container.Container.Provide(func() (*contents, error) {
obj := &contents{}
return obj, nil
}); err != nil {
return err
}
if err := container.Container.Provide(func() (*orders, error) {
obj := &orders{}
return obj, nil
}); err != nil {
return err
}
if err := container.Container.Provide(func(
auth *auth,
contents *contents,
middlewares *middlewares.Middlewares,
orders *orders,
tenants *tenants,
users *users,
) (contracts.HttpRoute, error) {
obj := &Routes{
auth: auth,
contents: contents,
middlewares: middlewares,
orders: orders,
tenants: tenants,
users: users,
}
if err := obj.Prepare(); err != nil {
return nil, err
}
return obj, nil
}, atom.GroupRoutes); err != nil {
return err
}
if err := container.Container.Provide(func() (*tenants, error) {
obj := &tenants{}
return obj, nil
}); err != nil {
return err
}
if err := container.Container.Provide(func() (*users, error) {
obj := &users{}
return obj, nil
}); err != nil {
return err
}
return nil
}

View File

@@ -0,0 +1,157 @@
// Code generated by atomctl. DO NOT EDIT.
// Package v1 provides HTTP route definitions and registration
// for the quyun/v2 application.
package v1
import (
dto "quyun/v2/app/http/super/v1/dto"
"quyun/v2/app/middlewares"
"github.com/gofiber/fiber/v3"
log "github.com/sirupsen/logrus"
_ "go.ipao.vip/atom"
_ "go.ipao.vip/atom/contracts"
. "go.ipao.vip/atom/fen"
)
// Routes implements the HttpRoute contract and provides route registration
// for all controllers in the v1 module.
//
// @provider contracts.HttpRoute atom.GroupRoutes
type Routes struct {
log *log.Entry `inject:"false"`
middlewares *middlewares.Middlewares
// Controller instances
auth *auth
contents *contents
orders *orders
tenants *tenants
users *users
}
// Prepare initializes the routes provider with logging configuration.
func (r *Routes) Prepare() error {
r.log = log.WithField("module", "routes.v1")
r.log.Info("Initializing routes module")
return nil
}
// Name returns the unique identifier for this routes provider.
func (r *Routes) Name() string {
return "v1"
}
// Register registers all HTTP routes with the provided fiber router.
// Each route is registered with its corresponding controller action and parameter bindings.
func (r *Routes) Register(router fiber.Router) {
// Register routes for controller: auth
r.log.Debugf("Registering route: Get /super/v1/auth/token -> auth.CheckToken")
router.Get("/super/v1/auth/token"[len(r.Path()):], DataFunc0(
r.auth.CheckToken,
))
r.log.Debugf("Registering route: Post /super/v1/auth/login -> auth.Login")
router.Post("/super/v1/auth/login"[len(r.Path()):], DataFunc1(
r.auth.Login,
Body[dto.LoginForm]("form"),
))
// Register routes for controller: contents
r.log.Debugf("Registering route: Get /super/v1/contents -> contents.List")
router.Get("/super/v1/contents"[len(r.Path()):], DataFunc1(
r.contents.List,
Query[dto.SuperContentListFilter]("filter"),
))
r.log.Debugf("Registering route: Patch /super/v1/tenants/:tenantID/contents/:contentID/status -> contents.UpdateStatus")
router.Patch("/super/v1/tenants/:tenantID/contents/:contentID/status"[len(r.Path()):], Func3(
r.contents.UpdateStatus,
PathParam[int64]("tenantID"),
PathParam[int64]("contentID"),
Body[dto.SuperTenantContentStatusUpdateForm]("form"),
))
// Register routes for controller: orders
r.log.Debugf("Registering route: Get /super/v1/orders -> orders.List")
router.Get("/super/v1/orders"[len(r.Path()):], DataFunc1(
r.orders.List,
Query[dto.SuperOrderListFilter]("filter"),
))
r.log.Debugf("Registering route: Get /super/v1/orders/:id -> orders.Get")
router.Get("/super/v1/orders/:id"[len(r.Path()):], DataFunc1(
r.orders.Get,
PathParam[int64]("id"),
))
r.log.Debugf("Registering route: Get /super/v1/orders/statistics -> orders.Statistics")
router.Get("/super/v1/orders/statistics"[len(r.Path()):], DataFunc0(
r.orders.Statistics,
))
r.log.Debugf("Registering route: Post /super/v1/orders/:id/refund -> orders.Refund")
router.Post("/super/v1/orders/:id/refund"[len(r.Path()):], Func2(
r.orders.Refund,
PathParam[int64]("id"),
Body[dto.SuperOrderRefundForm]("form"),
))
// Register routes for controller: tenants
r.log.Debugf("Registering route: Get /super/v1/tenants -> tenants.List")
router.Get("/super/v1/tenants"[len(r.Path()):], DataFunc1(
r.tenants.List,
Query[dto.TenantListFilter]("filter"),
))
r.log.Debugf("Registering route: Get /super/v1/tenants/:id -> tenants.Get")
router.Get("/super/v1/tenants/:id"[len(r.Path()):], DataFunc1(
r.tenants.Get,
PathParam[int64]("id"),
))
r.log.Debugf("Registering route: Get /super/v1/tenants/statuses -> tenants.Statuses")
router.Get("/super/v1/tenants/statuses"[len(r.Path()):], DataFunc0(
r.tenants.Statuses,
))
r.log.Debugf("Registering route: Patch /super/v1/tenants/:id -> tenants.UpdateExpire")
router.Patch("/super/v1/tenants/:id"[len(r.Path()):], Func2(
r.tenants.UpdateExpire,
PathParam[int64]("id"),
Body[dto.TenantExpireUpdateForm]("form"),
))
r.log.Debugf("Registering route: Patch /super/v1/tenants/:id/status -> tenants.UpdateStatus")
router.Patch("/super/v1/tenants/:id/status"[len(r.Path()):], Func2(
r.tenants.UpdateStatus,
PathParam[int64]("id"),
Body[dto.TenantStatusUpdateForm]("form"),
))
r.log.Debugf("Registering route: Post /super/v1/tenants -> tenants.Create")
router.Post("/super/v1/tenants"[len(r.Path()):], Func1(
r.tenants.Create,
Body[dto.TenantCreateForm]("form"),
))
// Register routes for controller: users
r.log.Debugf("Registering route: Get /super/v1/users -> users.List")
router.Get("/super/v1/users"[len(r.Path()):], DataFunc1(
r.users.List,
Query[dto.UserListFilter]("filter"),
))
r.log.Debugf("Registering route: Get /super/v1/users/:id -> users.Get")
router.Get("/super/v1/users/:id"[len(r.Path()):], DataFunc1(
r.users.Get,
PathParam[int64]("id"),
))
r.log.Debugf("Registering route: Get /super/v1/users/statistics -> users.Statistics")
router.Get("/super/v1/users/statistics"[len(r.Path()):], DataFunc0(
r.users.Statistics,
))
r.log.Debugf("Registering route: Get /super/v1/users/statuses -> users.Statuses")
router.Get("/super/v1/users/statuses"[len(r.Path()):], DataFunc0(
r.users.Statuses,
))
r.log.Debugf("Registering route: Patch /super/v1/users/:id/roles -> users.UpdateRoles")
router.Patch("/super/v1/users/:id/roles"[len(r.Path()):], Func2(
r.users.UpdateRoles,
PathParam[int64]("id"),
Body[dto.UserRolesUpdateForm]("form"),
))
r.log.Debugf("Registering route: Patch /super/v1/users/:id/status -> users.UpdateStatus")
router.Patch("/super/v1/users/:id/status"[len(r.Path()):], Func2(
r.users.UpdateStatus,
PathParam[int64]("id"),
Body[dto.UserStatusUpdateForm]("form"),
))
r.log.Info("Successfully registered all routes")
}

View File

@@ -0,0 +1,9 @@
package v1
func (r *Routes) Path() string {
return "/super/v1"
}
func (r *Routes) Middlewares() []any {
return nil
}

View File

@@ -0,0 +1,106 @@
package v1
import (
dto "quyun/v2/app/http/super/v1/dto"
"quyun/v2/app/requests"
"quyun/v2/app/services"
"github.com/gofiber/fiber/v3"
)
// @provider
type tenants struct{}
// List tenants
//
// @Router /super/v1/tenants [get]
// @Summary List tenants
// @Description List tenants
// @Tags Tenant
// @Accept json
// @Produce json
// @Param page query int false "Page number"
// @Param limit query int false "Page size"
// @Param name query string false "Name"
// @Success 200 {object} requests.Pager{items=[]dto.TenantItem}
// @Bind filter query
func (c *tenants) List(ctx fiber.Ctx, filter *dto.TenantListFilter) (*requests.Pager, error) {
return services.Super.ListTenants(ctx.Context(), filter)
}
// Create tenant
//
// @Router /super/v1/tenants [post]
// @Summary Create tenant
// @Description Create tenant
// @Tags Tenant
// @Accept json
// @Produce json
// @Param form body dto.TenantCreateForm true "Create form"
// @Success 200 {string} string "Created"
// @Bind form body
func (c *tenants) Create(ctx fiber.Ctx, form *dto.TenantCreateForm) error {
return services.Super.CreateTenant(ctx.Context(), form)
}
// Get tenant
//
// @Router /super/v1/tenants/:id [get]
// @Summary Get tenant
// @Description Get tenant
// @Tags Tenant
// @Accept json
// @Produce json
// @Param id path int64 true "Tenant ID"
// @Success 200 {object} dto.TenantItem
// @Bind id path
func (c *tenants) Get(ctx fiber.Ctx, id int64) (*dto.TenantItem, error) {
return services.Super.GetTenant(ctx.Context(), id)
}
// Update tenant status
//
// @Router /super/v1/tenants/:id/status [patch]
// @Summary Update tenant status
// @Description Update tenant status
// @Tags Tenant
// @Accept json
// @Produce json
// @Param id path int64 true "Tenant ID"
// @Param form body dto.TenantStatusUpdateForm true "Update form"
// @Success 200 {string} string "Updated"
// @Bind id path
// @Bind form body
func (c *tenants) UpdateStatus(ctx fiber.Ctx, id int64, form *dto.TenantStatusUpdateForm) error {
return services.Super.UpdateTenantStatus(ctx.Context(), id, form)
}
// Update tenant expire
//
// @Router /super/v1/tenants/:id [patch]
// @Summary Update tenant expire
// @Description Update tenant expire
// @Tags Tenant
// @Accept json
// @Produce json
// @Param id path int64 true "Tenant ID"
// @Param form body dto.TenantExpireUpdateForm true "Update form"
// @Success 200 {string} string "Updated"
// @Bind id path
// @Bind form body
func (c *tenants) UpdateExpire(ctx fiber.Ctx, id int64, form *dto.TenantExpireUpdateForm) error {
return services.Super.UpdateTenantExpire(ctx.Context(), id, form)
}
// Tenant statuses
//
// @Router /super/v1/tenants/statuses [get]
// @Summary Tenant statuses
// @Description Tenant statuses
// @Tags Tenant
// @Accept json
// @Produce json
// @Success 200 {array} requests.KV
func (c *tenants) Statuses(ctx fiber.Ctx) ([]requests.KV, error) {
return services.Super.TenantStatuses(ctx.Context())
}

View File

@@ -0,0 +1,104 @@
package v1
import (
dto "quyun/v2/app/http/super/v1/dto"
"quyun/v2/app/requests"
"quyun/v2/app/services"
"github.com/gofiber/fiber/v3"
)
// @provider
type users struct{}
// List users
//
// @Router /super/v1/users [get]
// @Summary List users
// @Description List users
// @Tags User
// @Accept json
// @Produce json
// @Param page query int false "Page number"
// @Param limit query int false "Page size"
// @Param username query string false "Username"
// @Success 200 {object} requests.Pager{items=[]dto.UserItem}
// @Bind filter query
func (c *users) List(ctx fiber.Ctx, filter *dto.UserListFilter) (*requests.Pager, error) {
return services.Super.ListUsers(ctx.Context(), filter)
}
// Get user
//
// @Router /super/v1/users/:id [get]
// @Summary Get user
// @Description Get user
// @Tags User
// @Accept json
// @Produce json
// @Param id path int64 true "User ID"
// @Success 200 {object} dto.UserItem
// @Bind id path
func (c *users) Get(ctx fiber.Ctx, id int64) (*dto.UserItem, error) {
return services.Super.GetUser(ctx.Context(), id)
}
// Update user status
//
// @Router /super/v1/users/:id/status [patch]
// @Summary Update user status
// @Description Update user status
// @Tags User
// @Accept json
// @Produce json
// @Param id path int64 true "User ID"
// @Param form body dto.UserStatusUpdateForm true "Update form"
// @Success 200 {string} string "Updated"
// @Bind id path
// @Bind form body
func (c *users) UpdateStatus(ctx fiber.Ctx, id int64, form *dto.UserStatusUpdateForm) error {
return services.Super.UpdateUserStatus(ctx.Context(), id, form)
}
// Update user roles
//
// @Router /super/v1/users/:id/roles [patch]
// @Summary Update user roles
// @Description Update user roles
// @Tags User
// @Accept json
// @Produce json
// @Param id path int64 true "User ID"
// @Param form body dto.UserRolesUpdateForm true "Update form"
// @Success 200 {string} string "Updated"
// @Bind id path
// @Bind form body
func (c *users) UpdateRoles(ctx fiber.Ctx, id int64, form *dto.UserRolesUpdateForm) error {
return services.Super.UpdateUserRoles(ctx.Context(), id, form)
}
// User statistics
//
// @Router /super/v1/users/statistics [get]
// @Summary User statistics
// @Description User statistics
// @Tags User
// @Accept json
// @Produce json
// @Success 200 {array} dto.UserStatistics
func (c *users) Statistics(ctx fiber.Ctx) ([]dto.UserStatistics, error) {
return services.Super.UserStatistics(ctx.Context())
}
// User statuses
//
// @Router /super/v1/users/statuses [get]
// @Summary User statuses
// @Description User statuses
// @Tags User
// @Accept json
// @Produce json
// @Success 200 {array} requests.KV
func (c *users) Statuses(ctx fiber.Ctx) ([]requests.KV, error) {
return services.Super.UserStatuses(ctx.Context())
}