Skip to content

Commit

Permalink
Merge pull request #177 from EFUB4-Jukebox/develop
Browse files Browse the repository at this point in the history
[Deploy] 배포 v0.5.11 - feat: 검색 시 디코딩 코드 추가
  • Loading branch information
seohyun-lee authored Aug 9, 2024
2 parents da23e1b + 302a7bd commit 8b37798
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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해당 회원의 팔로우, 팔로잉 데이터는 삭제합니다.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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입니다.")
Expand Down Expand Up @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -18,7 +20,8 @@ public class SpotifyController {
@GetMapping("/external/songs")
public List<SpotifySearchDto> 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);
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
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;
import org.springframework.web.bind.MissingServletRequestParameterException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.io.UnsupportedEncodingException;
import java.time.LocalDateTime;

@RestControllerAdvice
Expand Down Expand Up @@ -59,5 +61,17 @@ protected ResponseEntity<ErrorDto> handleMissingRequestParamException(MissingSer
);
return new ResponseEntity<>(errorDto, HttpStatusCode.valueOf(errorCode.getStatus()));
}


// 인코딩 에러
@ExceptionHandler({UnsupportedEncodingException.class})
protected ResponseEntity<ErrorDto> 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);
}
}

0 comments on commit 8b37798

Please sign in to comment.