Skip to content

Commit e5e280e

Browse files
committed
feat(recruit-board): 봉사 모집글 삭제 기능
1 parent 6134620 commit e5e280e

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.somemore.recruitboard.service.command;
2+
3+
import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_RECRUIT_BOARD;
4+
import static com.somemore.global.exception.ExceptionMessage.UNAUTHORIZED_RECRUIT_BOARD;
5+
6+
import com.somemore.global.exception.BadRequestException;
7+
import com.somemore.global.exception.ExceptionMessage;
8+
import com.somemore.recruitboard.domain.RecruitBoard;
9+
import com.somemore.recruitboard.repository.RecruitBoardRepository;
10+
import com.somemore.recruitboard.usecase.command.DeleteRecruitBoardUseCase;
11+
import java.util.UUID;
12+
import lombok.RequiredArgsConstructor;
13+
import org.springframework.stereotype.Service;
14+
import org.springframework.transaction.annotation.Transactional;
15+
16+
@RequiredArgsConstructor
17+
@Transactional
18+
@Service
19+
public class DeleteRecruitBoardService implements DeleteRecruitBoardUseCase {
20+
21+
private final RecruitBoardRepository recruitBoardRepository;
22+
23+
@Override
24+
public void deleteRecruitBoard(UUID centerId, Long recruitBoardId) {
25+
RecruitBoard recruitBoard = recruitBoardRepository.findById(recruitBoardId).orElseThrow(
26+
() -> new BadRequestException(NOT_EXISTS_RECRUIT_BOARD.getMessage())
27+
);
28+
29+
validateWriter(recruitBoard, centerId);
30+
31+
recruitBoard.markAsDeleted();
32+
recruitBoardRepository.save(recruitBoard);
33+
}
34+
35+
private void validateWriter(RecruitBoard recruitBoard, UUID centerId) {
36+
if (recruitBoard.isWriter(centerId)) {
37+
return;
38+
}
39+
40+
throw new BadRequestException(UNAUTHORIZED_RECRUIT_BOARD.getMessage());
41+
}
42+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.somemore.recruitboard.usecase.command;
2+
3+
import java.util.UUID;
4+
5+
public interface DeleteRecruitBoardUseCase {
6+
7+
public void deleteRecruitBoard(UUID centerId, Long recruitBoardId);
8+
}

0 commit comments

Comments
 (0)