From 7b972ed4c12c3454d6dfa5c6da22e985fbb6137a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98jminkkk=E2=80=99?= <102847513+jminkkk@users.noreply.github.com> Date: Mon, 6 Nov 2023 17:39:08 +0900 Subject: [PATCH 01/12] =?UTF-8?q?docs:=20=EB=B3=B4=ED=98=B8=EC=86=8C=20API?= =?UTF-8?q?=20=EC=8A=A4=EC=9B=A8=EA=B1=B0=20=EC=98=88=EC=99=B8=20=EC=9D=91?= =?UTF-8?q?=EB=8B=B5=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shelter/controller/ShelterControllerApi.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/animory/src/main/java/com/daggle/animory/domain/shelter/controller/ShelterControllerApi.java b/animory/src/main/java/com/daggle/animory/domain/shelter/controller/ShelterControllerApi.java index 42d6112d..5782a7a1 100644 --- a/animory/src/main/java/com/daggle/animory/domain/shelter/controller/ShelterControllerApi.java +++ b/animory/src/main/java/com/daggle/animory/domain/shelter/controller/ShelterControllerApi.java @@ -45,6 +45,10 @@ public interface ShelterControllerApi { ) } ) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "보호소 프로필 조회 성공", content = @Content), + @ApiResponse(responseCode = "404", description = "해당하는 보호소가 존재하지 않을 경우") + }) @GetMapping("/{shelterId}") Response getShelter(@PathVariable @Min(0) Integer shelterId, @@ -77,6 +81,11 @@ Response getShelter(@PathVariable @Min(0) Integer shelterId, ) ) ) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "보호소 정보 수정 성공", content = @Content), + @ApiResponse(responseCode = "403", description = "내 보호소가 아닌 다른 보호소를 수정하려는 경우 권한 없음으로 예외 발생", content = @Content), + @ApiResponse(responseCode = "404", description = "수정하려는 보호소가 애니모리에 등록되있지 않는 경우"), + }) @PutMapping("/{shelterId}") Response updateShelter(@AuthenticationPrincipal UserDetailsImpl userDetails, @PathVariable @Min(0) Integer shelterId, @@ -95,10 +104,6 @@ Response updateShelter(@AuthenticationPrincipal UserDet ) ) ) - @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "회원가입 성공"), - @ApiResponse(responseCode = "403", description = "내 보호소가 아닌 다른 보호소를 수정하려는 경우 권한이 없다.", content = @Content) - }) @PostMapping("/filter") Response> filterExistShelterListByLocationId(@RequestBody List shelterLocationIdList); } From 1047f5a29359101c8494433a7f46cc56a1609aa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98jminkkk=E2=80=99?= <102847513+jminkkk@users.noreply.github.com> Date: Mon, 6 Nov 2023 18:32:09 +0900 Subject: [PATCH 02/12] =?UTF-8?q?docs:=20=EA=B3=84=EC=A0=95=20API=20?= =?UTF-8?q?=EC=8A=A4=EC=9B=A8=EA=B1=B0=20=EC=98=88=EC=99=B8=20=EC=9D=91?= =?UTF-8?q?=EB=8B=B5=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/account/controller/AccountControllerApi.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/animory/src/main/java/com/daggle/animory/domain/account/controller/AccountControllerApi.java b/animory/src/main/java/com/daggle/animory/domain/account/controller/AccountControllerApi.java index 7123cbb4..d270c4da 100644 --- a/animory/src/main/java/com/daggle/animory/domain/account/controller/AccountControllerApi.java +++ b/animory/src/main/java/com/daggle/animory/domain/account/controller/AccountControllerApi.java @@ -34,8 +34,7 @@ public interface AccountControllerApi { @ApiResponse(responseCode = "400", description = """ - ID 또는 Password 불일치로 인한 로그인 실패 - Email 형식 오류, 비밀번호가 null - """, content = @Content), - @ApiResponse(responseCode = "404", description = "해당하는 보호소를 찾을 수 없는 경우", content = @Content) + """, content = @Content) }) ResponseEntity> login(@Valid @RequestBody AccountLoginDto request); From fa08792f9f4c04b867db8da5643437fae40cee55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98jminkkk=E2=80=99?= <102847513+jminkkk@users.noreply.github.com> Date: Mon, 6 Nov 2023 19:44:42 +0900 Subject: [PATCH 03/12] =?UTF-8?q?docs:=20=EC=88=8F=ED=8F=BC=20API=20?= =?UTF-8?q?=EC=8A=A4=EC=9B=A8=EA=B1=B0=20=EC=98=88=EC=99=B8=20=EC=9D=91?= =?UTF-8?q?=EB=8B=B5=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ShortFormControllerApi.java | 47 ++++++++++++++++--- 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/animory/src/main/java/com/daggle/animory/domain/shortform/controller/ShortFormControllerApi.java b/animory/src/main/java/com/daggle/animory/domain/shortform/controller/ShortFormControllerApi.java index 259ab522..8a68e7da 100644 --- a/animory/src/main/java/com/daggle/animory/domain/shortform/controller/ShortFormControllerApi.java +++ b/animory/src/main/java/com/daggle/animory/domain/shortform/controller/ShortFormControllerApi.java @@ -9,7 +9,10 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.enums.ParameterIn; +import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.data.domain.Pageable; import org.springframework.data.web.PageableDefault; @@ -18,12 +21,9 @@ import javax.servlet.http.HttpServletRequest; import javax.validation.Valid; -@Tag( - name = "숏폼 비디오 API", - description = """ - 최종수정시각: 2023-10-22 23:24 - """ -) +@Tag(name = "숏폼 API", description = """ + 최종수정일: 2023-11-06 + """) public interface ShortFormControllerApi { @Operation(summary = "조건부 숏폼 비디오 탐색", @@ -84,10 +84,43 @@ Response getShortForms(@Parameter(hidden = true) @GetMapping("/short-forms/home") Response getHomeShortForms(@Parameter(hidden = true) @PageableDefault Pageable pageable); + @Operation(summary = "숏폼 좋아요 등록", + description = "특정 숏폼에 좋아요를 등록합니다.", + parameters = { + @Parameter( + in = ParameterIn.HEADER, + name = "X-Forwarded-For", + description = "클라이언트 IP", + required = true, + schema = @Schema(type = "string", defaultValue = "") + ) + } + ) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "좋아요 삭제 성공"), + @ApiResponse(responseCode = "400", description = "헤당하는 Ip로 숏폼에 좋아요가 이미 등록되있는 경우", content = @Content), + @ApiResponse(responseCode = "404", description = "해당하는 숏폼이 존재하지 않을 경우", content = @Content) + }) @PostMapping("/like/{petVideoId}") Response increasePetLikeCount(final HttpServletRequest httpServletRequest, @PathVariable final int petVideoId); - + @Operation(summary = "숏폼 좋아요 삭제", + description = "특정 숏폼에 좋아요를 삭제합니다.", + parameters = { + @Parameter( + in = ParameterIn.HEADER, + name = "X-Forwarded-For", + description = "클라이언트 IP", + required = true, + schema = @Schema(type = "string", defaultValue = "") + ) + } + ) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "좋아요 삭제 성공"), + @ApiResponse(responseCode = "400", description = "헤당하는 Ip로 숏폼에 좋아요가 등록되있지 않은 경우", content = @Content), + @ApiResponse(responseCode = "404", description = "해당하는 숏폼이 존재하지 않을 경우", content = @Content) + }) @DeleteMapping("/like/{petVideoId}") Response deletePetLikeCount(final HttpServletRequest httpServletRequest, @PathVariable final int petVideoId); } From 3490a0066c702ce2fffbf21696ba7483663bab33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98jminkkk=E2=80=99?= <102847513+jminkkk@users.noreply.github.com> Date: Mon, 6 Nov 2023 19:46:08 +0900 Subject: [PATCH 04/12] =?UTF-8?q?docs:=20=EC=B5=9C=EC=A2=85=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=EC=9D=BC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../account/controller/AccountControllerApi.java | 6 ++++-- .../shelter/controller/ShelterControllerApi.java | 10 +++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/animory/src/main/java/com/daggle/animory/domain/account/controller/AccountControllerApi.java b/animory/src/main/java/com/daggle/animory/domain/account/controller/AccountControllerApi.java index d270c4da..a2a72c8e 100644 --- a/animory/src/main/java/com/daggle/animory/domain/account/controller/AccountControllerApi.java +++ b/animory/src/main/java/com/daggle/animory/domain/account/controller/AccountControllerApi.java @@ -15,7 +15,9 @@ import javax.validation.Valid; -@Tag(name = "계정 API", description = "계정 관련 API 입니다.") +@Tag(name = "계정 API", description = """ + 최종수정일: 2023-11-06 + """) public interface AccountControllerApi { @Operation(summary = "보호소 계정으로 회원가입 API", description = "보호소 계정으로 회원가입합니다.") @@ -41,7 +43,7 @@ public interface AccountControllerApi { @Operation(summary = "이메일 중복 검증 API", description = "회원가입에 사용할 이메일이 중복되는지 검사합니다.") @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "이메일 중복 검증 성공"), - @ApiResponse(responseCode = "400", description = "이미 존재하는 이메일인 경우"), + @ApiResponse(responseCode = "400", description = "이미 존재하는 이메일인 경우", content = @Content), }) Response validateEmail(@Valid @RequestBody EmailValidateDto emailValidateDto); } diff --git a/animory/src/main/java/com/daggle/animory/domain/shelter/controller/ShelterControllerApi.java b/animory/src/main/java/com/daggle/animory/domain/shelter/controller/ShelterControllerApi.java index 5782a7a1..86fc53dc 100644 --- a/animory/src/main/java/com/daggle/animory/domain/shelter/controller/ShelterControllerApi.java +++ b/animory/src/main/java/com/daggle/animory/domain/shelter/controller/ShelterControllerApi.java @@ -23,7 +23,7 @@ import java.util.List; @Tag(name = "보호소 API", description = """ - 최종수정시각: 2023-10-22 23:44 + 최종수정일: 2023-11-06 """) public interface ShelterControllerApi { @@ -46,8 +46,8 @@ public interface ShelterControllerApi { } ) @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "보호소 프로필 조회 성공", content = @Content), - @ApiResponse(responseCode = "404", description = "해당하는 보호소가 존재하지 않을 경우") + @ApiResponse(responseCode = "200", description = "보호소 프로필 조회 성공"), + @ApiResponse(responseCode = "404", description = "해당하는 보호소가 존재하지 않을 경우", content = @Content) }) @GetMapping("/{shelterId}") Response getShelter(@PathVariable @Min(0) Integer shelterId, @@ -82,9 +82,9 @@ Response getShelter(@PathVariable @Min(0) Integer shelterId, ) ) @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "보호소 정보 수정 성공", content = @Content), + @ApiResponse(responseCode = "200", description = "보호소 정보 수정 성공"), @ApiResponse(responseCode = "403", description = "내 보호소가 아닌 다른 보호소를 수정하려는 경우 권한 없음으로 예외 발생", content = @Content), - @ApiResponse(responseCode = "404", description = "수정하려는 보호소가 애니모리에 등록되있지 않는 경우"), + @ApiResponse(responseCode = "404", description = "수정하려는 보호소가 애니모리에 등록되있지 않는 경우", content = @Content), }) @PutMapping("/{shelterId}") Response updateShelter(@AuthenticationPrincipal UserDetailsImpl userDetails, From 9debff7867bf8c37a8f70b2d61be8a42b0cee2bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98jminkkk=E2=80=99?= <102847513+jminkkk@users.noreply.github.com> Date: Mon, 6 Nov 2023 20:05:14 +0900 Subject: [PATCH 05/12] =?UTF-8?q?docs:=20=ED=8E=AB=20API=20=EC=8A=A4?= =?UTF-8?q?=EC=9B=A8=EA=B1=B0=20=EC=98=88=EC=99=B8=20=EC=9D=91=EB=8B=B5=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pet/controller/PetControllerApi.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/animory/src/main/java/com/daggle/animory/domain/pet/controller/PetControllerApi.java b/animory/src/main/java/com/daggle/animory/domain/pet/controller/PetControllerApi.java index ab87cea6..eae06f0c 100644 --- a/animory/src/main/java/com/daggle/animory/domain/pet/controller/PetControllerApi.java +++ b/animory/src/main/java/com/daggle/animory/domain/pet/controller/PetControllerApi.java @@ -20,9 +20,8 @@ import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.multipart.MultipartFile; -@Tag(name = "Pet", description = """ - Pet 등록, 수정 및 조회 관련 API - 최종수정시각: 2023-10-22 23:56 +@Tag(name = "펫 API", description = """ + 최종수정일: 2023-11-06 """) public interface PetControllerApi { @@ -46,7 +45,7 @@ public interface PetControllerApi { "\t\n 3. 빈 이미지 파일일 경우" + "\t\n 4. 빈 비디오 파일일 경우" + "\t\n 5. 잘못된 나이 형식일 경우", content = @Content), - @ApiResponse(responseCode = "404", description = "보호소를 찾을 수 없는 경우", content = @Content), + @ApiResponse(responseCode = "404", description = "로그인되어 있는 보호소의 권한 체크 중 해당 보호소를 DB에서 찾을 수 없는 경우", content = @Content), @ApiResponse(responseCode = "500", description = "S3 저장 오류", content = @Content) }) Response registerPet( @@ -59,6 +58,8 @@ Response registerPet( @Operation(summary = "Pet 수정 페이지 진입, 기존 펫 정보 확인", description = "Pet 수정 페이지에서, 기존 등록된 정보를 확인하기 위해 호출하는 API 입니다.") @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "기존 펫 정보 조회 성공"), + @ApiResponse(responseCode = "403", description = "수정 권한이 없는 보호소 계정으로 해당 페이지를 조회 시도한 경우", content = @Content), @ApiResponse(responseCode = "404", description = "존재하지 않는 펫인 경우", content = @Content) }) Response getPetRegisterInfo(UserDetailsImpl userDetails, @@ -85,7 +86,8 @@ Response getPetRegisterInfo(UserDetailsImpl userDetails, "\t\n 3. 빈 이미지 파일일 경우" + "\t\n 4. 빈 비디오 파일일 경우" + "\t\n 5. 잘못된 나이 형식일 경우", content = @Content), - @ApiResponse(responseCode = "404", description = "존재하지 않는 펫 오류", content = @Content), + @ApiResponse(responseCode = "403", description = "해당 펫을 수정할 권한이 없는 경세", content = @Content), + @ApiResponse(responseCode = "404", description = "존재하지 않는 펫을 수정하려는 경우", content = @Content), @ApiResponse(responseCode = "500", description = "S3 저장 오류", content = @Content) }) Response updatePet( @@ -149,11 +151,13 @@ Response getPetNewProfiles( @Operation(summary = "Pet 상세 조회", description = "") @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "펫 상세 조회 성공"), @ApiResponse(responseCode = "404", description = "존재하지 않는 펫인 경우", content = @Content) }) Response getPetDetail(@PathVariable int petId); + @Operation(summary = "[로그인 필요: 보호소] Pet 입양 완료 처리", description = "입양 상태가 변경되고, 보호만료날짜가 삭제됩니다.", parameters = { @@ -167,8 +171,10 @@ Response getPetNewProfiles( } ) @ApiResponses(value = { - @ApiResponse(responseCode = "404", description = "1. 존재하지 않는 펫인 경우" + - "\t\n 2. 보호소를 찾을 수 없는 경우", content = @Content) + @ApiResponse(responseCode = "200", description = "펫 입양 처리 성공"), + @ApiResponse(responseCode = "403", description = "해당 펫을 수정할 권한이 없는 경우", content = @Content), + @ApiResponse(responseCode = "404", description = "1. 존재하지 않는 펫인 경우" + + "\t\n 2. 로그인되어 있는 보호소의 권한 체크 중 해당 보호소를 DB에서 찾을 수 없는 경우", content = @Content) }) Response updatePetAdopted(@AuthenticationPrincipal UserDetailsImpl userDetails, @PathVariable int petId); From b93cc65eeb0e815a3647833b740494fa91a98046 Mon Sep 17 00:00:00 2001 From: greennarae Date: Mon, 6 Nov 2023 22:54:14 +0900 Subject: [PATCH 06/12] =?UTF-8?q?feat:=20short=20form=20api=EC=97=90=20nex?= =?UTF-8?q?tpage=EA=B0=92=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/response/CategoryShortFormPage.java | 9 ++++++--- .../dto/response/HomeShortFormPage.java | 9 ++++++--- .../shortform/service/ShortFormService.java | 19 +++++++++++++------ 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/animory/src/main/java/com/daggle/animory/domain/shortform/dto/response/CategoryShortFormPage.java b/animory/src/main/java/com/daggle/animory/domain/shortform/dto/response/CategoryShortFormPage.java index c154ad24..1b6c09cc 100644 --- a/animory/src/main/java/com/daggle/animory/domain/shortform/dto/response/CategoryShortFormPage.java +++ b/animory/src/main/java/com/daggle/animory/domain/shortform/dto/response/CategoryShortFormPage.java @@ -7,16 +7,19 @@ public record CategoryShortFormPage( List shortForms, - boolean hasNext + boolean hasNext, + Integer nextPage ) { public static CategoryShortFormPage of(final List petVideos, - final boolean hasNext) { + final boolean hasNext, + final Integer nextPage) { return new CategoryShortFormPage( petVideos.stream() .map(ShortFormDto::of) .toList(), - hasNext + hasNext, + nextPage ); } } diff --git a/animory/src/main/java/com/daggle/animory/domain/shortform/dto/response/HomeShortFormPage.java b/animory/src/main/java/com/daggle/animory/domain/shortform/dto/response/HomeShortFormPage.java index 2789070c..9587d79b 100644 --- a/animory/src/main/java/com/daggle/animory/domain/shortform/dto/response/HomeShortFormPage.java +++ b/animory/src/main/java/com/daggle/animory/domain/shortform/dto/response/HomeShortFormPage.java @@ -6,16 +6,19 @@ public record HomeShortFormPage( List shortForms, - boolean hasNext + boolean hasNext, + Integer nextPage ) { public static HomeShortFormPage of(final List petVideos, - final boolean hasNext) { + final boolean hasNext, + final Integer nextPage) { return new HomeShortFormPage( petVideos.stream() .map(ShortFormDto::of) .toList(), - hasNext + hasNext, + nextPage ); } } diff --git a/animory/src/main/java/com/daggle/animory/domain/shortform/service/ShortFormService.java b/animory/src/main/java/com/daggle/animory/domain/shortform/service/ShortFormService.java index 86663996..147a52cd 100644 --- a/animory/src/main/java/com/daggle/animory/domain/shortform/service/ShortFormService.java +++ b/animory/src/main/java/com/daggle/animory/domain/shortform/service/ShortFormService.java @@ -28,26 +28,28 @@ public class ShortFormService { public HomeShortFormPage getHomeShortFormPage(final Pageable pageable) { // Fetch Join + Pageable 동시에 수행하는 경우 발생하는 문제(HHH000104) 해결을 위해 쿼리를 두 개로 분할하였습니다. - Slice petVideoIdSlice = petVideoJpaRepository.findPetVideoIdsBy(pageable); - List petVideos = petVideoJpqlRepository.findAllByIds(petVideoIdSlice.getContent()); + final Slice petVideoIdSlice = petVideoJpaRepository.findPetVideoIdsBy(pageable); + final List petVideos = petVideoJpqlRepository.findAllByIds(petVideoIdSlice.getContent()); // LikeCount DESC 순서로 조회하고, 반환된 페이지(Slice)를 랜덤으로 섞는다. return HomeShortFormPage.of( shuffleVideos(petVideos), - petVideoIdSlice.hasNext() + petVideoIdSlice.hasNext(), + getNextPage(petVideoIdSlice.hasNext(), pageable) ); } public CategoryShortFormPage getCategoryShortFormPage(final ShortFormSearchCondition searchCondition, final Pageable pageable) { - Slice petVideoIds = petVideoJpqlRepository + final Slice petVideoIds = petVideoJpqlRepository .findPetVideoIdsBy(searchCondition.type(), searchCondition.area(), pageable); - List petVideos = petVideoJpqlRepository.findAllByIds(petVideoIds.getContent()); + final List petVideos = petVideoJpqlRepository.findAllByIds(petVideoIds.getContent()); return CategoryShortFormPage.of( shuffleVideos(petVideos), - petVideoIds.hasNext() + petVideoIds.hasNext(), + getNextPage(petVideoIds.hasNext(), pageable) ); } @@ -56,4 +58,9 @@ private List shuffleVideos(final List petVideos) { Collections.shuffle(petVideos); return petVideos; } + + private Integer getNextPage(final boolean hasNext, + final Pageable pageable) { + return hasNext ? pageable.getPageNumber() + 1 : null; + } } From 33f9921632307abec401c19b09fcbd6db98f6048 Mon Sep 17 00:00:00 2001 From: greennarae Date: Mon, 6 Nov 2023 23:45:22 +0900 Subject: [PATCH 07/12] fix: nextPage number +2 --- .../animory/domain/shortform/service/ShortFormService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/animory/src/main/java/com/daggle/animory/domain/shortform/service/ShortFormService.java b/animory/src/main/java/com/daggle/animory/domain/shortform/service/ShortFormService.java index 147a52cd..3b9c9c91 100644 --- a/animory/src/main/java/com/daggle/animory/domain/shortform/service/ShortFormService.java +++ b/animory/src/main/java/com/daggle/animory/domain/shortform/service/ShortFormService.java @@ -58,9 +58,9 @@ private List shuffleVideos(final List petVideos) { Collections.shuffle(petVideos); return petVideos; } - + private Integer getNextPage(final boolean hasNext, final Pageable pageable) { - return hasNext ? pageable.getPageNumber() + 1 : null; + return hasNext ? pageable.getPageNumber() + 2 : null; } } From 8355c59d395b8822f7a624830d9a94d5c3a796c3 Mon Sep 17 00:00:00 2001 From: greennarae Date: Tue, 7 Nov 2023 23:20:17 +0900 Subject: [PATCH 08/12] =?UTF-8?q?fix:=20Security=20Exception=20Handling?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EC=9D=91=EB=8B=B5=EC=9D=B4=20=EC=A0=9C?= =?UTF-8?q?=EB=8C=80=EB=A1=9C=20=EB=82=98=EC=98=A4=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../handler/GlobalExceptionHandler.java | 9 +++++++ .../security/JwtAuthenticationFilter.java | 27 ++++++++++--------- .../common/security/SecurityConfig.java | 9 +++---- .../common/security/TokenProvider.java | 24 ++++++++--------- .../exception/JwtExceptionFilter.java | 14 ++++++---- .../exception/UnAuthorizedException.java | 9 +++++++ .../daggle/animory/acceptance/PetTest.java | 4 +-- 7 files changed, 60 insertions(+), 36 deletions(-) create mode 100644 animory/src/main/java/com/daggle/animory/common/security/exception/UnAuthorizedException.java diff --git a/animory/src/main/java/com/daggle/animory/common/exception/handler/GlobalExceptionHandler.java b/animory/src/main/java/com/daggle/animory/common/exception/handler/GlobalExceptionHandler.java index 1e774a85..65dca644 100644 --- a/animory/src/main/java/com/daggle/animory/common/exception/handler/GlobalExceptionHandler.java +++ b/animory/src/main/java/com/daggle/animory/common/exception/handler/GlobalExceptionHandler.java @@ -3,6 +3,7 @@ import com.daggle.animory.common.Response; import com.daggle.animory.common.security.exception.ForbiddenException; +import com.daggle.animory.common.security.exception.UnAuthorizedException; import com.daggle.animory.domain.account.exception.AlreadyExistEmailException; import com.daggle.animory.domain.account.exception.CheckEmailOrPasswordException; import com.daggle.animory.domain.fileserver.exception.*; @@ -107,6 +108,14 @@ public ResponseEntity> handleShelterAlreadyExistException(final E HttpStatus.BAD_REQUEST)); } + // 401 + @ExceptionHandler({UnAuthorizedException.class}) + public ResponseEntity> handleUnAuthorizedException(final Exception e) { + return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(Response.error(e.getMessage(), + HttpStatus.UNAUTHORIZED)); + } + + // 403 @ExceptionHandler({ShelterPermissionDeniedException.class}) public ResponseEntity> handleShelterPermissionDeniedException(final Exception e) { diff --git a/animory/src/main/java/com/daggle/animory/common/security/JwtAuthenticationFilter.java b/animory/src/main/java/com/daggle/animory/common/security/JwtAuthenticationFilter.java index 63db1df4..699b7d77 100644 --- a/animory/src/main/java/com/daggle/animory/common/security/JwtAuthenticationFilter.java +++ b/animory/src/main/java/com/daggle/animory/common/security/JwtAuthenticationFilter.java @@ -22,18 +22,22 @@ public class JwtAuthenticationFilter extends BasicAuthenticationFilter { private static final String AUTHORIZATION_HEADER = "Authorization"; private final TokenProvider tokenProvider; - public JwtAuthenticationFilter(final AuthenticationManager authenticationManager, final TokenProvider tokenProvider) { + public JwtAuthenticationFilter(final AuthenticationManager authenticationManager, + final TokenProvider tokenProvider) { super(authenticationManager); this.tokenProvider = tokenProvider; } // 권한 확인을 수행하는 로직 @Override - protected void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response, final FilterChain chain) throws IOException, ServletException { + protected void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response, + final FilterChain chain) throws IOException, ServletException { + log.debug("JwtAuthenticationFilter 동작"); + final String jwt = request.getHeader(AUTHORIZATION_HEADER); if (jwt == null) { - super.doFilterInternal(request, response, chain); + chain.doFilter(request, response); return; } @@ -44,24 +48,25 @@ protected void doFilterInternal(final HttpServletRequest request, final HttpServ final AccountRole role = tokenProvider.getRoleFromToken(claims); final Account account = Account.builder() - .email(email) - .role(role) - .build(); + .email(email) + .role(role) + .build(); final UserDetailsImpl userDetails = new UserDetailsImpl(account); final Authentication authentication = new UsernamePasswordAuthenticationToken( - userDetails, - userDetails.getPassword(), - userDetails.getAuthorities()); + userDetails, + userDetails.getPassword(), + userDetails.getAuthorities()); SecurityContextHolder.getContext().setAuthentication(authentication); log.debug("디버그 : 인증 객체 만들어짐"); + chain.doFilter(request, response); } catch (SecurityException e) { log.info("Invalid JWT signature."); throw new JwtException("잘못된 JWT 시그니처"); } catch (MalformedJwtException e) { - log.info("Invalid JWT token."); + log.info("Invalid JWT token: {}.", e.getMessage()); throw new JwtException("유효하지 않은 JWT 토큰"); } catch (ExpiredJwtException e) { log.info("Expired JWT token."); @@ -72,8 +77,6 @@ protected void doFilterInternal(final HttpServletRequest request, final HttpServ } catch (IllegalArgumentException e) { log.info("JWT token compact of handler are invalid."); throw new JwtException("JWT token compact of handler are invalid."); - } finally { - super.doFilterInternal(request, response, chain); } } } diff --git a/animory/src/main/java/com/daggle/animory/common/security/SecurityConfig.java b/animory/src/main/java/com/daggle/animory/common/security/SecurityConfig.java index 15ab752d..29185546 100644 --- a/animory/src/main/java/com/daggle/animory/common/security/SecurityConfig.java +++ b/animory/src/main/java/com/daggle/animory/common/security/SecurityConfig.java @@ -2,6 +2,7 @@ import com.daggle.animory.common.security.exception.ForbiddenException; import com.daggle.animory.common.security.exception.JwtExceptionFilter; +import com.daggle.animory.common.security.exception.UnAuthorizedException; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -21,8 +22,6 @@ import org.springframework.web.cors.UrlBasedCorsConfigurationSource; import org.springframework.web.servlet.HandlerExceptionResolver; -import javax.servlet.http.HttpServletResponse; - @Slf4j @Configuration @EnableWebSecurity @@ -64,12 +63,12 @@ public SecurityFilterChain securityFilterChain(final HttpSecurity http, http.apply(new SecurityFilterManagerImpl()); http.exceptionHandling().authenticationEntryPoint((request, response, authException) -> { - log.info(authException.getMessage()); - response.sendError(HttpServletResponse.SC_UNAUTHORIZED); + log.info("{}, {}", request.getRemoteAddr(), authException.getMessage()); + resolver.resolveException(request, response, null, new UnAuthorizedException()); }); http.exceptionHandling().accessDeniedHandler((request, response, accessDeniedException) -> { - log.info(accessDeniedException.getMessage()); + log.info("{}, {}", request.getRemoteAddr(), accessDeniedException.getMessage()); resolver.resolveException(request, response, null, new ForbiddenException()); }); diff --git a/animory/src/main/java/com/daggle/animory/common/security/TokenProvider.java b/animory/src/main/java/com/daggle/animory/common/security/TokenProvider.java index d4b784d3..a9a2cda0 100644 --- a/animory/src/main/java/com/daggle/animory/common/security/TokenProvider.java +++ b/animory/src/main/java/com/daggle/animory/common/security/TokenProvider.java @@ -17,12 +17,11 @@ @Component public class TokenProvider { - private final String key; private static final String TOKEN_PREFIX = "Bearer "; private static final String ROLES_CLAIM = "roles"; - private static final int TOKEN_EXPIRATION_DATE_TO_PLUS = 1; private static final int TOKEN_EXPIRATION_FIXED_HOUR = 3; + private final String key; public TokenProvider(@Value("${jwt.secret}") final String key) { this.key = Base64.getEncoder().encodeToString(key.getBytes()); @@ -31,13 +30,14 @@ public TokenProvider(@Value("${jwt.secret}") final String key) { public String create(final String email, final AccountRole role) { return TOKEN_PREFIX + Jwts.builder().setSubject(email) // 정보 저장 - .claim(ROLES_CLAIM, role).setIssuedAt(new Date()) // 토큰 발행 시간 - .setExpiration(calcExpirationDateTime()) // 토큰 만료 시간 - .signWith(SignatureAlgorithm.HS256, key) // 암호화 알고리즘 및 secretKey - .compact(); + .claim(ROLES_CLAIM, role).setIssuedAt(new Date()) // 토큰 발행 시간 + .setExpiration(calcExpirationDateTime()) // 토큰 만료 시간 + .signWith(SignatureAlgorithm.HS256, key) // 암호화 알고리즘 및 secretKey + .compact(); } - public TokenWithExpirationDateTimeDto createTokenWithExpirationDateTimeDto(final String email, final AccountRole role) { + public TokenWithExpirationDateTimeDto createTokenWithExpirationDateTimeDto(final String email, + final AccountRole role) { final Date expirationDateTime = calcExpirationDateTime(); final String token = TOKEN_PREFIX + Jwts.builder().setSubject(email) .claim(ROLES_CLAIM, role).setIssuedAt(new Date()) @@ -70,17 +70,17 @@ private String cutTokenPrefix(final String bearerToken) { private Claims extractBody(final String token) { return Jwts.parser() - .setSigningKey(key) - .parseClaimsJws(token) - .getBody(); + .setSigningKey(key) + .parseClaimsJws(token) + .getBody(); } private Date calcExpirationDateTime() { final LocalDateTime currentTime = LocalDateTime.now(); // 현재 시각으로 부터 final LocalDateTime expirationDateTime = currentTime - .plusDays(TOKEN_EXPIRATION_DATE_TO_PLUS) // day를 더하고 - .withHour(TOKEN_EXPIRATION_FIXED_HOUR); // 고정된 시각 + .plusDays(TOKEN_EXPIRATION_DATE_TO_PLUS) // day를 더하고 + .withHour(TOKEN_EXPIRATION_FIXED_HOUR); // 고정된 시각 return convertLocalDateTimeToDate(expirationDateTime); } diff --git a/animory/src/main/java/com/daggle/animory/common/security/exception/JwtExceptionFilter.java b/animory/src/main/java/com/daggle/animory/common/security/exception/JwtExceptionFilter.java index 1f1efc58..15ba2744 100644 --- a/animory/src/main/java/com/daggle/animory/common/security/exception/JwtExceptionFilter.java +++ b/animory/src/main/java/com/daggle/animory/common/security/exception/JwtExceptionFilter.java @@ -1,11 +1,12 @@ package com.daggle.animory.common.security.exception; +import com.daggle.animory.common.Response; import com.fasterxml.jackson.databind.ObjectMapper; import io.jsonwebtoken.JwtException; +import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.web.filter.OncePerRequestFilter; -import com.daggle.animory.common.Response; import javax.servlet.FilterChain; import javax.servlet.ServletException; @@ -13,9 +14,12 @@ import javax.servlet.http.HttpServletResponse; import java.io.IOException; +@Slf4j public class JwtExceptionFilter extends OncePerRequestFilter { @Override - protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { + protected void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response, + final FilterChain filterChain) throws ServletException, IOException { + log.debug("JwtExceptionFilter 동작"); try { filterChain.doFilter(request, response); } catch (final JwtException e) { @@ -23,9 +27,9 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response.setContentType(MediaType.APPLICATION_JSON_VALUE); response.setCharacterEncoding("UTF-8"); response.getWriter().write( - new ObjectMapper() - .writeValueAsString( - Response.error(e.getMessage(), HttpStatus.UNAUTHORIZED))); + new ObjectMapper() + .writeValueAsString( + Response.error(e.getMessage(), HttpStatus.UNAUTHORIZED))); } } } diff --git a/animory/src/main/java/com/daggle/animory/common/security/exception/UnAuthorizedException.java b/animory/src/main/java/com/daggle/animory/common/security/exception/UnAuthorizedException.java new file mode 100644 index 00000000..777361c7 --- /dev/null +++ b/animory/src/main/java/com/daggle/animory/common/security/exception/UnAuthorizedException.java @@ -0,0 +1,9 @@ +package com.daggle.animory.common.security.exception; + +public class UnAuthorizedException extends RuntimeException { + @Override + public String getMessage() { + return SecurityExceptionMessage.UNAUTHORIZED.getMessage(); + } +} + diff --git a/animory/src/test/java/com/daggle/animory/acceptance/PetTest.java b/animory/src/test/java/com/daggle/animory/acceptance/PetTest.java index dc2d3ee8..293848b7 100644 --- a/animory/src/test/java/com/daggle/animory/acceptance/PetTest.java +++ b/animory/src/test/java/com/daggle/animory/acceptance/PetTest.java @@ -28,9 +28,9 @@ class PetTest extends AcceptanceTest { final MockMultipartFile image = new MockMultipartFile("profileImage", "image.jpg", "image/jpeg", - "image" .getBytes(StandardCharsets.UTF_8)); + "image".getBytes(StandardCharsets.UTF_8)); final MockMultipartFile video = new MockMultipartFile("profileVideo", "video.mp4", "video/mp4", - "video" .getBytes(StandardCharsets.UTF_8)); + "video".getBytes(StandardCharsets.UTF_8)); @Nested class 강아지_등록 { From d8bd91f90cb21fcafdb57d1f2accce728225cce5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98jminkkk=E2=80=99?= <102847513+jminkkk@users.noreply.github.com> Date: Thu, 9 Nov 2023 11:51:48 +0900 Subject: [PATCH 09/12] =?UTF-8?q?refactor:=20=EA=B8=B0=EC=A1=B4=20?= =?UTF-8?q?=EC=BB=A4=EC=8A=A4=ED=85=80=20exception=EC=99=80=20=ED=86=B5?= =?UTF-8?q?=EC=9D=BC=EC=84=B1=EC=9D=84=20=EC=9C=84=ED=95=B4=20=EC=88=8F?= =?UTF-8?q?=ED=8F=BC=20=EC=BB=A4=EC=8A=A4=ED=85=80=20=EC=97=90=EB=9F=AC=20?= =?UTF-8?q?=EC=9D=B4=EB=A6=84=EC=97=90=20Exception=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...deo.java => AlreadyLikedPetVideoException.java} | 2 +- ...etVideo.java => NotLikedPetVideoException.java} | 2 +- ...tFound.java => ShortFormNotFoundException.java} | 2 +- .../shortform/service/PetVideoLikeService.java | 14 +++++++------- 4 files changed, 10 insertions(+), 10 deletions(-) rename animory/src/main/java/com/daggle/animory/domain/shortform/exception/{AlreadyLikedPetVideo.java => AlreadyLikedPetVideoException.java} (73%) rename animory/src/main/java/com/daggle/animory/domain/shortform/exception/{NotLikedPetVideo.java => NotLikedPetVideoException.java} (73%) rename animory/src/main/java/com/daggle/animory/domain/shortform/exception/{ShortFormNotFound.java => ShortFormNotFoundException.java} (73%) diff --git a/animory/src/main/java/com/daggle/animory/domain/shortform/exception/AlreadyLikedPetVideo.java b/animory/src/main/java/com/daggle/animory/domain/shortform/exception/AlreadyLikedPetVideoException.java similarity index 73% rename from animory/src/main/java/com/daggle/animory/domain/shortform/exception/AlreadyLikedPetVideo.java rename to animory/src/main/java/com/daggle/animory/domain/shortform/exception/AlreadyLikedPetVideoException.java index 99e4d762..84057eb0 100644 --- a/animory/src/main/java/com/daggle/animory/domain/shortform/exception/AlreadyLikedPetVideo.java +++ b/animory/src/main/java/com/daggle/animory/domain/shortform/exception/AlreadyLikedPetVideoException.java @@ -1,6 +1,6 @@ package com.daggle.animory.domain.shortform.exception; -public class AlreadyLikedPetVideo extends RuntimeException { +public class AlreadyLikedPetVideoException extends RuntimeException { @Override public String getMessage() { return ShortFormExceptionMessage.ALREADY_LIKED_PET_VIDEO.getMessage(); diff --git a/animory/src/main/java/com/daggle/animory/domain/shortform/exception/NotLikedPetVideo.java b/animory/src/main/java/com/daggle/animory/domain/shortform/exception/NotLikedPetVideoException.java similarity index 73% rename from animory/src/main/java/com/daggle/animory/domain/shortform/exception/NotLikedPetVideo.java rename to animory/src/main/java/com/daggle/animory/domain/shortform/exception/NotLikedPetVideoException.java index 4bd65943..d622e503 100644 --- a/animory/src/main/java/com/daggle/animory/domain/shortform/exception/NotLikedPetVideo.java +++ b/animory/src/main/java/com/daggle/animory/domain/shortform/exception/NotLikedPetVideoException.java @@ -1,6 +1,6 @@ package com.daggle.animory.domain.shortform.exception; -public class NotLikedPetVideo extends RuntimeException { +public class NotLikedPetVideoException extends RuntimeException { @Override public String getMessage() { return ShortFormExceptionMessage.NOT_LIKED_PET_VIDEO.getMessage(); diff --git a/animory/src/main/java/com/daggle/animory/domain/shortform/exception/ShortFormNotFound.java b/animory/src/main/java/com/daggle/animory/domain/shortform/exception/ShortFormNotFoundException.java similarity index 73% rename from animory/src/main/java/com/daggle/animory/domain/shortform/exception/ShortFormNotFound.java rename to animory/src/main/java/com/daggle/animory/domain/shortform/exception/ShortFormNotFoundException.java index 74ee8ed9..ce65aa94 100644 --- a/animory/src/main/java/com/daggle/animory/domain/shortform/exception/ShortFormNotFound.java +++ b/animory/src/main/java/com/daggle/animory/domain/shortform/exception/ShortFormNotFoundException.java @@ -1,6 +1,6 @@ package com.daggle.animory.domain.shortform.exception; -public class ShortFormNotFound extends RuntimeException { +public class ShortFormNotFoundException extends RuntimeException { @Override public String getMessage() { return ShortFormExceptionMessage.SHORT_FORM_NOT_FOUND.getMessage(); diff --git a/animory/src/main/java/com/daggle/animory/domain/shortform/service/PetVideoLikeService.java b/animory/src/main/java/com/daggle/animory/domain/shortform/service/PetVideoLikeService.java index cb9e94d3..0cd77fb6 100644 --- a/animory/src/main/java/com/daggle/animory/domain/shortform/service/PetVideoLikeService.java +++ b/animory/src/main/java/com/daggle/animory/domain/shortform/service/PetVideoLikeService.java @@ -2,9 +2,9 @@ import com.daggle.animory.domain.pet.entity.PetVideo; import com.daggle.animory.domain.shortform.entity.PetVideoLike; -import com.daggle.animory.domain.shortform.exception.AlreadyLikedPetVideo; -import com.daggle.animory.domain.shortform.exception.NotLikedPetVideo; -import com.daggle.animory.domain.shortform.exception.ShortFormNotFound; +import com.daggle.animory.domain.shortform.exception.AlreadyLikedPetVideoException; +import com.daggle.animory.domain.shortform.exception.NotLikedPetVideoException; +import com.daggle.animory.domain.shortform.exception.ShortFormNotFoundException; import com.daggle.animory.domain.shortform.repository.PetVideoJpaRepository; import com.daggle.animory.domain.shortform.repository.PetVideoLikeRepository; import lombok.RequiredArgsConstructor; @@ -22,7 +22,7 @@ public void updatePetVideoLikeCount(final String IPAddress, final int petVideoId validatePetVideoLikeDuplication(IPAddress, petVideoId); final PetVideo petVideo = petVideoJpaRepository.findById(petVideoId) - .orElseThrow(ShortFormNotFound::new); + .orElseThrow(ShortFormNotFoundException::new); petVideo.updateLikeCount(); @@ -36,7 +36,7 @@ public void deletePetVideoLikeCount(final String ipAddress, final int petVideoId validatePetVideoLikeDelete(ipAddress, petVideoId); final PetVideo petVideo = petVideoJpaRepository.findById(petVideoId) - .orElseThrow(ShortFormNotFound::new); + .orElseThrow(ShortFormNotFoundException::new); petVideo.deleteLikeCount(); @@ -45,13 +45,13 @@ public void deletePetVideoLikeCount(final String ipAddress, final int petVideoId private void validatePetVideoLikeDuplication(final String IPAddress, final int petVideoId) { if (petVideoLikeRepository.existsByIpAddressAndPetVideoId(IPAddress, petVideoId)) { - throw new AlreadyLikedPetVideo(); + throw new AlreadyLikedPetVideoException(); } } private void validatePetVideoLikeDelete(final String IPAddress, final int petVideoId) { if (!petVideoLikeRepository.existsByIpAddressAndPetVideoId(IPAddress, petVideoId)) { - throw new NotLikedPetVideo(); + throw new NotLikedPetVideoException(); } } } From e0d53ce46ef60ed9d5d27644b66618c80559c36e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98jminkkk=E2=80=99?= <102847513+jminkkk@users.noreply.github.com> Date: Thu, 9 Nov 2023 11:52:47 +0900 Subject: [PATCH 10/12] =?UTF-8?q?fix:=20GlobalExceptionHandler=EC=97=90=20?= =?UTF-8?q?=EB=88=84=EB=9D=BD=EB=90=9C=20=EC=88=8F=ED=8F=BC=20=EC=BB=A4?= =?UTF-8?q?=EC=8A=A4=ED=85=80=20=EC=98=88=EC=99=B8=20=EC=B2=98=EB=A6=AC=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../handler/GlobalExceptionHandler.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/animory/src/main/java/com/daggle/animory/common/exception/handler/GlobalExceptionHandler.java b/animory/src/main/java/com/daggle/animory/common/exception/handler/GlobalExceptionHandler.java index 65dca644..ffdcba83 100644 --- a/animory/src/main/java/com/daggle/animory/common/exception/handler/GlobalExceptionHandler.java +++ b/animory/src/main/java/com/daggle/animory/common/exception/handler/GlobalExceptionHandler.java @@ -11,9 +11,13 @@ import com.daggle.animory.domain.pet.exception.InvalidPetMonthRangeException; import com.daggle.animory.domain.pet.exception.InvalidPetYearRangeException; import com.daggle.animory.domain.pet.exception.PetNotFoundException; +import com.daggle.animory.domain.pet.exception.PetPermissionDeniedException; import com.daggle.animory.domain.shelter.exception.ShelterAlreadyExistException; import com.daggle.animory.domain.shelter.exception.ShelterNotFoundException; import com.daggle.animory.domain.shelter.exception.ShelterPermissionDeniedException; +import com.daggle.animory.domain.shortform.exception.AlreadyLikedPetVideoException; +import com.daggle.animory.domain.shortform.exception.NotLikedPetVideoException; +import com.daggle.animory.domain.shortform.exception.ShortFormNotFoundException; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.responses.ApiResponse; import lombok.RequiredArgsConstructor; @@ -108,6 +112,18 @@ public ResponseEntity> handleShelterAlreadyExistException(final E HttpStatus.BAD_REQUEST)); } + @ExceptionHandler({AlreadyLikedPetVideoException.class}) + public ResponseEntity> handleAlreadyLikedPetVideoException(final Exception e) { + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(Response.error(e.getMessage(), + HttpStatus.BAD_REQUEST)); + } + + @ExceptionHandler({NotLikedPetVideoException.class}) + public ResponseEntity> handleNotLikedPetVideoException(final Exception e) { + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(Response.error(e.getMessage(), + HttpStatus.BAD_REQUEST)); + } + // 401 @ExceptionHandler({UnAuthorizedException.class}) public ResponseEntity> handleUnAuthorizedException(final Exception e) { @@ -122,6 +138,11 @@ public ResponseEntity> handleShelterPermissionDeniedException(fin return ResponseEntity.status(HttpStatus.FORBIDDEN).body(Response.error(e.getMessage(), HttpStatus.FORBIDDEN)); } + @ExceptionHandler({PetPermissionDeniedException.class}) + public ResponseEntity> handlePetPermissionDeniedException(final Exception e) { + return ResponseEntity.status(HttpStatus.FORBIDDEN).body(Response.error(e.getMessage(), HttpStatus.FORBIDDEN)); + } + @ExceptionHandler({ForbiddenException.class}) public ResponseEntity> handleForbiddenExceptionn(final Exception e) { return ResponseEntity.status(HttpStatus.FORBIDDEN).body(Response.error(e.getMessage(), HttpStatus.FORBIDDEN)); @@ -137,6 +158,10 @@ public ResponseEntity> handlePetNotFoundException(final Exception public ResponseEntity> handleShelterNotFoundException(final Exception e) { return ResponseEntity.status(HttpStatus.NOT_FOUND).body(Response.error(e.getMessage(), HttpStatus.NOT_FOUND)); } + @ExceptionHandler({ShortFormNotFoundException.class}) + public ResponseEntity> handleShortFormNotFoundException(final Exception e) { + return ResponseEntity.status(HttpStatus.NOT_FOUND).body(Response.error(e.getMessage(), HttpStatus.NOT_FOUND)); + } @ExceptionHandler({MaxUploadSizeExceededException.class}) public ResponseEntity> handleMaxUploadSizeExceededException(final RuntimeException e) { From 4ced51114f0cf5cc6c01d5734a709f972b9c2196 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98jminkkk=E2=80=99?= <102847513+jminkkk@users.noreply.github.com> Date: Thu, 9 Nov 2023 17:47:03 +0900 Subject: [PATCH 11/12] =?UTF-8?q?fix:=20=ED=94=84=EB=A1=9C=ED=95=84=20?= =?UTF-8?q?=EB=AA=A9=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=204=EA=B0=9C=EC=94=A9?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/daggle/animory/domain/pet/service/PetReadService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/animory/src/main/java/com/daggle/animory/domain/pet/service/PetReadService.java b/animory/src/main/java/com/daggle/animory/domain/pet/service/PetReadService.java index 60d0aaee..982027d1 100644 --- a/animory/src/main/java/com/daggle/animory/domain/pet/service/PetReadService.java +++ b/animory/src/main/java/com/daggle/animory/domain/pet/service/PetReadService.java @@ -25,8 +25,8 @@ public class PetReadService { public PetProfilesDto getPetProfiles() { // sos, new 프로필 각각 최대 8개씩 조회 - final List sosProfiles = petRepository.findProfilesWithProtectionExpirationDate(PageRequest.of(0, 8)).getContent(); - final List newProfiles = petRepository.findProfilesWithCreatedAt(PageRequest.of(0, 8)).getContent(); + final List sosProfiles = petRepository.findProfilesWithProtectionExpirationDate(PageRequest.of(0, 4)).getContent(); + final List newProfiles = petRepository.findProfilesWithCreatedAt(PageRequest.of(0, 4)).getContent(); // DTO에 넣어주기 final List sosList = sosProfiles.stream() From 6fd9f23844a47c8a158ab0166e37c7a803f754bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98jminkkk=E2=80=99?= <102847513+jminkkk@users.noreply.github.com> Date: Thu, 9 Nov 2023 17:47:20 +0900 Subject: [PATCH 12/12] =?UTF-8?q?refactor:=20=EC=82=AC=EC=9A=A9=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8A=94=20=EC=97=90=EB=9F=AC=20=EB=A9=94?= =?UTF-8?q?=EC=8B=9C=EC=A7=80=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/security/exception/SecurityExceptionMessage.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/animory/src/main/java/com/daggle/animory/common/security/exception/SecurityExceptionMessage.java b/animory/src/main/java/com/daggle/animory/common/security/exception/SecurityExceptionMessage.java index af01f84e..a12a0987 100644 --- a/animory/src/main/java/com/daggle/animory/common/security/exception/SecurityExceptionMessage.java +++ b/animory/src/main/java/com/daggle/animory/common/security/exception/SecurityExceptionMessage.java @@ -3,8 +3,7 @@ public enum SecurityExceptionMessage { UNAUTHORIZED("인증되지 않은 사용자입니다."), FORBIDDEN("권한이 없습니다."), - INVALID_TOKEN("유효하지 않은 토큰입니다."), - INVALID_TOKEN_FORMAT("유효하지 않은 토큰 형식입니다."),; + ; private final String message;