-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Feat/#30 유저 프로필 수정 기능 구현
- Loading branch information
Showing
7 changed files
with
116 additions
and
2 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
src/main/java/coffeemeet/server/interest/service/InterestService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package coffeemeet.server.interest.service; | ||
|
||
import coffeemeet.server.interest.domain.Interest; | ||
import coffeemeet.server.interest.domain.Keyword; | ||
import coffeemeet.server.interest.repository.InterestRepository; | ||
import coffeemeet.server.user.domain.User; | ||
import coffeemeet.server.user.repository.UserRepository; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class InterestService { | ||
|
||
private final InterestRepository interestRepository; | ||
private final UserRepository userRepository; | ||
|
||
@Transactional | ||
public void updateInterests(Long userId, List<Keyword> interests) { | ||
|
||
for (Keyword interest : interests) { | ||
try { | ||
Keyword.valueOf(interest.name()); | ||
} catch (IllegalArgumentException e) { | ||
throw new IllegalArgumentException("유효한 관심사가 아닙니다."); | ||
} | ||
} | ||
|
||
User user = userRepository.findById(userId) | ||
.orElseThrow(() -> new IllegalArgumentException("해당 사용자를 찾을 수 없습니다.")); | ||
|
||
List<Interest> currentInterests = interestRepository.findAllByUserId(userId); | ||
interestRepository.deleteAll(currentInterests); | ||
|
||
for (Keyword keyword : interests) { | ||
Interest newInterest = new Interest(keyword, user); | ||
interestRepository.save(newInterest); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/main/java/coffeemeet/server/user/dto/UpdateProfileImageUrlRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package coffeemeet.server.user.dto; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
|
||
public record UpdateProfileImageUrlRequest(@NotBlank String profileImageUrl) { | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/coffeemeet/server/user/dto/UpdateProfileRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package coffeemeet.server.user.dto; | ||
|
||
import coffeemeet.server.interest.domain.Keyword; | ||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.NotNull; | ||
import jakarta.validation.constraints.Size; | ||
import java.util.List; | ||
|
||
public record UpdateProfileRequest(@NotBlank String nickname, | ||
@NotNull @Size(min = 1, max = 3) List<Keyword> interests) { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters