Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,17 @@ Page<Scenario> findByUserIdAndDecisionLineIsNotNullAndStatusOrderByCreatedDateDe

@Query("select s.id from Scenario s where s.baseLine.id = :baseLineId")
List<Long> findIdsByBaseLine_Id(@Param("baseLineId") Long baseLineId);

@Modifying(clearAutomatically = true)
@Query("""
UPDATE Scenario s
SET s.representative =
CASE WHEN s.id = :scenarioId THEN true ELSE false END
WHERE s.user.id = :userId
AND (s.representative = true OR s.id = :scenarioId)
""")
void updateRepresentativeStatus(
@Param("userId") Long userId,
@Param("scenarioId") Long scenarioId
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ public ResponseEntity<UserInfoResponse> getMyInfo(@AuthenticationPrincipal Custo
@PostMapping("/users-info")
public ResponseEntity<UserInfoResponse> createMyInfo(@AuthenticationPrincipal CustomUserDetails principal,
@Valid @RequestBody UserInfoRequest req) {
return ResponseEntity.ok(userInfoService.createMyInfo(principal.getId(), req));
return ResponseEntity.ok(userInfoService.saveOrUpdateMyInfo(principal.getId(), req));
}

// 사용자 정보 수정
@PutMapping("/users-info")
public ResponseEntity<UserInfoResponse> updateMyInfo(@AuthenticationPrincipal CustomUserDetails principal,
@Valid @RequestBody UserInfoRequest req) {
return ResponseEntity.ok(userInfoService.updateMyInfo(principal.getId(), req));
return ResponseEntity.ok(userInfoService.saveOrUpdateMyInfo(principal.getId(), req));
}

// 내가 만든 시나리오 목록 조회 (평행우주 목록)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public User createAndSaveGuest(){
User guest = User.builder()
.email(guestEmail)
.username(guestLoginId)
.password(null) // 게스트 비밀번호 없음(추후 전환 시 설정)
.password(null)
.nickname("게스트_" + UUID.randomUUID().toString().substring(0, 4))
.birthdayAt(LocalDateTime.now())
.role(Role.GUEST)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,7 @@ public UserInfoResponse getMyInfo(Long userId) {
}

@Transactional
public UserInfoResponse createMyInfo(Long userId, UserInfoRequest req) {
User user = userRepository.findById(userId)
.orElseThrow(() -> new EntityNotFoundException("User not found: " + userId));

applyPatch(user, req);

return UserInfoResponse.from(user);
}

@Transactional
public UserInfoResponse updateMyInfo(Long userId, UserInfoRequest req) {
public UserInfoResponse saveOrUpdateMyInfo(Long userId, UserInfoRequest req) {
User user = userRepository.findById(userId)
.orElseThrow(() -> new EntityNotFoundException("User not found: " + userId));

Expand Down Expand Up @@ -85,11 +75,12 @@ public PageResponse<UserScenarioListResponse> getMyScenarios(Long userId, Pageab
// 시나리오 id 목록 추출
List<Long> scenarioIds = scenarioPage.getContent().stream()
.map(Scenario::getId)
.collect(Collectors.toList());
.toList();

// SceneType 조회, 시나리오 id별로 그룹화
List<SceneType> sceneTypes = sceneTypeRepository.findByScenarioIdIn(scenarioIds);
Map<Long, List<SceneType>> sceneTypeMap = sceneTypes.stream()
Map<Long, List<SceneType>> sceneTypeMap = scenarioIds.isEmpty()
? Map.of()
: sceneTypeRepository.findByScenarioIdIn(scenarioIds).stream()
.collect(Collectors.groupingBy(st -> st.getScenario().getId()));

Page<UserScenarioListResponse> responsePage = scenarioPage.map(scenario ->
Expand Down Expand Up @@ -134,12 +125,7 @@ public void setProfileScenario(Long userId, Long scenarioId) {
throw new IllegalArgumentException("Scenario does not belong to user");
}

// 기존 대표 시나리오를 false로 변경
scenarioRepository.findByUserIdAndRepresentativeTrue(userId)
.ifPresent(existingRepresentative -> existingRepresentative.setRepresentative(false));

// 새로운 시나리오를 대표로 설정
scenario.setRepresentative(true);
scenarioRepository.updateRepresentativeStatus(userId, scenarioId);
}

public UserProfileResponse getMyProfile(Long userId) {
Expand All @@ -157,11 +143,11 @@ public UserProfileResponse getMyProfile(Long userId) {
}

private void applyPatch(User user, UserInfoRequest req) {
if (req.username() != null) user.setUsername(req.username());
if (req.username() != null) user.setUsername(req.username().trim());
if (req.birthdayAt() != null) user.setBirthdayAt(req.birthdayAt());
if (req.gender() != null) user.setGender(req.gender());
if (req.mbti() != null) user.setMbti(req.mbti());
if (req.beliefs() != null) user.setBeliefs(req.beliefs());
if (req.beliefs() != null) user.setBeliefs(req.beliefs().trim());
if (req.lifeSatis() != null) user.setLifeSatis(req.lifeSatis());
if (req.relationship() != null) user.setRelationship(req.relationship());
if (req.workLifeBal() != null) user.setWorkLifeBal(req.workLifeBal());
Expand Down