@@ -42,17 +42,7 @@ public UserInfoResponse getMyInfo(Long userId) {
4242 }
4343
4444 @ Transactional
45- public UserInfoResponse createMyInfo (Long userId , UserInfoRequest req ) {
46- User user = userRepository .findById (userId )
47- .orElseThrow (() -> new EntityNotFoundException ("User not found: " + userId ));
48-
49- applyPatch (user , req );
50-
51- return UserInfoResponse .from (user );
52- }
53-
54- @ Transactional
55- public UserInfoResponse updateMyInfo (Long userId , UserInfoRequest req ) {
45+ public UserInfoResponse saveOrUpdateMyInfo (Long userId , UserInfoRequest req ) {
5646 User user = userRepository .findById (userId )
5747 .orElseThrow (() -> new EntityNotFoundException ("User not found: " + userId ));
5848
@@ -85,11 +75,12 @@ public PageResponse<UserScenarioListResponse> getMyScenarios(Long userId, Pageab
8575 // 시나리오 id 목록 추출
8676 List <Long > scenarioIds = scenarioPage .getContent ().stream ()
8777 .map (Scenario ::getId )
88- .collect ( Collectors . toList () );
78+ .toList ();
8979
9080 // SceneType 조회, 시나리오 id별로 그룹화
91- List <SceneType > sceneTypes = sceneTypeRepository .findByScenarioIdIn (scenarioIds );
92- Map <Long , List <SceneType >> sceneTypeMap = sceneTypes .stream ()
81+ Map <Long , List <SceneType >> sceneTypeMap = scenarioIds .isEmpty ()
82+ ? Map .of ()
83+ : sceneTypeRepository .findByScenarioIdIn (scenarioIds ).stream ()
9384 .collect (Collectors .groupingBy (st -> st .getScenario ().getId ()));
9485
9586 Page <UserScenarioListResponse > responsePage = scenarioPage .map (scenario ->
@@ -134,12 +125,7 @@ public void setProfileScenario(Long userId, Long scenarioId) {
134125 throw new IllegalArgumentException ("Scenario does not belong to user" );
135126 }
136127
137- // 기존 대표 시나리오를 false로 변경
138- scenarioRepository .findByUserIdAndRepresentativeTrue (userId )
139- .ifPresent (existingRepresentative -> existingRepresentative .setRepresentative (false ));
140-
141- // 새로운 시나리오를 대표로 설정
142- scenario .setRepresentative (true );
128+ scenarioRepository .updateRepresentativeStatus (userId , scenarioId );
143129 }
144130
145131 public UserProfileResponse getMyProfile (Long userId ) {
@@ -157,11 +143,11 @@ public UserProfileResponse getMyProfile(Long userId) {
157143 }
158144
159145 private void applyPatch (User user , UserInfoRequest req ) {
160- if (req .username () != null ) user .setUsername (req .username ());
146+ if (req .username () != null ) user .setUsername (req .username (). trim () );
161147 if (req .birthdayAt () != null ) user .setBirthdayAt (req .birthdayAt ());
162148 if (req .gender () != null ) user .setGender (req .gender ());
163149 if (req .mbti () != null ) user .setMbti (req .mbti ());
164- if (req .beliefs () != null ) user .setBeliefs (req .beliefs ());
150+ if (req .beliefs () != null ) user .setBeliefs (req .beliefs (). trim () );
165151 if (req .lifeSatis () != null ) user .setLifeSatis (req .lifeSatis ());
166152 if (req .relationship () != null ) user .setRelationship (req .relationship ());
167153 if (req .workLifeBal () != null ) user .setWorkLifeBal (req .workLifeBal ());
0 commit comments