Skip to content

Commit a6fd975

Browse files
committed
feat: 사용자 프로필 수정 로직 추가
1 parent 8d5f4b2 commit a6fd975

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/main/java/com/back/domain/profile/service/ProfileService.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.back.domain.profile.service;
22

33
import com.back.domain.profile.dto.ProfileResponseDto;
4+
import com.back.domain.profile.dto.ProfileUpdateRequestDto;
45
import com.back.domain.user.entity.User;
56
import com.back.domain.user.repository.UserRepository;
67
import 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
}

0 commit comments

Comments
 (0)