Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
163 lines
4.5 KiB
Go
163 lines
4.5 KiB
Go
package v1
|
|
|
|
import (
|
|
"quyun/v2/app/errorx"
|
|
"quyun/v2/app/http/v1/dto"
|
|
"quyun/v2/app/requests"
|
|
"quyun/v2/app/services"
|
|
|
|
"github.com/gofiber/fiber/v3"
|
|
)
|
|
|
|
// @provider
|
|
type Tenant struct{}
|
|
|
|
// List tenants
|
|
//
|
|
// @Router /v1/t/:tenantCode/tenants [get]
|
|
// @Summary List tenants
|
|
// @Description List public tenants under current tenant scope
|
|
// @Tags TenantPublic
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param page query int false "Page number"
|
|
// @Param limit query int false "Page size"
|
|
// @Param keyword query string false "Search keyword"
|
|
// @Success 200 {object} requests.Pager{items=[]dto.TenantProfile}
|
|
// @Bind filter query
|
|
func (t *Tenant) List(ctx fiber.Ctx, filter *dto.TenantListFilter) (*requests.Pager, error) {
|
|
tenantID := getTenantID(ctx)
|
|
|
|
return services.Tenant.List(ctx, tenantID, filter)
|
|
}
|
|
|
|
// Get tenant profile
|
|
//
|
|
// @Router /v1/t/:tenantCode/tenants/:id<int> [get]
|
|
// @Summary Get tenant profile
|
|
// @Description Get public tenant profile by tenant ID
|
|
// @Tags TenantPublic
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param id path int64 true "Tenant ID"
|
|
// @Success 200 {object} dto.TenantProfile
|
|
// @Bind id path
|
|
func (t *Tenant) Get(ctx fiber.Ctx, id int64) (*dto.TenantProfile, error) {
|
|
tenantID := getTenantID(ctx)
|
|
if tenantID > 0 && id != tenantID {
|
|
return nil, errorx.ErrForbidden.WithMsg("租户不匹配")
|
|
}
|
|
userID := getUserID(ctx)
|
|
|
|
return services.Tenant.GetPublicProfile(ctx, id, userID)
|
|
}
|
|
|
|
// Follow tenant
|
|
//
|
|
// @Router /v1/t/:tenantCode/tenants/:id<int>/follow [post]
|
|
// @Summary Follow tenant
|
|
// @Description Follow a tenant
|
|
// @Tags TenantPublic
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param id path int64 true "Tenant ID"
|
|
// @Success 200 {string} string "Followed"
|
|
// @Bind id path
|
|
func (t *Tenant) Follow(ctx fiber.Ctx, id int64) error {
|
|
tenantID := getTenantID(ctx)
|
|
if tenantID > 0 && id != tenantID {
|
|
return errorx.ErrForbidden.WithMsg("租户不匹配")
|
|
}
|
|
userID := getUserID(ctx)
|
|
|
|
return services.Tenant.Follow(ctx, id, userID)
|
|
}
|
|
|
|
// Unfollow tenant
|
|
//
|
|
// @Router /v1/t/:tenantCode/tenants/:id<int>/follow [delete]
|
|
// @Summary Unfollow tenant
|
|
// @Description Unfollow a tenant
|
|
// @Tags TenantPublic
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param id path int64 true "Tenant ID"
|
|
// @Success 200 {string} string "Unfollowed"
|
|
// @Bind id path
|
|
func (t *Tenant) Unfollow(ctx fiber.Ctx, id int64) error {
|
|
tenantID := getTenantID(ctx)
|
|
if tenantID > 0 && id != tenantID {
|
|
return errorx.ErrForbidden.WithMsg("租户不匹配")
|
|
}
|
|
userID := getUserID(ctx)
|
|
|
|
return services.Tenant.Unfollow(ctx, id, userID)
|
|
}
|
|
|
|
// Apply to join tenant
|
|
//
|
|
// @Router /v1/t/:tenantCode/tenants/:id<int>/join [post]
|
|
// @Summary Apply to join tenant
|
|
// @Description Apply to join a tenant
|
|
// @Tags TenantPublic
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param id path int64 true "Tenant ID"
|
|
// @Param form body dto.TenantJoinApplyForm true "Join apply form"
|
|
// @Success 200 {string} string "Applied"
|
|
// @Bind id path
|
|
// @Bind form body
|
|
func (t *Tenant) ApplyJoin(ctx fiber.Ctx, id int64, form *dto.TenantJoinApplyForm) error {
|
|
tenantID := getTenantID(ctx)
|
|
if tenantID > 0 && id != tenantID {
|
|
return errorx.ErrForbidden.WithMsg("租户不匹配")
|
|
}
|
|
userID := getUserID(ctx)
|
|
|
|
return services.Tenant.ApplyJoin(ctx, id, userID, form)
|
|
}
|
|
|
|
// Cancel join application
|
|
//
|
|
// @Router /v1/t/:tenantCode/tenants/:id<int>/join [delete]
|
|
// @Summary Cancel join application
|
|
// @Description Cancel pending tenant join application
|
|
// @Tags TenantPublic
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param id path int64 true "Tenant ID"
|
|
// @Success 200 {string} string "Canceled"
|
|
// @Bind id path
|
|
func (t *Tenant) CancelJoin(ctx fiber.Ctx, id int64) error {
|
|
tenantID := getTenantID(ctx)
|
|
if tenantID > 0 && id != tenantID {
|
|
return errorx.ErrForbidden.WithMsg("租户不匹配")
|
|
}
|
|
userID := getUserID(ctx)
|
|
|
|
return services.Tenant.CancelJoin(ctx, id, userID)
|
|
}
|
|
|
|
// Accept tenant invite
|
|
//
|
|
// @Router /v1/t/:tenantCode/tenants/:id<int>/invites/accept [post]
|
|
// @Summary Accept tenant invite
|
|
// @Description Accept a tenant invite by code
|
|
// @Tags TenantPublic
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param id path int64 true "Tenant ID"
|
|
// @Param form body dto.TenantInviteAcceptForm true "Invite form"
|
|
// @Success 200 {string} string "Accepted"
|
|
// @Bind id path
|
|
// @Bind form body
|
|
func (t *Tenant) AcceptInvite(ctx fiber.Ctx, id int64, form *dto.TenantInviteAcceptForm) error {
|
|
tenantID := getTenantID(ctx)
|
|
if tenantID > 0 && id != tenantID {
|
|
return errorx.ErrForbidden.WithMsg("租户不匹配")
|
|
}
|
|
userID := getUserID(ctx)
|
|
|
|
return services.Tenant.AcceptInvite(ctx, id, userID, form)
|
|
}
|