|
| 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 | +} |
0 commit comments