Skip to content

Commit

Permalink
FIX(api) : Parameter Decoding 로직 수정 및 Controller Method 보완
Browse files Browse the repository at this point in the history
- Controller Method Mapping Annotation 추가했습니다. (`@GetMapping("")`)
- Parameter에 key 이름을 명시했습니다.
  - 변수명과 달라 jackson 매핑 실패됩니다.
- 기존 Encoding 되고 있었던 잘못된 코드를 Decoding으로 변경했습니다.
  • Loading branch information
yummygyudon committed Jul 2, 2024
1 parent 66295c9 commit eef9988
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.net.URLDecoder;
import java.security.Principal;
import java.util.Arrays;
import java.util.List;
import java.net.URLEncoder;
import java.io.UnsupportedEncodingException;

import static org.sopt.makers.operation.code.success.UserSuccessCode.SUCCESS_GET_USER;
Expand Down Expand Up @@ -48,9 +49,10 @@ public ResponseEntity<BaseResponse<?>> getUserInfoSelf(
}

@Override
@GetMapping("")
public ResponseEntity<BaseResponse<?>> getUserInfoOf(
@NonNull Principal principal,
@NonNull String targetUserIds
@NonNull @RequestParam("userIds") String targetUserIds
) {
val userIds = getIdsFromParameter(targetUserIds);
val response = userService.getUserInfos(userIds);
Expand All @@ -59,8 +61,9 @@ public ResponseEntity<BaseResponse<?>> getUserInfoOf(

private List<Long> getIdsFromParameter(@NonNull String parameter) {
try {
String encodedParameter = URLEncoder.encode(parameter, DECODING_CHARSET);
return Arrays.stream(encodedParameter.split(DELIMITER_ID_PARAMETER))
String decodedParameter = URLDecoder.decode(parameter, DECODING_CHARSET);
return Arrays.stream(decodedParameter.split(DELIMITER_ID_PARAMETER))
.filter(str -> !str.equals(DELIMITER_ID_PARAMETER))
.map(id -> Long.parseLong(id.trim()))
.toList();
} catch (UnsupportedEncodingException ex) {
Expand Down

0 comments on commit eef9988

Please sign in to comment.