feat(kol): add KolProfileService.UpdateProfile
This commit is contained in:
@@ -15,6 +15,12 @@ type KolProfileService struct {
|
||||
repo repository.KolProfileRepository
|
||||
}
|
||||
|
||||
type UpdateKolProfileServiceInput struct {
|
||||
DisplayName string
|
||||
Bio *string
|
||||
AvatarURL *string
|
||||
}
|
||||
|
||||
type KolProfileResponse struct {
|
||||
ID int64 `json:"id"`
|
||||
TenantID int64 `json:"tenant_id"`
|
||||
@@ -43,6 +49,44 @@ func (s *KolProfileService) RequireActiveKol(ctx context.Context, actor auth.Act
|
||||
return profile, nil
|
||||
}
|
||||
|
||||
func (s *KolProfileService) UpdateProfile(ctx context.Context, actor auth.Actor, input UpdateKolProfileServiceInput) (*repository.KolProfile, error) {
|
||||
profile, err := s.RequireActiveKol(ctx, actor)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
displayName, err := validateKolDisplayName(input.DisplayName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
bio, err := validateKolBio(input.Bio)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
avatarURL, err := validateKolAvatarURL(input.AvatarURL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := s.repo.Update(ctx, actor.TenantID, repository.UpdateKolProfileInput{
|
||||
ID: profile.ID,
|
||||
DisplayName: displayName,
|
||||
Bio: bio,
|
||||
AvatarURL: avatarURL,
|
||||
}); err != nil {
|
||||
return nil, response.ErrInternal(50062, "kol_profile_update_failed", err.Error())
|
||||
}
|
||||
|
||||
updated, err := s.repo.GetByID(ctx, profile.ID)
|
||||
if err != nil {
|
||||
return nil, response.ErrInternal(50061, "kol_profile_query_failed", err.Error())
|
||||
}
|
||||
if updated == nil {
|
||||
return nil, ErrNotActiveKol
|
||||
}
|
||||
return updated, nil
|
||||
}
|
||||
|
||||
func NewKolProfileResponse(profile *repository.KolProfile) *KolProfileResponse {
|
||||
if profile == nil {
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user