Files
quyun/backend_v1/app/http/admin/medias.go
Rogee 7b18a6a0e6
Some checks failed
build quyun / Build (push) Failing after 2m1s
feat: Enhance Swagger documentation with new admin and user endpoints
- 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.
2025-12-19 23:43:46 +08:00

79 lines
1.9 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package admin
import (
"quyun/v2/app/requests"
"quyun/v2/app/services"
"quyun/v2/database"
"quyun/v2/database/models"
"quyun/v2/providers/ali"
"github.com/gofiber/fiber/v3"
)
// @provider
type medias struct {
oss *ali.OSSClient
}
// 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
func (ctl *medias) List(ctx fiber.Ctx, pagination *requests.Pagination, query *ListQuery) (*requests.Pager, error) {
return services.Medias.List(ctx, pagination, models.MediaQuery.Name.Like(database.WrapLike(*query.Keyword)))
}
// 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 {
media, err := services.Medias.FindByID(ctx, id)
if err != nil {
return ctx.SendString("Media not found")
}
url, err := ctl.oss.GetSignedUrl(ctx, media.Path)
if err != nil {
return err
}
return ctx.Redirect().To(url)
}
// 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 {
media, err := services.Medias.FindByID(ctx, id)
if err != nil {
return ctx.SendString("Media not found")
}
if err := ctl.oss.Delete(ctx, media.Path); err != nil {
return err
}
if _, err := media.Delete(ctx); err != nil {
return err
}
return ctx.SendStatus(fiber.StatusNoContent)
}