- Add TenantOptionalAuth middleware to allow access to public content without requiring authentication. - Introduce ListPublicPublished and PublicDetail methods in the content service to retrieve publicly accessible content. - Create tenant_public HTTP routes for listing and showing public content, including preview and main asset retrieval. - Enhance content tests to cover scenarios for public content access and permissions. - Update specifications to reflect the new public content access features and rules.
73 lines
2.5 KiB
Go
73 lines
2.5 KiB
Go
// Code generated by atomctl. DO NOT EDIT.
|
|
|
|
// Package tenant_public provides HTTP route definitions and registration
|
|
// for the quyun/v2 application.
|
|
package tenant_public
|
|
|
|
import (
|
|
tenant_dto "quyun/v2/app/http/tenant/dto"
|
|
"quyun/v2/app/middlewares"
|
|
"quyun/v2/database/models"
|
|
|
|
"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 tenant_public module.
|
|
//
|
|
// @provider contracts.HttpRoute atom.GroupRoutes
|
|
type Routes struct {
|
|
log *log.Entry `inject:"false"`
|
|
middlewares *middlewares.Middlewares
|
|
// Controller instances
|
|
content *content
|
|
}
|
|
|
|
// Prepare initializes the routes provider with logging configuration.
|
|
func (r *Routes) Prepare() error {
|
|
r.log = log.WithField("module", "routes.tenant_public")
|
|
r.log.Info("Initializing routes module")
|
|
return nil
|
|
}
|
|
|
|
// Name returns the unique identifier for this routes provider.
|
|
func (r *Routes) Name() string {
|
|
return "tenant_public"
|
|
}
|
|
|
|
// 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: content
|
|
r.log.Debugf("Registering route: Get /t/:tenantCode/v1/public/contents -> content.list")
|
|
router.Get("/t/:tenantCode/v1/public/contents"[len(r.Path()):], DataFunc2(
|
|
r.content.list,
|
|
Local[*models.Tenant]("tenant"),
|
|
Query[tenant_dto.ContentListFilter]("filter"),
|
|
))
|
|
r.log.Debugf("Registering route: Get /t/:tenantCode/v1/public/contents/:contentID -> content.show")
|
|
router.Get("/t/:tenantCode/v1/public/contents/:contentID"[len(r.Path()):], DataFunc2(
|
|
r.content.show,
|
|
Local[*models.Tenant]("tenant"),
|
|
PathParam[int64]("contentID"),
|
|
))
|
|
r.log.Debugf("Registering route: Get /t/:tenantCode/v1/public/contents/:contentID/assets -> content.mainAssets")
|
|
router.Get("/t/:tenantCode/v1/public/contents/:contentID/assets"[len(r.Path()):], DataFunc2(
|
|
r.content.mainAssets,
|
|
Local[*models.Tenant]("tenant"),
|
|
PathParam[int64]("contentID"),
|
|
))
|
|
r.log.Debugf("Registering route: Get /t/:tenantCode/v1/public/contents/:contentID/preview -> content.previewAssets")
|
|
router.Get("/t/:tenantCode/v1/public/contents/:contentID/preview"[len(r.Path()):], DataFunc2(
|
|
r.content.previewAssets,
|
|
Local[*models.Tenant]("tenant"),
|
|
PathParam[int64]("contentID"),
|
|
))
|
|
|
|
r.log.Info("Successfully registered all routes")
|
|
}
|