-
Notifications
You must be signed in to change notification settings - Fork 1
Feature/129 봉사 지원 승인/거절 #132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
e964462
feat(recruit-board): 모집 게시글 도메인 로직
leebs0521 a887257
feat(recruit-board): 봉사 활동 모집글 조회 기능
leebs0521 004af0f
feat(volunteer-apply): 봉사 활동 지원 승인 기능
leebs0521 79f7132
test(volunteer-apply): 봉사 활동 지원 승인 기능 테스트
leebs0521 552a1f6
feat(volunteer-apply): 봉사 활동 지원 승인 API
leebs0521 45e6e26
test(volunteer-apply): 봉사 활동 지원 승인 API 테스트
leebs0521 70b78ca
chore: 디렉토리 위치 변경
leebs0521 83dffa2
feat(volunteer-apply): 봉사 활동 지원 거절 기능
leebs0521 882811a
test(volunteer-apply): 봉사 활동 지원 거절 기능 테스트
leebs0521 cc75f9a
feat(volunteer-apply): 봉사 활동 지원 거절 API
leebs0521 d8d609b
test(volunteer-apply): 봉사 활동 지원 거절 API 테스트
leebs0521 e8cae10
refactor(volunteer-apply): 메서드 이름 수정
leebs0521 0f8d4eb
chore: 불필요한 import 제거
leebs0521 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
50 changes: 50 additions & 0 deletions
50
...java/com/somemore/volunteerapply/controller/CenterVolunteerApplyCommandApiController.java
This file contains hidden or 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,50 @@ | ||
| package com.somemore.volunteerapply.controller; | ||
|
|
||
| import com.somemore.auth.annotation.CurrentUser; | ||
| import com.somemore.global.common.response.ApiResponse; | ||
| import com.somemore.volunteerapply.usecase.ApproveVolunteerApplyUseCase; | ||
| import com.somemore.volunteerapply.usecase.RejectVolunteerApplyUseCase; | ||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||
| import java.util.UUID; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.security.access.annotation.Secured; | ||
| import org.springframework.web.bind.annotation.PatchMapping; | ||
| import org.springframework.web.bind.annotation.PathVariable; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| @Tag(name = "Center Volunteer Apply Command API", description = "봉사 활동 지원 승인, 거절, 정산 API") | ||
| @RequiredArgsConstructor | ||
| @RequestMapping("/api") | ||
| @RestController | ||
| public class CenterVolunteerApplyCommandApiController { | ||
|
|
||
| private final ApproveVolunteerApplyUseCase approveVolunteerApplyUseCase; | ||
| private final RejectVolunteerApplyUseCase rejectVolunteerApplyUseCase; | ||
|
|
||
| @Secured("ROLE_CENTER") | ||
| @Operation(summary = "봉사 활동 지원 승인", description = "봉사 활동 지원을 승인합니다.") | ||
| @PatchMapping("/volunteer-apply/{id}/approve") | ||
| public ApiResponse<String> approve( | ||
| @CurrentUser UUID centerId, | ||
| @PathVariable Long id | ||
| ) { | ||
|
|
||
| approveVolunteerApplyUseCase.approve(id, centerId); | ||
| return ApiResponse.ok("봉사 활동 지원 승인 성공"); | ||
| } | ||
|
|
||
| @Secured("ROLE_CENTER") | ||
| @Operation(summary = "봉사 활동 지원 거절", description = "봉사 활동 지원을 거절합니다.") | ||
| @PatchMapping("/volunteer-apply/{id}/reject") | ||
| public ApiResponse<String> reject( | ||
| @CurrentUser UUID centerId, | ||
| @PathVariable Long id | ||
| ) { | ||
|
|
||
| rejectVolunteerApplyUseCase.reject(id, centerId); | ||
| return ApiResponse.ok("봉사 활동 지원 거절 성공"); | ||
| } | ||
|
|
||
| } | ||
58 changes: 58 additions & 0 deletions
58
src/main/java/com/somemore/volunteerapply/service/ApproveVolunteerApplyService.java
This file contains hidden or 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,58 @@ | ||
| package com.somemore.volunteerapply.service; | ||
|
|
||
| import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_VOLUNTEER_APPLY; | ||
| import static com.somemore.global.exception.ExceptionMessage.RECRUIT_BOARD_ALREADY_COMPLETED; | ||
| import static com.somemore.global.exception.ExceptionMessage.UNAUTHORIZED_RECRUIT_BOARD; | ||
| import static com.somemore.volunteerapply.domain.ApplyStatus.APPROVED; | ||
|
|
||
| import com.somemore.global.exception.BadRequestException; | ||
| import com.somemore.recruitboard.domain.RecruitBoard; | ||
| import com.somemore.recruitboard.usecase.query.RecruitBoardQueryUseCase; | ||
| import com.somemore.volunteerapply.domain.VolunteerApply; | ||
| import com.somemore.volunteerapply.repository.VolunteerApplyRepository; | ||
| import com.somemore.volunteerapply.usecase.ApproveVolunteerApplyUseCase; | ||
| import java.util.UUID; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| @RequiredArgsConstructor | ||
| @Transactional | ||
| @Service | ||
| public class ApproveVolunteerApplyService implements ApproveVolunteerApplyUseCase { | ||
|
|
||
| private final VolunteerApplyRepository volunteerApplyRepository; | ||
|
|
||
| private final RecruitBoardQueryUseCase recruitBoardQueryUseCase; | ||
|
|
||
| @Override | ||
| public void approve(Long id, UUID centerId) { | ||
| VolunteerApply apply = getVolunteerApply(id); | ||
| RecruitBoard recruitBoard = recruitBoardQueryUseCase.getById(apply.getRecruitBoardId()); | ||
|
|
||
| validateWriter(recruitBoard, centerId); | ||
| validateBoardStatus(recruitBoard); | ||
|
|
||
| apply.changeStatus(APPROVED); | ||
| volunteerApplyRepository.save(apply); | ||
| } | ||
|
|
||
| private VolunteerApply getVolunteerApply(Long id) { | ||
| return volunteerApplyRepository.findById(id).orElseThrow( | ||
| () -> new BadRequestException(NOT_EXISTS_VOLUNTEER_APPLY) | ||
| ); | ||
| } | ||
|
|
||
| private void validateWriter(RecruitBoard recruitBoard, UUID centerId) { | ||
| if (recruitBoard.isWriter(centerId)) { | ||
| return; | ||
| } | ||
| throw new BadRequestException(UNAUTHORIZED_RECRUIT_BOARD); | ||
| } | ||
|
|
||
| private void validateBoardStatus(RecruitBoard recruitBoard) { | ||
| if (recruitBoard.isCompleted()) { | ||
| throw new BadRequestException(RECRUIT_BOARD_ALREADY_COMPLETED); | ||
| } | ||
| } | ||
| } |
58 changes: 58 additions & 0 deletions
58
src/main/java/com/somemore/volunteerapply/service/RejectVolunteerApplyService.java
This file contains hidden or 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,58 @@ | ||
| package com.somemore.volunteerapply.service; | ||
|
|
||
| import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_VOLUNTEER_APPLY; | ||
| import static com.somemore.global.exception.ExceptionMessage.RECRUIT_BOARD_ALREADY_COMPLETED; | ||
| import static com.somemore.global.exception.ExceptionMessage.UNAUTHORIZED_RECRUIT_BOARD; | ||
| import static com.somemore.volunteerapply.domain.ApplyStatus.REJECTED; | ||
|
|
||
| import com.somemore.global.exception.BadRequestException; | ||
| import com.somemore.recruitboard.domain.RecruitBoard; | ||
| import com.somemore.recruitboard.usecase.query.RecruitBoardQueryUseCase; | ||
| import com.somemore.volunteerapply.domain.VolunteerApply; | ||
| import com.somemore.volunteerapply.repository.VolunteerApplyRepository; | ||
| import com.somemore.volunteerapply.usecase.RejectVolunteerApplyUseCase; | ||
| import java.util.UUID; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| @RequiredArgsConstructor | ||
| @Transactional | ||
| @Service | ||
| public class RejectVolunteerApplyService implements RejectVolunteerApplyUseCase { | ||
|
|
||
| private final VolunteerApplyRepository volunteerApplyRepository; | ||
| private final RecruitBoardQueryUseCase recruitBoardQueryUseCase; | ||
|
|
||
| @Override | ||
| public void reject(Long id, UUID centerId) { | ||
| VolunteerApply apply = getApply(id); | ||
| RecruitBoard recruitBoard = recruitBoardQueryUseCase.getById(apply.getRecruitBoardId()); | ||
|
|
||
| validateWriter(recruitBoard, centerId); | ||
| validateBoardStatus(recruitBoard); | ||
|
|
||
| apply.changeStatus(REJECTED); | ||
| volunteerApplyRepository.save(apply); | ||
| } | ||
|
|
||
| private VolunteerApply getApply(Long id) { | ||
| return volunteerApplyRepository.findById(id).orElseThrow( | ||
| () -> new BadRequestException(NOT_EXISTS_VOLUNTEER_APPLY) | ||
| ); | ||
| } | ||
|
|
||
| private void validateWriter(RecruitBoard recruitBoard, UUID centerId) { | ||
| if (recruitBoard.isWriter(centerId)) { | ||
| return; | ||
| } | ||
| throw new BadRequestException(UNAUTHORIZED_RECRUIT_BOARD); | ||
| } | ||
|
|
||
| private void validateBoardStatus(RecruitBoard recruitBoard) { | ||
| if (recruitBoard.isCompleted()) { | ||
| throw new BadRequestException(RECRUIT_BOARD_ALREADY_COMPLETED); | ||
| } | ||
| } | ||
|
|
||
| } |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/somemore/volunteerapply/usecase/ApproveVolunteerApplyUseCase.java
This file contains hidden or 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,10 @@ | ||
| package com.somemore.volunteerapply.usecase; | ||
|
|
||
|
|
||
| import java.util.UUID; | ||
|
|
||
| public interface ApproveVolunteerApplyUseCase { | ||
|
|
||
| void approve(Long id, UUID centerId); | ||
|
|
||
| } |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/somemore/volunteerapply/usecase/RejectVolunteerApplyUseCase.java
This file contains hidden or 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,9 @@ | ||
| package com.somemore.volunteerapply.usecase; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| public interface RejectVolunteerApplyUseCase { | ||
|
|
||
| void reject(Long id, UUID centerId); | ||
|
|
||
| } |
68 changes: 68 additions & 0 deletions
68
.../com/somemore/volunteerapply/controller/CenterVolunteerApplyCommandApiControllerTest.java
This file contains hidden or 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,68 @@ | ||
| package com.somemore.volunteerapply.controller; | ||
|
|
||
| import static org.mockito.ArgumentMatchers.any; | ||
| import static org.mockito.BDDMockito.willDoNothing; | ||
| import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch; | ||
| import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; | ||
| import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
|
||
| import com.somemore.ControllerTestSupport; | ||
| import com.somemore.WithMockCustomUser; | ||
| import com.somemore.volunteerapply.usecase.ApproveVolunteerApplyUseCase; | ||
| import com.somemore.volunteerapply.usecase.RejectVolunteerApplyUseCase; | ||
| import java.util.UUID; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.boot.test.mock.mockito.MockBean; | ||
| import org.springframework.test.web.servlet.MockMvc; | ||
|
|
||
| class CenterVolunteerApplyCommandApiControllerTest extends ControllerTestSupport { | ||
|
|
||
| @Autowired | ||
| private MockMvc mockMvc; | ||
|
|
||
| @MockBean | ||
| private ApproveVolunteerApplyUseCase approveVolunteerApplyUseCase; | ||
|
|
||
| @MockBean | ||
| private RejectVolunteerApplyUseCase rejectVolunteerApplyUseCase; | ||
|
|
||
| @Test | ||
| @DisplayName("봉사 활동 지원 승인 성공 테스트") | ||
| @WithMockCustomUser(role = "CENTER") | ||
| void approve() throws Exception { | ||
| // given | ||
| Long id = 1L; | ||
|
|
||
| willDoNothing().given(approveVolunteerApplyUseCase) | ||
| .approve(any(), any(UUID.class)); | ||
| // when | ||
| mockMvc.perform(patch("/api/volunteer-apply/{id}/approve", id) | ||
| .header("Authorization", "Bearer access-token")) | ||
| // then | ||
| .andExpect(status().isOk()) | ||
| .andExpect(jsonPath("$.code").value(200)) | ||
| .andExpect(jsonPath("$.data").value("")) | ||
| .andExpect(jsonPath("$.message").value("봉사 활동 지원 승인 성공")); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("봉사 활동 지원 거절 성공 테스트") | ||
| @WithMockCustomUser(role = "CENTER") | ||
| void reject() throws Exception { | ||
| // given | ||
| Long id = 1L; | ||
|
|
||
| willDoNothing().given(rejectVolunteerApplyUseCase) | ||
| .reject(any(), any(UUID.class)); | ||
| // when | ||
| mockMvc.perform(patch("/api/volunteer-apply/{id}/reject", id) | ||
| .header("Authorization", "Bearer access-token")) | ||
| // then | ||
| .andExpect(status().isOk()) | ||
| .andExpect(jsonPath("$.code").value(200)) | ||
| .andExpect(jsonPath("$.data").value("")) | ||
| .andExpect(jsonPath("$.message").value("봉사 활동 지원 거절 성공")); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
좋아요~~