From 877dd3092bb872e26e3fbae820fe38dcf58acfb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=ED=95=98=EC=84=B1?= Date: Wed, 22 Nov 2023 01:35:50 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9A=99=EF=B8=8F=20::=20(#hotfix)=20filter=20?= =?UTF-8?q?bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../retum/jobis/common/util/NumberUtil.java | 2 ++ .../retum/jobis/common/util/StringUtil.java | 2 +- .../presentation/RecruitmentWebAdapter.java | 28 +++++++++++-------- .../error/exception/GlobalErrorCode.java | 4 ++- .../global/exception/BadRequestException.java | 13 +++++++++ 5 files changed, 35 insertions(+), 14 deletions(-) create mode 100644 jobis-infrastructure/src/main/java/team/retum/jobis/global/exception/BadRequestException.java diff --git a/jobis-application/src/main/java/team/retum/jobis/common/util/NumberUtil.java b/jobis-application/src/main/java/team/retum/jobis/common/util/NumberUtil.java index f69bfcacc..deaa2bb31 100644 --- a/jobis-application/src/main/java/team/retum/jobis/common/util/NumberUtil.java +++ b/jobis-application/src/main/java/team/retum/jobis/common/util/NumberUtil.java @@ -3,6 +3,8 @@ import lombok.AccessLevel; import lombok.NoArgsConstructor; +import java.util.List; + @NoArgsConstructor(access = AccessLevel.PRIVATE) public class NumberUtil { diff --git a/jobis-application/src/main/java/team/retum/jobis/common/util/StringUtil.java b/jobis-application/src/main/java/team/retum/jobis/common/util/StringUtil.java index ea98ef78e..f9a679be2 100644 --- a/jobis-application/src/main/java/team/retum/jobis/common/util/StringUtil.java +++ b/jobis-application/src/main/java/team/retum/jobis/common/util/StringUtil.java @@ -16,7 +16,7 @@ public static String joinStringList(List request, String key) { } public static List divideString(String content, String key) { - if (content == null || content.isEmpty() || content.length() == 2) { + if (content == null || content.isEmpty()) { return List.of(); } diff --git a/jobis-infrastructure/src/main/java/team/retum/jobis/domain/recruitment/presentation/RecruitmentWebAdapter.java b/jobis-infrastructure/src/main/java/team/retum/jobis/domain/recruitment/presentation/RecruitmentWebAdapter.java index 729363d94..c1a8652b9 100644 --- a/jobis-infrastructure/src/main/java/team/retum/jobis/domain/recruitment/presentation/RecruitmentWebAdapter.java +++ b/jobis-infrastructure/src/main/java/team/retum/jobis/domain/recruitment/presentation/RecruitmentWebAdapter.java @@ -36,6 +36,7 @@ import team.retum.jobis.domain.recruitment.usecase.TeacherQueryRecruitmentsUseCase; import team.retum.jobis.domain.recruitment.usecase.UpdateRecruitAreaUseCase; import team.retum.jobis.domain.recruitment.usecase.UpdateRecruitmentUseCase; +import team.retum.jobis.global.exception.BadRequestException; import javax.validation.Valid; import javax.validation.constraints.Positive; @@ -102,15 +103,10 @@ public StudentQueryRecruitmentsResponse studentQueryRecruitments( @RequestParam(value = "job_code", required = false) String jobCode, @RequestParam(value = "winter_intern", required = false) Boolean winterIntern ) { - List codes = new ArrayList<>(StringUtil.divideString(techCodes, ",")); - if (jobCode.length() == 2) codes.add(jobCode); - return studentQueryRecruitmentsUseCase.execute( companyName, page - 1, - codes.stream() - .map(Long::parseLong) - .toList(), + this.parseCodes(jobCode, techCodes), winterIntern ); } @@ -122,14 +118,9 @@ public TotalPageCountResponse studentQueryRecruitmentCount( @RequestParam(value = "job_code", required = false) String jobCode, @RequestParam(value = "winter_intern", required = false) Boolean winterIntern ) { - List codes = new ArrayList<>(StringUtil.divideString(techCodes, ",")); - if (jobCode.length() == 2) codes.add(jobCode); - return studentQueryRecruitmentsUseCase.getTotalPageCount( companyName, - codes.stream() - .map(Long::parseLong) - .toList(), + this.parseCodes(jobCode, techCodes), winterIntern ); } @@ -189,4 +180,17 @@ public void deleteRecruitment(@PathVariable("recruitment-id") Long recruitmentId public void deleteRecruitArea(@PathVariable("recruit-area-id") Long recruitAreaId) { deleteRecruitAreaUseCase.execute(recruitAreaId); } + + private List parseCodes(String jobCode, String techCodes) { + List codes = new ArrayList<>(StringUtil.divideString(techCodes, ",")); + if (jobCode != null) codes.add(jobCode); + + try { + return codes.stream() + .map(Long::parseLong) + .toList(); + } catch (Exception e) { + throw new BadRequestException(); + } + } } diff --git a/jobis-infrastructure/src/main/java/team/retum/jobis/global/error/exception/GlobalErrorCode.java b/jobis-infrastructure/src/main/java/team/retum/jobis/global/error/exception/GlobalErrorCode.java index 29bfeebc9..01c6fb17d 100644 --- a/jobis-infrastructure/src/main/java/team/retum/jobis/global/error/exception/GlobalErrorCode.java +++ b/jobis-infrastructure/src/main/java/team/retum/jobis/global/error/exception/GlobalErrorCode.java @@ -15,7 +15,9 @@ public enum GlobalErrorCode implements ErrorProperty { EXPIRED_TOKEN(HttpStatus.UNAUTHORIZED, "Token Expired"), INVALID_TOKEN(HttpStatus.UNAUTHORIZED, "Invalid Token"), - MAIL_SEND_FAIL(HttpStatus.NOT_FOUND, "Mail Send Fail"); + MAIL_SEND_FAIL(HttpStatus.NOT_FOUND, "Mail Send Fail"), + + BAD_REQUEST(HttpStatus.BAD_REQUEST, "Bad Request"); private final HttpStatus status; private final String message; diff --git a/jobis-infrastructure/src/main/java/team/retum/jobis/global/exception/BadRequestException.java b/jobis-infrastructure/src/main/java/team/retum/jobis/global/exception/BadRequestException.java new file mode 100644 index 000000000..2942ae561 --- /dev/null +++ b/jobis-infrastructure/src/main/java/team/retum/jobis/global/exception/BadRequestException.java @@ -0,0 +1,13 @@ +package team.retum.jobis.global.exception; + +import team.retum.jobis.common.error.JobisException; +import team.retum.jobis.global.error.exception.GlobalErrorCode; + +public class BadRequestException extends JobisException { + + public static final JobisException EXCEPTION = new BadRequestException(); + + public BadRequestException() { + super(GlobalErrorCode.BAD_REQUEST); + } +}