feat: Enhance Swagger documentation with new admin and user endpoints
Some checks failed
build quyun / Build (push) Failing after 2m1s

- Added definitions for admin authentication, media, posts, orders, and user management.
- Implemented new API paths for admin functionalities including authentication, media management, order processing, and user statistics.
- Updated existing endpoints to improve clarity and structure in the Swagger documentation.
- Introduced new response schemas for various operations to standardize API responses.
This commit is contained in:
2025-12-19 23:43:46 +08:00
parent 49072ddd79
commit 7b18a6a0e6
14 changed files with 4180 additions and 120 deletions

View File

@@ -22,6 +22,12 @@ type TokenResponse struct {
// Login
//
// @Summary 管理员登录
// @Tags Admin Auth
// @Accept json
// @Produce json
// @Param body body AuthBody true "请求体"
// @Success 200 {object} TokenResponse "成功"
// @Router /admin/auth [post]
// @Bind body body
func (ctl *auth) Login(ctx fiber.Ctx, body *AuthBody) (*TokenResponse, error) {

View File

@@ -17,6 +17,12 @@ type medias struct {
// List medias
//
// @Summary 媒体列表
// @Tags Admin Medias
// @Produce json
// @Param pagination query requests.Pagination false "分页参数"
// @Param query query ListQuery false "筛选条件"
// @Success 200 {object} requests.Pager{items=models.Media} "成功"
// @Router /admin/medias [get]
// @Bind pagination query
// @Bind query query
@@ -26,6 +32,10 @@ func (ctl *medias) List(ctx fiber.Ctx, pagination *requests.Pagination, query *L
// Show media
//
// @Summary 媒体预览(跳转到签名 URL
// @Tags Admin Medias
// @Param id path int64 true "媒体 ID"
// @Success 302 {string} string "跳转"
// @Router /admin/medias/:id [get]
// @Bind id path
func (ctl *medias) Show(ctx fiber.Ctx, id int64) error {
@@ -44,6 +54,11 @@ func (ctl *medias) Show(ctx fiber.Ctx, id int64) error {
// Delete
//
// @Summary 删除媒体
// @Tags Admin Medias
// @Produce json
// @Param id path int64 true "媒体 ID"
// @Success 204 {object} any "成功"
// @Router /admin/medias/:id [delete]
// @Bind id path
func (ctl *medias) Delete(ctx fiber.Ctx, id int64) error {

View File

@@ -26,6 +26,12 @@ type orders struct {
// List users
//
// @Summary 订单列表
// @Tags Admin Orders
// @Produce json
// @Param pagination query requests.Pagination false "分页参数"
// @Param query query OrderListQuery false "筛选条件"
// @Success 200 {object} requests.Pager{items=services.OrderListItem} "成功"
// @Router /admin/orders [get]
// @Bind pagination query
// @Bind query query
@@ -47,6 +53,12 @@ func (ctl *orders) List(
}
// Refund
//
// @Summary 订单退款
// @Tags Admin Orders
// @Produce json
// @Param id path int64 true "订单 ID"
// @Success 200 {object} any "成功"
// @Router /admin/orders/:id/refund [post]
// @Bind id path
func (ctl *orders) Refund(ctx fiber.Ctx, id int64) error {

View File

@@ -21,6 +21,12 @@ type posts struct{}
// List posts
//
// @Summary 作品列表
// @Tags Admin Posts
// @Produce json
// @Param pagination query requests.Pagination false "分页参数"
// @Param query query ListQuery false "筛选条件"
// @Success 200 {object} requests.Pager{items=PostItem} "成功"
// @Router /admin/posts [get]
// @Bind pagination query
// @Bind query query
@@ -69,6 +75,12 @@ type PostForm struct {
// Create
//
// @Summary 创建作品
// @Tags Admin Posts
// @Accept json
// @Produce json
// @Param form body PostForm true "请求体"
// @Success 200 {object} any "成功"
// @Router /admin/posts [post]
// @Bind form body
func (ctl *posts) Create(ctx fiber.Ctx, form *PostForm) error {
@@ -107,6 +119,13 @@ func (ctl *posts) Create(ctx fiber.Ctx, form *PostForm) error {
// Update posts
//
// @Summary 更新作品
// @Tags Admin Posts
// @Accept json
// @Produce json
// @Param id path int64 true "作品 ID"
// @Param form body PostForm true "请求体"
// @Success 200 {object} any "成功"
// @Router /admin/posts/:id [put]
// @Bind id path
// @Bind form body
@@ -147,6 +166,11 @@ func (ctl *posts) Update(ctx fiber.Ctx, id int64, form *PostForm) error {
// Delete posts
//
// @Summary 删除作品
// @Tags Admin Posts
// @Produce json
// @Param id path int64 true "作品 ID"
// @Success 204 {object} any "成功"
// @Router /admin/posts/:id [delete]
// @Bind id path
func (ctl *posts) Delete(ctx fiber.Ctx, id int64) error {
@@ -172,6 +196,11 @@ type PostItem struct {
// Show posts by id
//
// @Summary 作品详情
// @Tags Admin Posts
// @Produce json
// @Param id path int64 true "作品 ID"
// @Success 200 {object} PostItem "成功"
// @Router /admin/posts/:id [get]
// @Bind id path
func (ctl *posts) Show(ctx fiber.Ctx, id int64) (*PostItem, error) {
@@ -194,6 +223,12 @@ func (ctl *posts) Show(ctx fiber.Ctx, id int64) (*PostItem, error) {
// SendTo
//
// @Summary 赠送作品给用户
// @Tags Admin Posts
// @Produce json
// @Param id path int64 true "作品 ID"
// @Param userId path int64 true "用户 ID"
// @Success 200 {object} any "成功"
// @Router /admin/posts/:id/send-to/:userId [post]
// @Bind id path
// @Bind userId path

View File

@@ -22,6 +22,10 @@ type StatisticsResponse struct {
// dashboard statistics
//
// @Summary 仪表盘统计
// @Tags Admin Statistics
// @Produce json
// @Success 200 {object} StatisticsResponse "成功"
// @Router /admin/statistics [get]
func (s *statistics) statistics(ctx fiber.Ctx) (*StatisticsResponse, error) {
statistics := &StatisticsResponse{}

View File

@@ -34,6 +34,13 @@ type PreCheckResp struct {
// PreUploadCheck
//
// @Summary 预上传检查
// @Tags Admin Uploads
// @Produce json
// @Param md5 path string true "文件 MD5"
// @Param ext path string true "文件扩展名(不含点)"
// @Param mime query string true "文件 MIME 类型"
// @Success 200 {object} PreCheckResp "成功"
// @Router /admin/uploads/pre-uploaded-check/:md5.:ext [get]
// @Bind md5 path
// @Bind ext path
@@ -61,6 +68,12 @@ type PostUploadedForm struct {
// PostUploadedAction
//
// @Summary 上传完成回调处理
// @Tags Admin Uploads
// @Accept json
// @Produce json
// @Param body body PostUploadedForm true "请求体"
// @Success 200 {object} any "成功"
// @Router /admin/uploads/post-uploaded-action [post]
// @Bind body body
func (up *uploads) PostUploadedAction(ctx fiber.Ctx, body *PostUploadedForm) error {

View File

@@ -19,6 +19,12 @@ type users struct{}
// List users
//
// @Summary 用户列表
// @Tags Admin Users
// @Produce json
// @Param pagination query requests.Pagination false "分页参数"
// @Param query query UserListQuery false "筛选条件"
// @Success 200 {object} requests.Pager{items=models.User} "成功"
// @Router /admin/users [get]
// @Bind pagination query
// @Bind query query
@@ -31,6 +37,11 @@ func (ctl *users) List(ctx fiber.Ctx, pagination *requests.Pagination, query *Us
// Show user
//
// @Summary 用户详情
// @Tags Admin Users
// @Produce json
// @Param id path int64 true "用户 ID"
// @Success 200 {object} models.User "成功"
// @Router /admin/users/:id [get]
// @Bind id path
func (ctl *users) Show(ctx fiber.Ctx, id int64) (*models.User, error) {
@@ -39,6 +50,12 @@ func (ctl *users) Show(ctx fiber.Ctx, id int64) (*models.User, error) {
// Articles show user bought articles
//
// @Summary 用户已购作品
// @Tags Admin Users
// @Produce json
// @Param id path int64 true "用户 ID"
// @Param pagination query requests.Pagination false "分页参数"
// @Success 200 {object} requests.Pager{items=models.Post} "成功"
// @Router /admin/users/:id/articles [get]
// @Bind id path
// @Bind pagination query
@@ -52,6 +69,13 @@ type UserBalance struct {
// Balance
//
// @Summary 调整用户余额
// @Tags Admin Users
// @Accept json
// @Produce json
// @Param id path int64 true "用户 ID"
// @Param balance body UserBalance true "请求体"
// @Success 200 {object} any "成功"
// @Router /admin/users/:id/balance [post]
// @Bind id path
// @Bind balance body

View File

@@ -38,6 +38,12 @@ type posts struct {
// List posts
//
// @Summary 作品列表
// @Tags Posts
// @Produce json
// @Param pagination query requests.Pagination false "分页参数"
// @Param query query ListQuery false "筛选条件"
// @Success 200 {object} requests.Pager{items=PostItem} "成功"
// @Router /posts [get]
// @Bind pagination query
// @Bind query query
@@ -123,6 +129,11 @@ type PostItem struct {
// Show
//
// @Summary 作品详情
// @Tags Posts
// @Produce json
// @Param id path int64 true "作品 ID"
// @Success 200 {object} PostItem "成功"
// @Router /posts/:id/show [get]
// @Bind id path
// @Bind user local
@@ -179,6 +190,11 @@ type PlayUrl struct {
// Play
//
// @Summary 获取播放地址
// @Tags Posts
// @Produce json
// @Param id path int64 true "作品 ID"
// @Success 200 {object} PlayUrl "成功"
// @Router /posts/:id/play [get]
// @Bind id path
// @Bind user local
@@ -230,6 +246,12 @@ func (ctl *posts) Play(ctx fiber.Ctx, id int64, user *models.User) (*PlayUrl, er
// Mine posts
//
// @Summary 我的已购作品
// @Tags Posts
// @Produce json
// @Param pagination query requests.Pagination false "分页参数"
// @Param query query ListQuery false "筛选条件"
// @Success 200 {object} requests.Pager{items=PostItem} "成功"
// @Router /posts/mine [get]
// @Bind pagination query
// @Bind query query
@@ -292,6 +314,11 @@ func (ctl *posts) Mine(
// Buy
//
// @Summary 购买作品
// @Tags Posts
// @Produce json
// @Param id path int64 true "作品 ID"
// @Success 200 {object} wechat.JSAPIPayParams "成功(余额支付返回 AppId=balance"
// @Router /posts/:id/buy [post]
// @Bind id path
// @Bind user local

View File

@@ -21,6 +21,12 @@ type UserInfo struct {
Balance int64 `json:"balance"`
}
// Profile 获取当前登录用户的基础信息。
//
// @Summary 获取个人信息
// @Tags Users
// @Produce json
// @Success 200 {object} UserInfo "成功"
// @Router /users/profile [get]
// @Bind user local
func (ctl *users) Profile(ctx fiber.Ctx, user *models.User) (*UserInfo, error) {
@@ -37,8 +43,14 @@ type ProfileForm struct {
Username string `json:"username" validate:"required"`
}
// Update
// Update 修改当前登录用户的用户名。
//
// @Summary 修改用户名
// @Tags Users
// @Accept json
// @Produce json
// @Param form body ProfileForm true "请求体"
// @Success 200 {object} any "成功"
// @Router /users/username [put]
// @Bind user local
// @Bind form body

View File

@@ -30,18 +30,20 @@ type Filter struct {
type ResponseItem struct{}
// Foo
// Foo 演示端点:展示 Fiber 参数绑定与 Swagger 注释写法。
//
// @Summary Test
// @Description Test
// @Tags Test
// @Accept json
// @Summary 演示接口
// @Tags Demo
// @Accept multipart/form-data
// @Produce json
//
// @Param id path int true "ID"
// @Param query query Filter true "Filter"
// @Param pager query requests.Pagination true "Pager"
// @Success 200 {object} requests.Pager{list=ResponseItem} "成功"
// @Param pager query requests.Pagination false "分页参数"
// @Param query query FooQuery false "查询参数"
// @Param Content-Type header string false "内容类型"
// @Param folder formData string false "上传到指定文件夹"
// @Param file formData file true "上传文件"
// @Success 200 {object} requests.Pager{items=ResponseItem} "成功"
//
// @Router /v1/medias/:id [post]
// @Bind query query

View File

@@ -14,6 +14,13 @@ import (
"go.ipao.vip/gen/types"
)
// OrderListItem 用于订单列表展示,补充作品标题与用户名等冗余信息,避免前端二次查询。
type OrderListItem struct {
*models.Order
PostTitle string `json:"post_title"`
Username string `json:"username"`
}
// @provider
type orders struct{}
@@ -51,15 +58,8 @@ func (m *orders) List(
postMap := lo.SliceToMap(posts, func(p *models.Post) (int64, *models.Post) { return p.ID, p })
userMap := lo.SliceToMap(users, func(u *models.User) (int64, *models.User) { return u.ID, u })
// OrderListItem 用于订单列表展示,补充作品标题与用户名等冗余信息,避免前端二次查询。
type orderListItem struct {
*models.Order
PostTitle string `json:"post_title"`
Username string `json:"username"`
}
items := lo.Map(orders, func(o *models.Order, _ int) *orderListItem {
item := &orderListItem{Order: o}
items := lo.Map(orders, func(o *models.Order, _ int) *OrderListItem {
item := &OrderListItem{Order: o}
if post, ok := postMap[o.PostID]; ok {
item.PostTitle = post.Title
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff