Files
quyun-v2/backend/app/http/v1/tenant.go

88 lines
2.2 KiB
Go

package v1
import (
"quyun/v2/app/http/v1/dto"
"quyun/v2/app/requests"
"quyun/v2/app/services"
"quyun/v2/database/models"
"github.com/gofiber/fiber/v3"
)
// @provider
type Tenant struct{}
// List creator contents
//
// @Router /v1/creators/:id/contents [get]
// @Summary List creator contents
// @Description List contents of a specific creator
// @Tags TenantPublic
// @Accept json
// @Produce json
// @Param id path string true "Tenant ID"
// @Param page query int false "Page"
// @Param limit query int false "Limit"
// @Success 200 {object} requests.Pager
// @Bind id path
// @Bind filter query
func (t *Tenant) ListContents(ctx fiber.Ctx, id string, filter *dto.ContentListFilter) (*requests.Pager, error) {
if filter == nil {
filter = &dto.ContentListFilter{}
}
filter.TenantID = &id
return services.Content.List(ctx, filter)
}
// 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 user local key(__ctx_user)
// @Bind id path
func (t *Tenant) Get(ctx fiber.Ctx, user *models.User, id string) (*dto.TenantProfile, error) {
uid := int64(0)
if user != nil {
uid = user.ID
}
return services.Tenant.GetPublicProfile(ctx, 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 user local key(__ctx_user)
// @Bind id path
func (t *Tenant) Follow(ctx fiber.Ctx, user *models.User, id string) error {
return services.Tenant.Follow(ctx, user.ID, 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 user local key(__ctx_user)
// @Bind id path
func (t *Tenant) Unfollow(ctx fiber.Ctx, user *models.User, id string) error {
return services.Tenant.Unfollow(ctx, user.ID, id)
}