-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
71 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/java/com/elice/ustory/global/Validation/PageableValidation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.elice.ustory.global.Validation; | ||
|
||
import com.elice.ustory.global.exception.model.ValidationException; | ||
import org.springframework.data.domain.PageRequest; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class PageableValidation { | ||
|
||
private static final String AT_LEAST_PAGE = "페이지는 1 이상이어야 합니다."; | ||
private static final String AT_LEAST_SIZE = "사이즈는 1 이상이어야 합니다."; | ||
|
||
|
||
/** | ||
* | ||
* @param page | ||
* @param size | ||
* 페이지네이션에서 페이지와 사이즈가 1 이상이여야 함을 검증하는 메서드 | ||
* Pageable 까지 만들어서 넘기는 버전, 그냥 검증한 하는 버전 두 가지 버전의 메서드를 구현 | ||
* 하나로 만들면 좋았겠다. 하지만 서비스단까지 바꿔야 하는 관계로 패스 | ||
*/ | ||
public void pageValidate(int page, int size) { | ||
if (page < 1) { | ||
throw new ValidationException(AT_LEAST_PAGE); | ||
} else if (size < 1) { | ||
throw new ValidationException(AT_LEAST_SIZE); | ||
} | ||
} | ||
|
||
public Pageable madePageable(int page, int size) { | ||
|
||
if (page < 1) { | ||
throw new ValidationException(AT_LEAST_PAGE); | ||
} else if (size < 1) { | ||
throw new ValidationException(AT_LEAST_SIZE); | ||
} | ||
|
||
return PageRequest.of(page - 1, size); | ||
} | ||
|
||
} | ||
|