Update update_user_info logic in service_user
Signed-off-by: Asai Neko <sugar@sne.moe>
This commit is contained in:
@@ -24,9 +24,9 @@ import { useUserInfo } from '@/hooks/data/useUserInfo';
|
||||
|
||||
const formSchema = z.object({
|
||||
username: z.string().min(5),
|
||||
nickname: z.string(),
|
||||
subtitle: z.string(),
|
||||
avatar: z.url(),
|
||||
nickname: z.string().min(1),
|
||||
subtitle: z.string().min(1),
|
||||
avatar: z.url().min(1),
|
||||
});
|
||||
export function EditProfileDialog() {
|
||||
const { data } = useUserInfo();
|
||||
@@ -41,7 +41,7 @@ export function EditProfileDialog() {
|
||||
subtitle: user.subtitle,
|
||||
},
|
||||
validators: {
|
||||
onSubmit: formSchema
|
||||
onBlur: formSchema,
|
||||
},
|
||||
onSubmit: async ({
|
||||
value,
|
||||
|
||||
@@ -40,50 +40,46 @@ func (self *UserServiceImpl) UpdateUserInfo(payload *UserInfoPayload) (result *U
|
||||
userData.SetUsername(payload.Data.Username)
|
||||
}
|
||||
|
||||
if payload.Data.Nickname != "" {
|
||||
if utf8.RuneCountInString(payload.Data.Nickname) > 24 {
|
||||
execption := new(exception.Builder).
|
||||
SetStatus(exception.StatusUser).
|
||||
SetService(exception.ServiceUser).
|
||||
SetType(exception.TypeCommon).
|
||||
SetOriginal(exception.CommonErrorInvalidInput)
|
||||
if utf8.RuneCountInString(payload.Data.Nickname) > 24 {
|
||||
execption := new(exception.Builder).
|
||||
SetStatus(exception.StatusUser).
|
||||
SetService(exception.ServiceUser).
|
||||
SetType(exception.TypeCommon).
|
||||
SetOriginal(exception.CommonErrorInvalidInput)
|
||||
|
||||
result = &UserInfoResult{
|
||||
Common: shared.CommonResult{
|
||||
HttpCode: 400,
|
||||
Exception: execption,
|
||||
},
|
||||
Data: nil,
|
||||
}
|
||||
|
||||
return
|
||||
result = &UserInfoResult{
|
||||
Common: shared.CommonResult{
|
||||
HttpCode: 400,
|
||||
Exception: execption,
|
||||
},
|
||||
Data: nil,
|
||||
}
|
||||
userData.SetNickname(payload.Data.Nickname)
|
||||
|
||||
return
|
||||
}
|
||||
userData.SetNickname(payload.Data.Nickname)
|
||||
|
||||
if payload.Data.Subtitle != "" {
|
||||
if utf8.RuneCountInString(payload.Data.Subtitle) > 32 {
|
||||
execption := new(exception.Builder).
|
||||
SetStatus(exception.StatusUser).
|
||||
SetService(exception.ServiceUser).
|
||||
SetEndpoint(exception.EndpointUserServiceUpdate).
|
||||
SetType(exception.TypeCommon).
|
||||
SetOriginal(exception.CommonErrorInvalidInput).
|
||||
SetError(nil).
|
||||
Throw(payload.Context)
|
||||
if utf8.RuneCountInString(payload.Data.Subtitle) > 32 {
|
||||
execption := new(exception.Builder).
|
||||
SetStatus(exception.StatusUser).
|
||||
SetService(exception.ServiceUser).
|
||||
SetEndpoint(exception.EndpointUserServiceUpdate).
|
||||
SetType(exception.TypeCommon).
|
||||
SetOriginal(exception.CommonErrorInvalidInput).
|
||||
SetError(nil).
|
||||
Throw(payload.Context)
|
||||
|
||||
result = &UserInfoResult{
|
||||
Common: shared.CommonResult{
|
||||
HttpCode: 400,
|
||||
Exception: execption,
|
||||
},
|
||||
Data: nil,
|
||||
}
|
||||
|
||||
return
|
||||
result = &UserInfoResult{
|
||||
Common: shared.CommonResult{
|
||||
HttpCode: 400,
|
||||
Exception: execption,
|
||||
},
|
||||
Data: nil,
|
||||
}
|
||||
userData.SetSubtitle(payload.Data.Subtitle)
|
||||
|
||||
return
|
||||
}
|
||||
userData.SetSubtitle(payload.Data.Subtitle)
|
||||
|
||||
if payload.Data.Avatar != "" {
|
||||
_, err := url.ParseRequestURI(payload.Data.Avatar)
|
||||
@@ -108,6 +104,8 @@ func (self *UserServiceImpl) UpdateUserInfo(payload *UserInfoPayload) (result *U
|
||||
return
|
||||
}
|
||||
userData.SetAvatar(payload.Data.Avatar)
|
||||
} else if payload.Data.Avatar == "" {
|
||||
userData.SetAvatar("")
|
||||
}
|
||||
|
||||
if payload.Data.Bio != "" {
|
||||
@@ -131,7 +129,9 @@ func (self *UserServiceImpl) UpdateUserInfo(payload *UserInfoPayload) (result *U
|
||||
|
||||
return
|
||||
}
|
||||
userData.Bio = payload.Data.Bio
|
||||
userData.SetBio(payload.Data.Bio)
|
||||
} else if payload.Data.Bio == "" {
|
||||
userData.SetBio("")
|
||||
}
|
||||
|
||||
err = userData.UpdateByUserID(payload.Context, &payload.UserId)
|
||||
|
||||
Reference in New Issue
Block a user