File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
src/main/java/com/back/domain/profile/service Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change 11package com .back .domain .profile .service ;
22
33import com .back .domain .profile .dto .ProfileResponseDto ;
4+ import com .back .domain .profile .dto .ProfileUpdateRequestDto ;
45import com .back .domain .user .entity .User ;
56import com .back .domain .user .repository .UserRepository ;
67import com .back .domain .user .support .AbvView ;
@@ -31,4 +32,31 @@ public ProfileResponseDto getProfile(Long id) {
3132 .abvLabel (label )
3233 .build ();
3334 }
35+
36+ @ Transactional
37+ public ProfileResponseDto updateProfile (Long id , ProfileUpdateRequestDto profileUpdateRequestDto ) {
38+ User user = userRepository .findById (id ).orElseThrow (() -> new ServiceException (404 , "사용자를 찾을 수 없습니다." ));
39+
40+ if (profileUpdateRequestDto .getNickname () != null ) {
41+ String nickname = profileUpdateRequestDto .getNickname ().trim ();
42+ if (nickname .isEmpty () || nickname .length () > 10 ) {
43+ throw new ServiceException (400 , "닉네임은 1~10자" );
44+ }
45+
46+ if (userRepository .existsByNicknameAndIdNot (nickname , id )) {
47+ throw new ServiceException (409 , "이미 사용중인 닉네임" );
48+ }
49+
50+ user .setNickname (nickname );
51+ }
52+
53+ if (profileUpdateRequestDto .getEmail () != null ) {
54+ String email = profileUpdateRequestDto .getEmail ().trim ();
55+ user .setEmail (email .isEmpty () ? null : email );
56+ }
57+
58+ userRepository .save (user );
59+
60+ return getProfile (id );
61+ }
3462}
You can’t perform that action at this time.
0 commit comments