2020import org .dfbf .soundlink .global .comm .enums .Emotions ;
2121import org .dfbf .soundlink .global .exception .ErrorCode ;
2222import org .dfbf .soundlink .global .exception .ResponseResult ;
23+ import org .dfbf .soundlink .global .slack .service .SlackService ;
2324import org .springframework .dao .DataAccessException ;
2425import org .springframework .data .domain .Page ;
2526import org .springframework .data .domain .PageRequest ;
@@ -41,6 +42,7 @@ public class EmotionRecordService {
4142 private final SpotifyMusicRepository spotifyMusicRepository ;
4243 private final EmotionRecordRepository emotionRecordRepository ;
4344 private final UserRepository userRepository ;
45+ private final SlackService slackService ;
4446
4547 // private final EmotionRecordCacheService emotionRecordCacheService;
4648 private final ChatRoomRepository chatRoomRepository ;
@@ -81,10 +83,13 @@ public ResponseResult saveEmotionRecordWithMusic(Long userId, EmotionRecordReque
8183
8284 return new ResponseResult (ErrorCode .SUCCESS );
8385 } catch (UserNotFoundException e ) {
86+ slackService .sendMsg (request , e .getMessage ());
8487 return new ResponseResult (ErrorCode .FAIL_TO_FIND_USER , e .getMessage ());
8588 } catch (DataAccessException e ) {
89+ slackService .sendMsg (request , e .getMessage ());
8690 return new ResponseResult (ErrorCode .DB_ERROR , e .getMessage ());
8791 } catch (Exception e ) {
92+ slackService .sendMsg (request , e .getMessage ());
8893 log .error ("감정기록 저장 서버 에러 {}" , e .getMessage ());
8994 return new ResponseResult (ErrorCode .INTERNAL_SERVER_ERROR , e .getMessage ());
9095 }
@@ -109,8 +114,10 @@ public ResponseResult getEmotionRecordsByUserId(Long userId, int page, int size)
109114
110115 return new ResponseResult (ErrorCode .SUCCESS , EmotionRecordPageResponseDTO .fromPage (recordsPage , dtoList ));
111116 } catch (DataAccessException e ) {
117+ slackService .sendMsg (userId , e .getMessage ());
112118 return new ResponseResult (ErrorCode .DB_ERROR , e .getMessage ());
113119 } catch (Exception e ) {
120+ slackService .sendMsg (userId , e .getMessage ());
114121 return new ResponseResult (ErrorCode .INTERNAL_SERVER_ERROR , e .getMessage ());
115122 }
116123 }
@@ -135,8 +142,10 @@ public ResponseResult getEmotionRecordsByLoginId(String userTag, int page, int s
135142
136143 return new ResponseResult (ErrorCode .SUCCESS , EmotionRecordPageResponseDTO .fromPage (recordsPage , dtoList ));
137144 } catch (DataAccessException e ) {
145+ slackService .sendMsg (userTag , e .getMessage ());
138146 return new ResponseResult (ErrorCode .DB_ERROR , e .getMessage ());
139147 } catch (Exception e ) {
148+ slackService .sendMsg (userTag , e .getMessage ());
140149 return new ResponseResult (ErrorCode .INTERNAL_SERVER_ERROR , e .getMessage ());
141150 }
142151 }
@@ -156,6 +165,7 @@ public ResponseResult getEmotionRecordsExcludingUserIdByFilters(Long userId, Lis
156165 .map (e -> Emotions .valueOf (e .toUpperCase ()))
157166 .toList ();
158167 } catch (IllegalArgumentException e ) {
168+ slackService .sendMsg (null , e .getMessage ());
159169 return new ResponseResult (ErrorCode .FAIL_TO_FIND_EMOTION , "잘못된 감정 값이 포함되어 있습니다." );
160170 }
161171 }
@@ -169,8 +179,10 @@ public ResponseResult getEmotionRecordsExcludingUserIdByFilters(Long userId, Lis
169179
170180 return new ResponseResult (ErrorCode .SUCCESS , EmotionRecordPageResponseDTO .fromPage (recordsPage , dtoList ));
171181 } catch (DataAccessException e ) {
182+ slackService .sendMsg (userId , e .getMessage ());
172183 return new ResponseResult (ErrorCode .DB_ERROR , e .getMessage ());
173184 } catch (Exception e ) {
185+ slackService .sendMsg (userId , e .getMessage ());
174186 return new ResponseResult (ErrorCode .INTERNAL_SERVER_ERROR , e .getMessage ());
175187 }
176188 }
@@ -184,10 +196,13 @@ public ResponseResult getEmotionRecord(Long userId, Long recordId) {
184196
185197 return new ResponseResult (ErrorCode .SUCCESS , EmotionRecordResponseWithOwnerDTO .fromEntity (records , userId ));
186198 } catch (EmotionRecordNotFoundException e ) {
199+ slackService .sendMsg (userId , e .getMessage ());
187200 return new ResponseResult (ErrorCode .FAIL_TO_FIND_EMOTION_RECORD , e .getMessage ());
188201 } catch (DataAccessException e ) {
202+ slackService .sendMsg (userId , e .getMessage ());
189203 return new ResponseResult (ErrorCode .DB_ERROR , e .getMessage ());
190204 } catch (Exception e ) {
205+ slackService .sendMsg (userId , e .getMessage ());
191206 return new ResponseResult (ErrorCode .INTERNAL_SERVER_ERROR , e .getMessage ());
192207 }
193208 }
@@ -202,10 +217,13 @@ public ResponseResult getVideoIdBySpotifyId(String spotifyId) {
202217 String videoId = music .getVideoId ();
203218 return new ResponseResult (ErrorCode .SUCCESS , videoId );
204219 } catch (SpotifyMusicNotFoundException e ) {
220+ slackService .sendMsg (spotifyId , e .getMessage ());
205221 return new ResponseResult (ErrorCode .FAIL_TO_FIND_SPOTIFY_MUSIC , e .getMessage ());
206222 } catch (DataAccessException e ) {
223+ slackService .sendMsg (spotifyId , e .getMessage ());
207224 return new ResponseResult (ErrorCode .DB_ERROR , e .getMessage ());
208225 } catch (Exception e ) {
226+ slackService .sendMsg (spotifyId , e .getMessage ());
209227 return new ResponseResult (ErrorCode .INTERNAL_SERVER_ERROR , e .getMessage ());
210228 }
211229 }
@@ -250,10 +268,13 @@ public ResponseResult updateEmotionRecord(Long recordId, EmotionRecordUpdateRequ
250268 );*/
251269 return new ResponseResult (ErrorCode .SUCCESS , responseDTO );
252270 } catch (EmotionRecordNotFoundException e ) {
271+ slackService .sendMsg (recordId , e .getMessage ());
253272 return new ResponseResult (ErrorCode .FAIL_TO_FIND_EMOTION_RECORD , e .getMessage ());
254273 } catch (DataAccessException e ) {
274+ slackService .sendMsg (recordId , e .getMessage ());
255275 return new ResponseResult (ErrorCode .DB_ERROR , e .getMessage ());
256276 } catch (Exception e ) {
277+ slackService .sendMsg (recordId , e .getMessage ());
257278 return new ResponseResult (ErrorCode .INTERNAL_SERVER_ERROR , e .getMessage ());
258279 }
259280 }
@@ -299,10 +320,13 @@ public ResponseResult deleteEmotionRecord(Long recordId) {
299320 }
300321 return new ResponseResult (ErrorCode .SUCCESS , "감정 기록이 성공적으로 삭제되었습니다." );
301322 } catch (EmotionRecordNotFoundException e ) {
323+ slackService .sendMsg (recordId , e .getMessage ());
302324 return new ResponseResult (ErrorCode .FAIL_TO_FIND_EMOTION_RECORD , e .getMessage ());
303325 } catch (DataAccessException e ) {
326+ slackService .sendMsg (recordId , e .getMessage ());
304327 return new ResponseResult (ErrorCode .DB_ERROR , e .getMessage ());
305328 } catch (Exception e ) {
329+ slackService .sendMsg (recordId , e .getMessage ());
306330 return new ResponseResult (ErrorCode .INTERNAL_SERVER_ERROR , e .getMessage ());
307331 }
308332 }
@@ -316,6 +340,7 @@ private ResponseResult validateAndCreatePageable(int page, int size) {
316340 Pageable pageable = PageRequest .of (page - 1 , size , Sort .by ("createdAt" ).descending ());
317341 return new ResponseResult (ErrorCode .SUCCESS , pageable );
318342 } catch (IllegalArgumentException e ) {
343+ slackService .sendMsg (page , e .getMessage ());
319344 return new ResponseResult (ErrorCode .INVALID_PAGE_REQUEST , "페이지 요청 값이 잘못되었습니다." );
320345 }
321346 }
0 commit comments