From 8b9877090f01e2e525e80af8c3ae149df0756c23 Mon Sep 17 00:00:00 2001 From: seohyun-lee Date: Sat, 10 Aug 2024 03:54:47 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=EA=B2=80=EC=83=89=20=EC=8B=9C=20?= =?UTF-8?q?=EB=94=94=EC=BD=94=EB=94=A9=20=EC=BD=94=EB=93=9C=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/controller/MemberController.java | 8 ++++++-- .../member/controller/MyPageController.java | 8 ++++++-- .../domain/place/controller/PlaceController.java | 8 ++++++-- .../playlist/controller/PlaylistController.java | 8 ++++++-- .../domain/song/controller/SongController.java | 7 +++++-- .../global/exception/GlobalExceptionHandler.java | 16 +++++++++++++++- 6 files changed, 44 insertions(+), 11 deletions(-) diff --git a/src/main/java/sws/songpin/domain/member/controller/MemberController.java b/src/main/java/sws/songpin/domain/member/controller/MemberController.java index cf347fa8..93c07cef 100644 --- a/src/main/java/sws/songpin/domain/member/controller/MemberController.java +++ b/src/main/java/sws/songpin/domain/member/controller/MemberController.java @@ -17,6 +17,9 @@ import sws.songpin.domain.playlist.service.PlaylistService; import sws.songpin.domain.member.service.ProfileService; +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; + @Tag(name = "Member", description = "Member 관련 API입니다.") @RestController @RequiredArgsConstructor @@ -31,8 +34,9 @@ public class MemberController { @Operation(summary = "유저 검색", description = "유저를 검색합니다.") @GetMapping public ResponseEntity searchMembers(@RequestParam("keyword") final String keyword, - @PageableDefault(size = 20) final Pageable pageable) { - return ResponseEntity.ok().body(memberService.searchMembers(keyword, pageable)); + @PageableDefault(size = 20) final Pageable pageable) throws UnsupportedEncodingException { + String decodedKeyword = URLDecoder.decode(keyword, "UTF-8"); + return ResponseEntity.ok().body(memberService.searchMembers(decodedKeyword, pageable)); } @Operation(summary = "타 유저 정보 조회", description = "memberId으로 해당 유저의 프로필 이미지, 닉네임, 아이디 정보 조회") @GetMapping("/{memberId}") diff --git a/src/main/java/sws/songpin/domain/member/controller/MyPageController.java b/src/main/java/sws/songpin/domain/member/controller/MyPageController.java index 554c6c2a..7df974b7 100644 --- a/src/main/java/sws/songpin/domain/member/controller/MyPageController.java +++ b/src/main/java/sws/songpin/domain/member/controller/MyPageController.java @@ -19,6 +19,9 @@ import sws.songpin.domain.playlist.service.PlaylistService; import sws.songpin.global.auth.CookieUtil; +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; + @Tag(name = "MyPage", description = "MyPage 관련 API입니다.") @RestController @RequiredArgsConstructor @@ -70,8 +73,9 @@ public ResponseEntity getMyFeedPinsByMonth(@RequestParam("year") int year, @R @Operation(summary = "마이페이지에서 핀 검색", description = "마이페이지에서의 핀 검색 결과를 페이징으로 불러옵니다.") @GetMapping("/pins") public ResponseEntity songSearch(@RequestParam("keyword") final String keyword, - @PageableDefault(size = 20) final Pageable pageable){ - return ResponseEntity.ok().body(pinService.searchMyPins(keyword, pageable)); + @PageableDefault(size = 20) final Pageable pageable) throws UnsupportedEncodingException { + String decodedKeyword = URLDecoder.decode(keyword, "UTF-8"); + return ResponseEntity.ok().body(pinService.searchMyPins(decodedKeyword, pageable)); } @Operation(summary = "회원 탈퇴", description = "회원 상태를 '탈퇴'로 변경하고 닉네임을 '(알 수 없음)'으로 변경합니다. \t\n해당 회원의 handle을 랜덤 uuid 값으로 변경합니다. \t\nRedis와 쿠키에 저장되었던 회원의 Refresh Token을 삭제합니다. \t\n해당 회원이 등록했던 핀 등의 데이터는 남겨둡니다. \t\n해당 회원의 팔로우, 팔로잉 데이터는 삭제합니다.") diff --git a/src/main/java/sws/songpin/domain/place/controller/PlaceController.java b/src/main/java/sws/songpin/domain/place/controller/PlaceController.java index b2fba6be..4bfdc7bf 100644 --- a/src/main/java/sws/songpin/domain/place/controller/PlaceController.java +++ b/src/main/java/sws/songpin/domain/place/controller/PlaceController.java @@ -10,6 +10,9 @@ import sws.songpin.domain.model.SortBy; import sws.songpin.domain.place.service.PlaceService; +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; + @Tag(name = "Place", description = "Place 관련 API입니다.") @RestController @RequestMapping("/places") @@ -27,7 +30,8 @@ public ResponseEntity placeDetails(@PathVariable final Long placeId) { @GetMapping public ResponseEntity placeSearch(@RequestParam final String keyword, @RequestParam(defaultValue = "ACCURACY") final String sortBy, - @PageableDefault(size = 20) final Pageable pageable) { - return ResponseEntity.ok().body(placeService.searchPlaces(keyword, SortBy.from(sortBy), pageable)); + @PageableDefault(size = 20) final Pageable pageable) throws UnsupportedEncodingException { + String decodedKeyword = URLDecoder.decode(keyword, "UTF-8"); + return ResponseEntity.ok().body(placeService.searchPlaces(decodedKeyword, SortBy.from(sortBy), pageable)); } } diff --git a/src/main/java/sws/songpin/domain/playlist/controller/PlaylistController.java b/src/main/java/sws/songpin/domain/playlist/controller/PlaylistController.java index 1d997a8c..1c649246 100644 --- a/src/main/java/sws/songpin/domain/playlist/controller/PlaylistController.java +++ b/src/main/java/sws/songpin/domain/playlist/controller/PlaylistController.java @@ -16,6 +16,9 @@ import sws.songpin.domain.playlist.service.PlaylistService; import sws.songpin.domain.playlistpin.service.PlaylistPinService; +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; + @Tag(name = "Playlist", description = "Playlist 관련 API입니다.") @RestController @RequiredArgsConstructor @@ -68,8 +71,9 @@ public ResponseEntity getPlaylistMain() { @GetMapping public ResponseEntity playlistSearch(@RequestParam final String keyword, @RequestParam(defaultValue = "ACCURACY") final String sortBy, - @PageableDefault(size = 20) final Pageable pageable) { - return ResponseEntity.ok().body(playlistService.searchPlaylists(keyword, SortBy.from(sortBy), pageable)); + @PageableDefault(size = 20) final Pageable pageable) throws UnsupportedEncodingException { + String decodedKeyword = URLDecoder.decode(keyword, "UTF-8"); + return ResponseEntity.ok().body(playlistService.searchPlaylists(decodedKeyword, SortBy.from(sortBy), pageable)); } diff --git a/src/main/java/sws/songpin/domain/song/controller/SongController.java b/src/main/java/sws/songpin/domain/song/controller/SongController.java index ec5d4565..9350c67e 100644 --- a/src/main/java/sws/songpin/domain/song/controller/SongController.java +++ b/src/main/java/sws/songpin/domain/song/controller/SongController.java @@ -13,6 +13,8 @@ import sws.songpin.domain.song.dto.response.SongDetailsResponseDto; import sws.songpin.domain.song.service.SongService; +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; import java.util.List; @Tag(name = "Song", description = "Song 관련 API입니다.") @@ -48,7 +50,8 @@ public ResponseEntity getMyPinsForSong(@PathVariable("songId") final Long son @Operation(summary = "노래 검색", description = "노래 검색 결과를 선택한 정렬 기준에 따라 페이징으로 불러옵니다.") public ResponseEntity songSearch(@RequestParam("keyword") final String keyword, @RequestParam(value = "sortBy", defaultValue = "ACCURACY") final String sortBy, - @PageableDefault(size = 20) final Pageable pageable){ - return ResponseEntity.ok().body(songService.searchSongs(keyword, SortBy.from(sortBy), pageable)); + @PageableDefault(size = 20) final Pageable pageable) throws UnsupportedEncodingException { + String decodedKeyword = URLDecoder.decode(keyword, "UTF-8"); + return ResponseEntity.ok().body(songService.searchSongs(decodedKeyword, SortBy.from(sortBy), pageable)); } } diff --git a/src/main/java/sws/songpin/global/exception/GlobalExceptionHandler.java b/src/main/java/sws/songpin/global/exception/GlobalExceptionHandler.java index cc3921a5..421b81c4 100644 --- a/src/main/java/sws/songpin/global/exception/GlobalExceptionHandler.java +++ b/src/main/java/sws/songpin/global/exception/GlobalExceptionHandler.java @@ -1,6 +1,7 @@ package sws.songpin.global.exception; import jakarta.servlet.http.HttpServletRequest; +import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatusCode; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.MethodArgumentNotValidException; @@ -8,6 +9,7 @@ import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; +import java.io.UnsupportedEncodingException; import java.time.LocalDateTime; @RestControllerAdvice @@ -59,5 +61,17 @@ protected ResponseEntity handleMissingRequestParamException(MissingSer ); return new ResponseEntity<>(errorDto, HttpStatusCode.valueOf(errorCode.getStatus())); } - + + // 인코딩 에러 + @ExceptionHandler({UnsupportedEncodingException.class}) + protected ResponseEntity handleUnsupportedEncodingException(UnsupportedEncodingException e, HttpServletRequest request) { + ErrorDto errorDto = new ErrorDto( + LocalDateTime.now().toString(), + HttpStatus.BAD_REQUEST.value(), + "UNSUPPORTED_ENCODING", + "The requested encoding is not supported.", + request.getRequestURI() + ); + return new ResponseEntity<>(errorDto, HttpStatus.BAD_REQUEST); + } } \ No newline at end of file From 71b7ac5808f00cacde48610d308a8bf52a3ced0b Mon Sep 17 00:00:00 2001 From: seohyun-lee Date: Sat, 10 Aug 2024 03:57:44 +0900 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20=EA=B2=80=EC=83=89=20=EC=8B=9C=20?= =?UTF-8?q?=EB=94=94=EC=BD=94=EB=94=A9=20=EC=BD=94=EB=93=9C=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sws/songpin/domain/song/spotify/SpotifyController.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/sws/songpin/domain/song/spotify/SpotifyController.java b/src/main/java/sws/songpin/domain/song/spotify/SpotifyController.java index 2766a1d8..f5f6a9e4 100644 --- a/src/main/java/sws/songpin/domain/song/spotify/SpotifyController.java +++ b/src/main/java/sws/songpin/domain/song/spotify/SpotifyController.java @@ -7,6 +7,8 @@ import sws.songpin.domain.song.dto.response.SpotifySearchDto; import sws.songpin.domain.song.service.SongService; +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; import java.util.List; @RestController @@ -18,7 +20,8 @@ public class SpotifyController { @GetMapping("/external/songs") public List searchTracks( @RequestParam("keyword") String keyword, - @RequestParam(value = "offset", defaultValue = "0") int offset) { - return songService.searchTracks(keyword, offset); + @RequestParam(value = "offset", defaultValue = "0") int offset) throws UnsupportedEncodingException { + String decodedKeyword = URLDecoder.decode(keyword, "UTF-8"); + return songService.searchTracks(decodedKeyword, offset); } }