-
Notifications
You must be signed in to change notification settings - Fork 1
Feature/117 봉사 활동 지원 및 철회 기능 #128
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
leebs0521
merged 19 commits into
main
from
feature/117-add-volunteer-apply-apply-and-withdraw
Dec 3, 2024
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
5b63fcf
refactor(recruit-board): 조회 기능 수정
leebs0521 8671add
test(recruit-board): 조회 기능 수정에 따른 테스트
leebs0521 191a6a7
feat(recruit-board): 모집 상태에 대한 도메인 비지니스 로직 메서드 작성
leebs0521 26cb27a
test(recruit-board): 모집 상태에 대한 도메인 비지니스 로직 메서드 테스트
leebs0521 404c409
test(recruit-board): 모집 상태에 대한 도메인 비지니스 로직 메서드 테스트
leebs0521 7ccf7dd
feat(volunteer-apply): 봉사 모집글 지원 기능
leebs0521 012e7a9
test(volunteer-apply): 봉사 모집글 지원 테스트
leebs0521 793bb34
feat(volunteer-apply): 봉사 모집글 지원 API 연결
leebs0521 97faef7
test(volunteer-apply): 봉사 모집글 지원 API 연결 테스트
leebs0521 c464977
refactor(volunteer-apply): 클래스 이름 변경
leebs0521 452b192
feat(volunteer-apply): 도메인 로직 작성
leebs0521 0180976
test(volunteer-apply): 도메인 로직 작성 테스트
leebs0521 697e6aa
feat(volunteer-apply): 봉사 지원 철회 기능
leebs0521 fcb83a4
test(volunteer-apply): 봉사 지원 철회 기능 테스트
leebs0521 b487880
feat(volunteer-apply): 봉사 지원 철회 기능 API
leebs0521 d0511e9
test(volunteer-apply): 봉사 지원 철회 기능 API 테스트
leebs0521 c6bd639
fix(volunteer-apply): sonar qube 리뷰 반영
leebs0521 72d09fa
refactor(recruit-board): 도메인 로직 메서드 변경
leebs0521 95e46bd
test(recruit-board): 도메인 로직 메서드 변경에 따른 테스트 및 부적절한 테스트 제거
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
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
55 changes: 55 additions & 0 deletions
55
src/main/java/com/somemore/volunteerapply/controller/VolunteerApplyCommandApiController.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,55 @@ | ||
| package com.somemore.volunteerapply.controller; | ||
|
|
||
| import com.somemore.auth.annotation.CurrentUser; | ||
| import com.somemore.global.common.response.ApiResponse; | ||
| import com.somemore.volunteerapply.dto.VolunteerApplyCreateRequestDto; | ||
| import com.somemore.volunteerapply.usecase.ApplyVolunteerApplyUseCase; | ||
| import com.somemore.volunteerapply.usecase.WithdrawVolunteerApplyUseCase; | ||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||
| import jakarta.validation.Valid; | ||
| import java.util.UUID; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.security.access.annotation.Secured; | ||
| import org.springframework.web.bind.annotation.DeleteMapping; | ||
| import org.springframework.web.bind.annotation.PathVariable; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| @Tag(name = "Volunteer Apply Command API", description = "봉사 활동 지원, 철회 관련 API") | ||
| @RequiredArgsConstructor | ||
| @RequestMapping("/api") | ||
| @RestController | ||
| public class VolunteerApplyCommandApiController { | ||
|
|
||
| private final ApplyVolunteerApplyUseCase applyVolunteerApplyUseCase; | ||
| private final WithdrawVolunteerApplyUseCase withdrawVolunteerApplyUseCase; | ||
|
|
||
| @Secured("ROLE_VOLUNTEER") | ||
| @Operation(summary = "봉사 활동 지원", description = "봉사 활동에 지원합니다.") | ||
| @PostMapping("/volunteer-apply") | ||
| public ApiResponse<Long> apply( | ||
| @CurrentUser UUID volunteerId, | ||
| @Valid @RequestBody VolunteerApplyCreateRequestDto requestDto | ||
| ) { | ||
| return ApiResponse.ok( | ||
| 201, | ||
| applyVolunteerApplyUseCase.apply(requestDto, volunteerId), | ||
| "봉사 활동 지원 성공" | ||
| ); | ||
| } | ||
|
|
||
| @Secured("ROLE_VOLUNTEER") | ||
| @Operation(summary = "봉사 활동 지원 철회", description = "봉사 활동 지원을 철회합니다.") | ||
| @DeleteMapping("/volunteer-apply/{id}") | ||
| public ApiResponse<String> withdraw( | ||
| @CurrentUser UUID volunteerId, | ||
| @PathVariable Long id | ||
| ) { | ||
| withdrawVolunteerApplyUseCase.withdraw(id, volunteerId); | ||
| return ApiResponse.ok("봉사 활동 지원 철회 성공"); | ||
| } | ||
|
|
||
| } |
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
30 changes: 30 additions & 0 deletions
30
src/main/java/com/somemore/volunteerapply/dto/VolunteerApplyCreateRequestDto.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,30 @@ | ||
| package com.somemore.volunteerapply.dto; | ||
|
|
||
| import static com.somemore.volunteerapply.domain.ApplyStatus.WAITING; | ||
|
|
||
| import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy; | ||
| import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
| import com.somemore.volunteerapply.domain.VolunteerApply; | ||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
| import jakarta.validation.constraints.NotNull; | ||
| import java.util.UUID; | ||
| import lombok.Builder; | ||
|
|
||
| @JsonNaming(SnakeCaseStrategy.class) | ||
| @Builder | ||
| public record VolunteerApplyCreateRequestDto( | ||
| @Schema(description = "봉사 모집글 아이디", example = "1") | ||
| @NotNull(message = "모집글 아이디는 필수 값입니다.") | ||
| Long recruitBoardId | ||
| ) { | ||
|
|
||
| public VolunteerApply toEntity(UUID volunteerId) { | ||
| return VolunteerApply.builder() | ||
| .volunteerId(volunteerId) | ||
| .recruitBoardId(recruitBoardId) | ||
| .status(WAITING) | ||
| .attended(false) | ||
| .build(); | ||
| } | ||
|
|
||
| } |
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
53 changes: 53 additions & 0 deletions
53
src/main/java/com/somemore/volunteerapply/service/ApplyVolunteerApplyService.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,53 @@ | ||
| package com.somemore.volunteerapply.service; | ||
|
|
||
| import static com.somemore.global.exception.ExceptionMessage.DUPLICATE_APPLICATION; | ||
| import static com.somemore.global.exception.ExceptionMessage.RECRUITMENT_NOT_OPEN; | ||
|
|
||
| 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.dto.VolunteerApplyCreateRequestDto; | ||
| import com.somemore.volunteerapply.repository.VolunteerApplyRepository; | ||
| import com.somemore.volunteerapply.usecase.ApplyVolunteerApplyUseCase; | ||
| import java.util.UUID; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| @RequiredArgsConstructor | ||
| @Transactional | ||
| @Service | ||
| public class ApplyVolunteerApplyService implements ApplyVolunteerApplyUseCase { | ||
|
|
||
| private final VolunteerApplyRepository volunteerApplyRepository; | ||
| private final RecruitBoardQueryUseCase recruitBoardQueryUseCase; | ||
|
|
||
| @Override | ||
| public Long apply(VolunteerApplyCreateRequestDto requestDto, UUID volunteerId) { | ||
|
|
||
| RecruitBoard board = recruitBoardQueryUseCase.getById(requestDto.recruitBoardId()); | ||
| validateCanApply(board); | ||
| validateDuplicatedApply(volunteerId, board); | ||
|
|
||
| VolunteerApply apply = requestDto.toEntity(volunteerId); | ||
| volunteerApplyRepository.save(apply); | ||
|
|
||
| return apply.getId(); | ||
| } | ||
|
|
||
| private void validateCanApply(RecruitBoard board) { | ||
| if (board.isRecruitOpen()) { | ||
| return; | ||
| } | ||
| throw new BadRequestException(RECRUITMENT_NOT_OPEN); | ||
| } | ||
|
|
||
| private void validateDuplicatedApply(UUID volunteerId, RecruitBoard board) { | ||
| boolean isDuplicate = volunteerApplyRepository.existsByRecruitIdAndVolunteerId(board.getId(), | ||
| volunteerId); | ||
| if (isDuplicate) { | ||
| throw new BadRequestException(DUPLICATE_APPLICATION); | ||
| } | ||
| } | ||
| } |
44 changes: 44 additions & 0 deletions
44
src/main/java/com/somemore/volunteerapply/service/WithdrawVolunteerApplyService.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,44 @@ | ||
| package com.somemore.volunteerapply.service; | ||
|
|
||
| import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_VOLUNTEER_APPLY; | ||
| import static com.somemore.global.exception.ExceptionMessage.UNAUTHORIZED_VOLUNTEER_APPLY; | ||
|
|
||
| import com.somemore.global.exception.BadRequestException; | ||
| import com.somemore.volunteerapply.domain.VolunteerApply; | ||
| import com.somemore.volunteerapply.repository.VolunteerApplyRepository; | ||
| import com.somemore.volunteerapply.usecase.WithdrawVolunteerApplyUseCase; | ||
| import java.util.UUID; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| @RequiredArgsConstructor | ||
| @Transactional | ||
| @Service | ||
| public class WithdrawVolunteerApplyService implements WithdrawVolunteerApplyUseCase { | ||
|
|
||
| private final VolunteerApplyRepository volunteerApplyRepository; | ||
|
|
||
| @Override | ||
| public void withdraw(Long id, UUID volunteerId) { | ||
| VolunteerApply apply = getApply(id); | ||
| validateVolunteerIdentity(apply, volunteerId); | ||
|
|
||
| apply.markAsDeleted(); | ||
| volunteerApplyRepository.save(apply); | ||
| } | ||
|
|
||
| private VolunteerApply getApply(Long id) { | ||
| return volunteerApplyRepository.findById(id).orElseThrow( | ||
| () -> new BadRequestException(NOT_EXISTS_VOLUNTEER_APPLY) | ||
| ); | ||
| } | ||
|
|
||
| private void validateVolunteerIdentity(VolunteerApply apply, UUID volunteerId) { | ||
| if (apply.isOwnApplication(volunteerId)) { | ||
| return; | ||
| } | ||
|
|
||
| throw new BadRequestException(UNAUTHORIZED_VOLUNTEER_APPLY); | ||
| } | ||
| } |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/somemore/volunteerapply/usecase/ApplyVolunteerApplyUseCase.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 com.somemore.volunteerapply.dto.VolunteerApplyCreateRequestDto; | ||
| import java.util.UUID; | ||
|
|
||
| public interface ApplyVolunteerApplyUseCase { | ||
|
|
||
| Long apply(VolunteerApplyCreateRequestDto requestDto, UUID volunteerId); | ||
|
|
||
| } |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/somemore/volunteerapply/usecase/WithdrawVolunteerApplyUseCase.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 WithdrawVolunteerApplyUseCase { | ||
|
|
||
| void withdraw(Long id, UUID volunteerId); | ||
|
|
||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.