Skip to content

Commit dc64424

Browse files
committed
feat(volunteer-apply): 봉사 지원 철회 기능
1 parent 8e92f05 commit dc64424

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

src/main/java/com/somemore/global/exception/ExceptionMessage.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public enum ExceptionMessage {
3131
NOT_EXISTS_REVIEW("존재하지 않는 리뷰입니다."),
3232
RECRUITMENT_NOT_OPEN("현재 모집 진행 중이 아닙니다."),
3333
DUPLICATE_APPLICATION("이미 신청한 봉사 모집 공고입니다."),
34+
UNAUTHORIZED_VOLUNTEER_APPLY("해당 지원에 권한이 없습니다."),
3435

3536
;
3637
private final String message;
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.somemore.volunteerapply.service;
2+
3+
import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_VOLUNTEER_APPLY;
4+
import static com.somemore.global.exception.ExceptionMessage.UNAUTHORIZED_VOLUNTEER_APPLY;
5+
6+
import com.somemore.global.exception.BadRequestException;
7+
import com.somemore.volunteerapply.domain.VolunteerApply;
8+
import com.somemore.volunteerapply.repository.VolunteerApplyRepository;
9+
import com.somemore.volunteerapply.usecase.WithdrawVolunteerApplyUseCase;
10+
import java.util.UUID;
11+
import lombok.RequiredArgsConstructor;
12+
import org.springframework.stereotype.Service;
13+
import org.springframework.transaction.annotation.Transactional;
14+
15+
@RequiredArgsConstructor
16+
@Transactional
17+
@Service
18+
public class WithdrawVolunteerApplyService implements WithdrawVolunteerApplyUseCase {
19+
20+
private final VolunteerApplyRepository volunteerApplyRepository;
21+
22+
@Override
23+
public void withdraw(Long id, UUID volunteerId) {
24+
VolunteerApply apply = getApply(id);
25+
validateVolunteerIdentity(apply, volunteerId);
26+
27+
apply.markAsDeleted();
28+
volunteerApplyRepository.save(apply);
29+
}
30+
31+
private VolunteerApply getApply(Long id) {
32+
return volunteerApplyRepository.findById(id).orElseThrow(
33+
() -> new BadRequestException(NOT_EXISTS_VOLUNTEER_APPLY)
34+
);
35+
}
36+
37+
private void validateVolunteerIdentity(VolunteerApply apply, UUID volunteerId) {
38+
if (apply.isOwnApplication(volunteerId)) {
39+
return;
40+
}
41+
42+
throw new BadRequestException(UNAUTHORIZED_VOLUNTEER_APPLY);
43+
}
44+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.somemore.volunteerapply.usecase;
2+
3+
import java.util.UUID;
4+
5+
public interface WithdrawVolunteerApplyUseCase {
6+
7+
void withdraw(Long id, UUID volunteerId);
8+
9+
}

0 commit comments

Comments
 (0)