Skip to content

Commit

Permalink
feat: pageSize validation 추가 (#279)
Browse files Browse the repository at this point in the history
* feat: pageSize validation 추가

* feat: magic number 추출
  • Loading branch information
ChooSeoyeon authored Aug 9, 2024
1 parent a7e76f7 commit 726abc8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion backend/http/offering.http
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
GET {{base-url}}/offerings/1

### 공모 목록 조회 API
GET {{base-url}}/offerings?filter=IMMINENT&page-size=3&last-id=10
GET {{base-url}}/offerings?last-id=10&page-size=10

### 공모 필터 목록 조회 API
GET {{base-url}}/offerings/filters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.springframework.web.bind.MissingServletRequestParameterException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.method.annotation.HandlerMethodValidationException;

@Slf4j
@RestControllerAdvice
Expand All @@ -29,7 +30,17 @@ public ResponseEntity<ErrorMessage> handle(MarketException e) {

@ExceptionHandler
public ResponseEntity<ErrorMessage> handle(MethodArgumentNotValidException e) {
ErrorMessage errorMessage = new ErrorMessage(e.getAllErrors().get(0).getDefaultMessage());
ErrorMessage errorMessage = new ErrorMessage(
"요청값이 유효하지 않습니다: [%s]".formatted(e.getAllErrors().get(0).getDefaultMessage()));
return ResponseEntity
.badRequest()
.body(errorMessage);
}

@ExceptionHandler
public ResponseEntity<ErrorMessage> handle(HandlerMethodValidationException e) {
ErrorMessage errorMessage = new ErrorMessage(
"요청값이 유효하지 않습니다: [%s]".formatted(e.getAllErrors().get(0).getDefaultMessage()));
return ResponseEntity
.badRequest()
.body(errorMessage);
Expand All @@ -44,6 +55,7 @@ public ResponseEntity<ErrorMessage> handle(MissingServletRequestParameterExcepti
.body(errorMessage);
}


@ExceptionHandler
public ResponseEntity<ErrorMessage> handle(Exception e, HttpServletRequest request, HttpServletResponse response)
throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import com.zzang.chongdae.offering.service.dto.OfferingSaveRequest;
import com.zzang.chongdae.offering.service.dto.OfferingStatusResponse;
import jakarta.validation.Valid;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import java.net.URI;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
Expand All @@ -29,6 +31,9 @@
@RestController
public class OfferingController {

private static final int MIN_PAGE_SIZE = 1;
private static final int MAX_PAGE_SIZE = 60;

private final OfferingService offeringService;

@GetMapping("/offerings/{offering-id}")
Expand All @@ -44,7 +49,8 @@ public ResponseEntity<OfferingAllResponse> getAllOffering(
@RequestParam(value = "filter", defaultValue = "RECENT") String filterName,
@RequestParam(value = "search", required = false) String searchKeyword,
@RequestParam(value = "last-id", required = false) Long lastId,
@RequestParam(value = "page-size", defaultValue = "10") Integer pageSize) {
@RequestParam(value = "page-size", defaultValue = "10") @Min(MIN_PAGE_SIZE) @Max(MAX_PAGE_SIZE)
Integer pageSize) {
OfferingAllResponse response = offeringService.getAllOffering(filterName, searchKeyword, lastId, pageSize);
return ResponseEntity.ok(response);
}
Expand Down

0 comments on commit 726abc8

Please sign in to comment.