feat(kol): KOL workspace services (profile/package/prompt/asset/renderer)
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/geo-platform/tenant-api/internal/shared/auth"
|
||||
"github.com/geo-platform/tenant-api/internal/shared/response"
|
||||
"github.com/geo-platform/tenant-api/internal/tenant/repository"
|
||||
)
|
||||
|
||||
var ErrNotActiveKol = response.ErrForbidden(40341, "kol_not_active", "user is not an active KOL")
|
||||
|
||||
type KolProfileService struct {
|
||||
repo repository.KolProfileRepository
|
||||
}
|
||||
|
||||
type KolProfileResponse struct {
|
||||
ID int64 `json:"id"`
|
||||
TenantID int64 `json:"tenant_id"`
|
||||
UserID int64 `json:"user_id"`
|
||||
DisplayName string `json:"display_name"`
|
||||
Bio *string `json:"bio"`
|
||||
AvatarURL *string `json:"avatar_url"`
|
||||
MarketEnabled bool `json:"market_enabled"`
|
||||
Status string `json:"status"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
func NewKolProfileService(repo repository.KolProfileRepository) *KolProfileService {
|
||||
return &KolProfileService{repo: repo}
|
||||
}
|
||||
|
||||
func (s *KolProfileService) RequireActiveKol(ctx context.Context, actor auth.Actor) (*repository.KolProfile, error) {
|
||||
profile, err := s.repo.GetByUser(ctx, actor.TenantID, actor.UserID)
|
||||
if err != nil {
|
||||
return nil, response.ErrInternal(50061, "kol_profile_query_failed", err.Error())
|
||||
}
|
||||
if profile == nil || profile.Status != "active" {
|
||||
return nil, ErrNotActiveKol
|
||||
}
|
||||
return profile, nil
|
||||
}
|
||||
|
||||
func NewKolProfileResponse(profile *repository.KolProfile) *KolProfileResponse {
|
||||
if profile == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &KolProfileResponse{
|
||||
ID: profile.ID,
|
||||
TenantID: profile.TenantID,
|
||||
UserID: profile.UserID,
|
||||
DisplayName: profile.DisplayName,
|
||||
Bio: profile.Bio,
|
||||
AvatarURL: profile.AvatarURL,
|
||||
MarketEnabled: profile.MarketEnabled,
|
||||
Status: profile.Status,
|
||||
CreatedAt: profile.CreatedAt,
|
||||
UpdatedAt: profile.UpdatedAt,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user