Files
quyun-v2/backend/app/http/v1/tenant.go
Rogee 54de243fa1 feat: Refactor user context handling and service methods
- Updated middleware to fetch user and tenant models by ID and set them in context.
- Refactored common service methods to accept userID as a parameter instead of extracting from context.
- Modified content service methods to include userID as a parameter for better clarity and performance.
- Adjusted coupon, creator, notification, order, tenant, user, and wallet services to utilize userID directly.
- Enhanced context key constants for improved readability and maintainability.
2025-12-30 22:49:26 +08:00

62 lines
1.6 KiB
Go

package v1
import (
"quyun/v2/app/http/v1/dto"
"quyun/v2/app/services"
"quyun/v2/pkg/consts"
"github.com/gofiber/fiber/v3"
"github.com/spf13/cast"
)
// @provider
type Tenant struct{}
// Get tenant public profile
//
// @Router /v1/tenants/:id [get]
// @Summary Get tenant profile
// @Description Get tenant public profile
// @Tags TenantPublic
// @Accept json
// @Produce json
// @Param id path string true "Tenant ID"
// @Success 200 {object} dto.TenantProfile
// @Bind id path
func (t *Tenant) Get(ctx fiber.Ctx, id string) (*dto.TenantProfile, error) {
uid := cast.ToInt64(ctx.Locals(consts.CtxKeyUser))
return services.Tenant.GetPublicProfile(ctx.Context(), uid, id)
}
// Follow a tenant
//
// @Router /v1/tenants/:id/follow [post]
// @Summary Follow tenant
// @Description Follow a tenant
// @Tags TenantPublic
// @Accept json
// @Produce json
// @Param id path string true "Tenant ID"
// @Success 200 {string} string "Followed"
// @Bind id path
func (t *Tenant) Follow(ctx fiber.Ctx, id string) error {
uid := cast.ToInt64(ctx.Locals(consts.CtxKeyUser))
return services.Tenant.Follow(ctx.Context(), uid, id)
}
// Unfollow a tenant
//
// @Router /v1/tenants/:id/follow [delete]
// @Summary Unfollow tenant
// @Description Unfollow a tenant
// @Tags TenantPublic
// @Accept json
// @Produce json
// @Param id path string true "Tenant ID"
// @Success 200 {string} string "Unfollowed"
// @Bind id path
func (t *Tenant) Unfollow(ctx fiber.Ctx, id string) error {
uid := cast.ToInt64(ctx.Locals(consts.CtxKeyUser))
return services.Tenant.Unfollow(ctx.Context(), uid, id)
}