feat: follow llm.txt

This commit is contained in:
2025-12-18 10:27:40 +08:00
parent 819fa7f218
commit 674c562831
25 changed files with 2775 additions and 106 deletions

View File

@@ -56,7 +56,7 @@ func (ctl *auth) login(ctx fiber.Ctx, form *dto.LoginForm) (*dto.LoginResponse,
// @Tags Super
// @Accept json
// @Produce json
// @Success 200 {object} dto.LoginResponse "成功"
// @Success 200 {object} dto.LoginResponse "成功"
//
// @Router /super/v1/auth/token [get]
func (ctl *auth) token(ctx fiber.Ctx) (*dto.LoginResponse, error) {

View File

@@ -18,7 +18,7 @@ import (
// Routes implements the HttpRoute contract and provides route registration
// for all controllers in the super module.
//
// @provider contracts.HttpRoute atom.GroupRoutes
// @provider contracts.HttpRoute atom.GroupRoutes
type Routes struct {
log *log.Entry `inject:"false"`
middlewares *middlewares.Middlewares

View File

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

View File

@@ -20,7 +20,7 @@ type tenant struct{}
// @Tags Super
// @Accept json
// @Produce json
// @Param filter query dto.TenantFilter true "Filter"
// @Param filter query dto.TenantFilter true "Filter"
// @Success 200 {object} requests.Pager{items=dto.TenantItem}
//
// @Router /super/v1/tenants [get]
@@ -72,7 +72,7 @@ func (*tenant) updateStatus(ctx fiber.Ctx, tenantID int64, form *dto.TenantStatu
// @Tags Super
// @Accept json
// @Produce json
// @Success 200 {array} requests.KV
// @Success 200 {array} requests.KV
//
// @Router /super/v1/tenants/statuses [get]
// @Bind userID path

View File

@@ -20,7 +20,7 @@ type user struct{}
// @Tags Super
// @Accept json
// @Produce json
// @Param filter query dto.UserPageFilter true "Filter"
// @Param filter query dto.UserPageFilter true "Filter"
// @Success 200 {object} requests.Pager{items=dto.UserItem}
//
// @Router /super/v1/users [get]
@@ -36,7 +36,7 @@ func (*user) list(ctx fiber.Ctx, filter *dto.UserPageFilter) (*requests.Pager, e
// @Accept json
// @Produce json
// @Param userID path int64 true "UserID"
// @Param form body dto.UserStatusUpdateForm true "Form"
// @Param form body dto.UserStatusUpdateForm true "Form"
//
// @Router /super/v1/users/:userID/status [patch]
// @Bind userID path
@@ -51,7 +51,7 @@ func (*user) updateStatus(ctx fiber.Ctx, userID int64, form *dto.UserStatusUpdat
// @Tags Super
// @Accept json
// @Produce json
// @Success 200 {array} requests.KV
// @Success 200 {array} requests.KV
//
// @Router /super/v1/users/statuses [get]
// @Bind userID path
@@ -68,7 +68,7 @@ func (*user) statusList(ctx fiber.Ctx) ([]requests.KV, error) {
// @Tags Super
// @Accept json
// @Produce json
// @Success 200 {array} dto.UserStatistics
// @Success 200 {array} dto.UserStatistics
//
// @Router /super/v1/users/statistics [get]
// @Bind userID path

View File

@@ -14,7 +14,7 @@ import (
// content provides tenant-side read-only content endpoints.
//
// @provider
// @provider
type content struct{}
// list
@@ -23,11 +23,11 @@ type content struct{}
// @Tags Tenant
// @Accept json
// @Produce json
// @Param tenant_code path string true "Tenant Code"
// @Param tenantCode path string true "Tenant Code"
// @Param filter query dto.ContentListFilter true "Filter"
// @Success 200 {object} requests.Pager{items=dto.ContentItem}
//
// @Router /t/:tenant_code/v1/contents [get]
// @Router /t/:tenantCode/v1/contents [get]
// @Bind tenant local key(tenant)
// @Bind user local key(user)
// @Bind filter query
@@ -47,11 +47,11 @@ func (*content) list(ctx fiber.Ctx, tenant *models.Tenant, user *models.User, fi
// @Tags Tenant
// @Accept json
// @Produce json
// @Param tenant_code path string true "Tenant Code"
// @Param tenantCode path string true "Tenant Code"
// @Param contentID path int64 true "ContentID"
// @Success 200 {object} dto.ContentDetail
//
// @Router /t/:tenant_code/v1/contents/:contentID [get]
// @Router /t/:tenantCode/v1/contents/:contentID [get]
// @Bind tenant local key(tenant)
// @Bind user local key(user)
// @Bind contentID path
@@ -79,11 +79,11 @@ func (*content) show(ctx fiber.Ctx, tenant *models.Tenant, user *models.User, co
// @Tags Tenant
// @Accept json
// @Produce json
// @Param tenant_code path string true "Tenant Code"
// @Param tenantCode path string true "Tenant Code"
// @Param contentID path int64 true "ContentID"
// @Success 200 {object} dto.ContentAssetsResponse
//
// @Router /t/:tenant_code/v1/contents/:contentID/preview [get]
// @Router /t/:tenantCode/v1/contents/:contentID/preview [get]
// @Bind tenant local key(tenant)
// @Bind user local key(user)
// @Bind contentID path
@@ -106,7 +106,7 @@ func (*content) previewAssets(ctx fiber.Ctx, tenant *models.Tenant, user *models
previewSeconds := int32(detail.Content.PreviewSeconds)
if previewSeconds <= 0 {
previewSeconds = 60
previewSeconds = consts.DefaultContentPreviewSeconds
}
return &dto.ContentAssetsResponse{
Content: detail.Content,
@@ -121,11 +121,11 @@ func (*content) previewAssets(ctx fiber.Ctx, tenant *models.Tenant, user *models
// @Tags Tenant
// @Accept json
// @Produce json
// @Param tenant_code path string true "Tenant Code"
// @Param tenantCode path string true "Tenant Code"
// @Param contentID path int64 true "ContentID"
// @Success 200 {object} dto.ContentAssetsResponse
//
// @Router /t/:tenant_code/v1/contents/:contentID/assets [get]
// @Router /t/:tenantCode/v1/contents/:contentID/assets [get]
// @Bind tenant local key(tenant)
// @Bind user local key(user)
// @Bind contentID path

View File

@@ -15,7 +15,7 @@ import (
// contentAdmin provides tenant-admin content management endpoints.
//
// @provider
// @provider
type contentAdmin struct{}
func requireTenantAdmin(tenantUser *models.TenantUser) error {
@@ -34,11 +34,11 @@ func requireTenantAdmin(tenantUser *models.TenantUser) error {
// @Tags Tenant
// @Accept json
// @Produce json
// @Param tenant_code path string true "Tenant Code"
// @Param tenantCode path string true "Tenant Code"
// @Param form body dto.ContentCreateForm true "Form"
// @Success 200 {object} models.Content
//
// @Router /t/:tenant_code/v1/admin/contents [post]
// @Router /t/:tenantCode/v1/admin/contents [post]
// @Bind tenant local key(tenant)
// @Bind tenantUser local key(tenant_user)
// @Bind form body
@@ -61,12 +61,12 @@ func (*contentAdmin) create(ctx fiber.Ctx, tenant *models.Tenant, tenantUser *mo
// @Tags Tenant
// @Accept json
// @Produce json
// @Param tenant_code path string true "Tenant Code"
// @Param contentID path int64 true "ContentID"
// @Param tenantCode path string true "Tenant Code"
// @Param contentID path int64 true "ContentID"
// @Param form body dto.ContentUpdateForm true "Form"
// @Success 200 {object} models.Content
//
// @Router /t/:tenant_code/v1/admin/contents/:contentID [patch]
// @Router /t/:tenantCode/v1/admin/contents/:contentID [patch]
// @Bind tenant local key(tenant)
// @Bind tenantUser local key(tenant_user)
// @Bind contentID path
@@ -91,12 +91,12 @@ func (*contentAdmin) update(ctx fiber.Ctx, tenant *models.Tenant, tenantUser *mo
// @Tags Tenant
// @Accept json
// @Produce json
// @Param tenant_code path string true "Tenant Code"
// @Param contentID path int64 true "ContentID"
// @Param tenantCode path string true "Tenant Code"
// @Param contentID path int64 true "ContentID"
// @Param form body dto.ContentPriceUpsertForm true "Form"
// @Success 200 {object} models.ContentPrice
//
// @Router /t/:tenant_code/v1/admin/contents/:contentID/price [put]
// @Router /t/:tenantCode/v1/admin/contents/:contentID/price [put]
// @Bind tenant local key(tenant)
// @Bind tenantUser local key(tenant_user)
// @Bind contentID path
@@ -121,12 +121,12 @@ func (*contentAdmin) upsertPrice(ctx fiber.Ctx, tenant *models.Tenant, tenantUse
// @Tags Tenant
// @Accept json
// @Produce json
// @Param tenant_code path string true "Tenant Code"
// @Param contentID path int64 true "ContentID"
// @Param tenantCode path string true "Tenant Code"
// @Param contentID path int64 true "ContentID"
// @Param form body dto.ContentAssetAttachForm true "Form"
// @Success 200 {object} models.ContentAsset
//
// @Router /t/:tenant_code/v1/admin/contents/:contentID/assets [post]
// @Router /t/:tenantCode/v1/admin/contents/:contentID/assets [post]
// @Bind tenant local key(tenant)
// @Bind tenantUser local key(tenant_user)
// @Bind contentID path

View File

@@ -5,6 +5,7 @@ import (
"quyun/v2/database/models"
)
// ContentListFilter defines list query filters for published contents within a tenant.
type ContentListFilter struct {
// Pagination controls paging parameters (page/limit).
requests.Pagination `json:",inline" query:",inline"`

View File

@@ -6,6 +6,7 @@ import (
"quyun/v2/pkg/consts"
)
// ContentCreateForm defines payload for tenant-admin to create a new content draft.
type ContentCreateForm struct {
// Title is the content title.
Title string `json:"title,omitempty"`

View File

@@ -4,7 +4,7 @@ import "quyun/v2/database/models"
// MeResponse returns the resolved tenant context for the current request.
type MeResponse struct {
// Tenant is the resolved tenant by `tenant_code`.
// Tenant is the resolved tenant by `tenantCode`.
Tenant *models.Tenant `json:"tenant,omitempty"`
// User is the authenticated user derived from JWT `user_id`.
User *models.User `json:"user,omitempty"`

View File

@@ -9,7 +9,7 @@ import (
// me provides tenant context introspection endpoints (current tenant/user/tenant_user).
//
// @provider
// @provider
type me struct{}
// get
@@ -18,10 +18,10 @@ type me struct{}
// @Tags Tenant
// @Accept json
// @Produce json
// @Param tenant_code path string true "Tenant Code"
// @Param tenantCode path string true "Tenant Code"
// @Success 200 {object} dto.MeResponse
//
// @Router /t/:tenant_code/v1/me [get]
// @Router /t/:tenantCode/v1/me [get]
// @Bind tenant local key(tenant)
// @Bind user local key(user)
// @Bind tenantUser local key(tenant_user)

View File

@@ -19,7 +19,7 @@ import (
// Routes implements the HttpRoute contract and provides route registration
// for all controllers in the tenant module.
//
// @provider contracts.HttpRoute atom.GroupRoutes
// @provider contracts.HttpRoute atom.GroupRoutes
type Routes struct {
log *log.Entry `inject:"false"`
middlewares *middlewares.Middlewares
@@ -45,60 +45,60 @@ func (r *Routes) Name() string {
// Each route is registered with its corresponding controller action and parameter bindings.
func (r *Routes) Register(router fiber.Router) {
// Register routes for controller: content
r.log.Debugf("Registering route: Get /t/:tenant_code/v1/contents -> content.list")
router.Get("/t/:tenant_code/v1/contents"[len(r.Path()):], DataFunc3(
r.log.Debugf("Registering route: Get /t/:tenantCode/v1/contents -> content.list")
router.Get("/t/:tenantCode/v1/contents"[len(r.Path()):], DataFunc3(
r.content.list,
Local[*models.Tenant]("tenant"),
Local[*models.User]("user"),
Query[dto.ContentListFilter]("filter"),
))
r.log.Debugf("Registering route: Get /t/:tenant_code/v1/contents/:contentID -> content.show")
router.Get("/t/:tenant_code/v1/contents/:contentID"[len(r.Path()):], DataFunc3(
r.log.Debugf("Registering route: Get /t/:tenantCode/v1/contents/:contentID -> content.show")
router.Get("/t/:tenantCode/v1/contents/:contentID"[len(r.Path()):], DataFunc3(
r.content.show,
Local[*models.Tenant]("tenant"),
Local[*models.User]("user"),
PathParam[int64]("contentID"),
))
r.log.Debugf("Registering route: Get /t/:tenant_code/v1/contents/:contentID/assets -> content.mainAssets")
router.Get("/t/:tenant_code/v1/contents/:contentID/assets"[len(r.Path()):], DataFunc3(
r.log.Debugf("Registering route: Get /t/:tenantCode/v1/contents/:contentID/assets -> content.mainAssets")
router.Get("/t/:tenantCode/v1/contents/:contentID/assets"[len(r.Path()):], DataFunc3(
r.content.mainAssets,
Local[*models.Tenant]("tenant"),
Local[*models.User]("user"),
PathParam[int64]("contentID"),
))
r.log.Debugf("Registering route: Get /t/:tenant_code/v1/contents/:contentID/preview -> content.previewAssets")
router.Get("/t/:tenant_code/v1/contents/:contentID/preview"[len(r.Path()):], DataFunc3(
r.log.Debugf("Registering route: Get /t/:tenantCode/v1/contents/:contentID/preview -> content.previewAssets")
router.Get("/t/:tenantCode/v1/contents/:contentID/preview"[len(r.Path()):], DataFunc3(
r.content.previewAssets,
Local[*models.Tenant]("tenant"),
Local[*models.User]("user"),
PathParam[int64]("contentID"),
))
// Register routes for controller: contentAdmin
r.log.Debugf("Registering route: Patch /t/:tenant_code/v1/admin/contents/:contentID -> contentAdmin.update")
router.Patch("/t/:tenant_code/v1/admin/contents/:contentID"[len(r.Path()):], DataFunc4(
r.log.Debugf("Registering route: Patch /t/:tenantCode/v1/admin/contents/:contentID -> contentAdmin.update")
router.Patch("/t/:tenantCode/v1/admin/contents/:contentID"[len(r.Path()):], DataFunc4(
r.contentAdmin.update,
Local[*models.Tenant]("tenant"),
Local[*models.TenantUser]("tenant_user"),
PathParam[int64]("contentID"),
Body[dto.ContentUpdateForm]("form"),
))
r.log.Debugf("Registering route: Post /t/:tenant_code/v1/admin/contents -> contentAdmin.create")
router.Post("/t/:tenant_code/v1/admin/contents"[len(r.Path()):], DataFunc3(
r.log.Debugf("Registering route: Post /t/:tenantCode/v1/admin/contents -> contentAdmin.create")
router.Post("/t/:tenantCode/v1/admin/contents"[len(r.Path()):], DataFunc3(
r.contentAdmin.create,
Local[*models.Tenant]("tenant"),
Local[*models.TenantUser]("tenant_user"),
Body[dto.ContentCreateForm]("form"),
))
r.log.Debugf("Registering route: Post /t/:tenant_code/v1/admin/contents/:contentID/assets -> contentAdmin.attachAsset")
router.Post("/t/:tenant_code/v1/admin/contents/:contentID/assets"[len(r.Path()):], DataFunc4(
r.log.Debugf("Registering route: Post /t/:tenantCode/v1/admin/contents/:contentID/assets -> contentAdmin.attachAsset")
router.Post("/t/:tenantCode/v1/admin/contents/:contentID/assets"[len(r.Path()):], DataFunc4(
r.contentAdmin.attachAsset,
Local[*models.Tenant]("tenant"),
Local[*models.TenantUser]("tenant_user"),
PathParam[int64]("contentID"),
Body[dto.ContentAssetAttachForm]("form"),
))
r.log.Debugf("Registering route: Put /t/:tenant_code/v1/admin/contents/:contentID/price -> contentAdmin.upsertPrice")
router.Put("/t/:tenant_code/v1/admin/contents/:contentID/price"[len(r.Path()):], DataFunc4(
r.log.Debugf("Registering route: Put /t/:tenantCode/v1/admin/contents/:contentID/price -> contentAdmin.upsertPrice")
router.Put("/t/:tenantCode/v1/admin/contents/:contentID/price"[len(r.Path()):], DataFunc4(
r.contentAdmin.upsertPrice,
Local[*models.Tenant]("tenant"),
Local[*models.TenantUser]("tenant_user"),
@@ -106,8 +106,8 @@ func (r *Routes) Register(router fiber.Router) {
Body[dto.ContentPriceUpsertForm]("form"),
))
// Register routes for controller: me
r.log.Debugf("Registering route: Get /t/:tenant_code/v1/me -> me.get")
router.Get("/t/:tenant_code/v1/me"[len(r.Path()):], DataFunc3(
r.log.Debugf("Registering route: Get /t/:tenantCode/v1/me -> me.get")
router.Get("/t/:tenantCode/v1/me"[len(r.Path()):], DataFunc3(
r.me.get,
Local[*models.Tenant]("tenant"),
Local[*models.User]("user"),

View File

@@ -1,12 +1,11 @@
package tenant
func (r *Routes) Path() string {
return "/t/:tenant_code/v1"
return "/t/:tenantCode/v1"
}
func (r *Routes) Middlewares() []any {
return []any{
r.middlewares.DebugMode,
r.middlewares.TenantResolve,
r.middlewares.TenantAuth,
r.middlewares.TenantRequireMember,

View File

@@ -1,7 +1,6 @@
package middlewares
import (
"go.ipao.vip/atom/container"
"quyun/v2/app/errorx"
"quyun/v2/app/services"
"quyun/v2/database/models"
@@ -12,9 +11,9 @@ import (
)
func (f *Middlewares) TenantResolve(c fiber.Ctx) error {
tenantCode := c.Params("tenant_code")
tenantCode := c.Params("tenantCode")
if tenantCode == "" {
return errorx.ErrMissingParameter.WithMsg("缺少 tenant_code")
return errorx.ErrMissingParameter.WithMsg("缺少 tenantCode")
}
tenantModel, err := services.Tenant.FindByCode(c, tenantCode)
@@ -39,18 +38,7 @@ func (f *Middlewares) TenantAuth(c fiber.Ctx) error {
return errorx.ErrTokenMissing
}
jwtProvider := f.jwt
if jwtProvider == nil {
if err := container.Container.Invoke(func(j *jwt.JWT) {
jwtProvider = j
f.jwt = j
}); err != nil {
f.log.WithError(err).Error("middlewares.tenant.auth.jwt_provider_missing")
return errorx.ErrInternalError.WithMsg("jwt provider missing")
}
}
claims, err := jwtProvider.Parse(authHeader)
claims, err := f.jwt.Parse(authHeader)
if err != nil {
f.log.WithError(err).Warn("middlewares.tenant.auth.invalid_token")
switch err {

View File

@@ -1,8 +1,11 @@
package requests
// KV is a generic key-value response item, commonly used for label/value enums.
type KV struct {
Key string `json:"key,omitempty"`
Value any `json:"value,omitempty"`
// Key is a machine-readable value, usually an enum string.
Key string `json:"key,omitempty"`
// Value is the label payload, often a human-readable string.
Value any `json:"value,omitempty"`
}
func NewKV(k string, v any) KV {

View File

@@ -2,14 +2,21 @@ package requests
import "github.com/samber/lo"
// Pager is a common paginated API response envelope.
type Pager struct {
// Pagination contains paging inputs (page/limit) echoed back in the response.
Pagination ` json:",inline"`
Total int64 `json:"total"`
Items any `json:"items"`
// Total is the total number of items matching current filter (before paging).
Total int64 `json:"total"`
// Items is the paged result list; concrete type depends on endpoint.
Items any `json:"items"`
}
// Pagination defines common paging query parameters used by list endpoints.
type Pagination struct {
Page int64 `json:"page" form:"page" query:"page"`
// Page is 1-based page index; values <= 0 are normalized to 1.
Page int64 `json:"page" form:"page" query:"page"`
// Limit is page size; only values in {10,20,50,100} are accepted (otherwise defaults to 10).
Limit int64 `json:"limit" form:"limit" query:"limit"`
}

View File

@@ -6,8 +6,11 @@ import (
"github.com/samber/lo"
)
// SortQueryFilter defines common query sorting parameters used by list endpoints.
type SortQueryFilter struct {
Asc *string `json:"asc" form:"asc"`
// Asc specifies comma-separated field names to sort ascending by.
Asc *string `json:"asc" form:"asc"`
// Desc specifies comma-separated field names to sort descending by.
Desc *string `json:"desc" form:"desc"`
}

View File

@@ -26,9 +26,9 @@ type content struct{}
// ContentDetailResult is the internal detail result used by controllers.
type ContentDetailResult struct {
// Content is the content entity.
Content *models.Content
Content *models.Content
// Price is the price settings (may be nil).
Price *models.ContentPrice
Price *models.ContentPrice
// HasAccess indicates whether the user can access main assets.
HasAccess bool
}
@@ -44,7 +44,7 @@ func (s *content) Create(ctx context.Context, tenantID, userID int64, form *dto.
visibility = consts.ContentVisibilityTenantOnly
}
previewSeconds := int32(60)
previewSeconds := consts.DefaultContentPreviewSeconds
if form.PreviewSeconds != nil && *form.PreviewSeconds > 0 {
previewSeconds = *form.PreviewSeconds
}