|
1 | 1 | package com.somemore.domains.recruitboard.service.command; |
2 | 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 | 3 | import com.somemore.domains.location.usecase.command.UpdateLocationUseCase; |
8 | 4 | import com.somemore.domains.recruitboard.domain.RecruitBoard; |
9 | 5 | import com.somemore.domains.recruitboard.domain.RecruitStatus; |
10 | 6 | import com.somemore.domains.recruitboard.dto.request.RecruitBoardLocationUpdateRequestDto; |
11 | 7 | import com.somemore.domains.recruitboard.dto.request.RecruitBoardUpdateRequestDto; |
12 | 8 | import com.somemore.domains.recruitboard.repository.RecruitBoardRepository; |
| 9 | +import com.somemore.domains.recruitboard.service.validator.RecruitBoardValidator; |
13 | 10 | import com.somemore.domains.recruitboard.usecase.command.UpdateRecruitBoardUseCase; |
14 | | -import java.time.LocalDateTime; |
15 | | -import java.util.UUID; |
| 11 | +import com.somemore.global.exception.BadRequestException; |
16 | 12 | import lombok.RequiredArgsConstructor; |
17 | 13 | import org.springframework.stereotype.Service; |
18 | 14 | import org.springframework.transaction.annotation.Transactional; |
19 | 15 |
|
| 16 | +import java.time.LocalDateTime; |
| 17 | +import java.util.UUID; |
| 18 | + |
| 19 | +import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_RECRUIT_BOARD; |
20 | 20 |
|
21 | 21 | @RequiredArgsConstructor |
22 | 22 | @Transactional |
23 | 23 | @Service |
24 | 24 | public class UpdateRecruitBoardService implements UpdateRecruitBoardUseCase { |
25 | 25 |
|
26 | 26 | private final RecruitBoardRepository recruitBoardRepository; |
| 27 | + private final RecruitBoardValidator recruitBoardValidator; |
27 | 28 | private final UpdateLocationUseCase updateLocationUseCase; |
28 | 29 |
|
29 | 30 | @Override |
30 | | - public void updateRecruitBoard( |
31 | | - RecruitBoardUpdateRequestDto requestDto, |
32 | | - Long recruitBoardId, |
33 | | - UUID centerId, |
34 | | - String imgUrl) { |
35 | | - |
| 31 | + public void updateRecruitBoard(RecruitBoardUpdateRequestDto dto, Long recruitBoardId, UUID centerId, String imgUrl) { |
36 | 32 | RecruitBoard recruitBoard = getRecruitBoard(recruitBoardId); |
37 | | - validateWriter(recruitBoard, centerId); |
38 | | - recruitBoard.updateWith(requestDto, imgUrl); |
| 33 | + recruitBoardValidator.validateAuthor(recruitBoard, centerId); |
| 34 | + recruitBoardValidator.validateRecruitBoardTime(dto.volunteerStartDateTime(), dto.volunteerEndDateTime()); |
39 | 35 |
|
40 | | - recruitBoardRepository.save(recruitBoard); |
| 36 | + recruitBoard.updateWith(dto, imgUrl); |
41 | 37 | } |
42 | 38 |
|
43 | 39 | @Override |
44 | | - public void updateRecruitBoardLocation(RecruitBoardLocationUpdateRequestDto requestDto, |
45 | | - Long recruitBoardId, UUID centerId) { |
46 | | - |
| 40 | + public void updateRecruitBoardLocation(RecruitBoardLocationUpdateRequestDto requestDto, Long recruitBoardId, |
| 41 | + UUID centerId) { |
47 | 42 | RecruitBoard recruitBoard = getRecruitBoard(recruitBoardId); |
48 | | - validateWriter(recruitBoard, centerId); |
| 43 | + recruitBoardValidator.validateAuthor(recruitBoard, centerId); |
49 | 44 |
|
50 | | - updateLocationUseCase.updateLocation(requestDto.toLocationUpdateRequestDto(), |
51 | | - recruitBoard.getLocationId()); |
| 45 | + updateLocationUseCase.updateLocation(requestDto.toLocationUpdateRequestDto(), recruitBoard.getLocationId()); |
52 | 46 |
|
53 | 47 | recruitBoard.updateWith(requestDto.region()); |
54 | | - recruitBoardRepository.save(recruitBoard); |
55 | 48 | } |
56 | 49 |
|
57 | 50 | @Override |
58 | 51 | public void updateRecruitBoardStatus(RecruitStatus status, Long recruitBoardId, UUID centerId, |
59 | | - LocalDateTime currentDateTime) { |
| 52 | + LocalDateTime currentDateTime) { |
60 | 53 | RecruitBoard recruitBoard = getRecruitBoard(recruitBoardId); |
61 | | - validateWriter(recruitBoard, centerId); |
| 54 | + recruitBoardValidator.validateAuthor(recruitBoard, centerId); |
62 | 55 |
|
63 | 56 | recruitBoard.changeRecruitStatus(status, currentDateTime); |
64 | | - recruitBoardRepository.save(recruitBoard); |
65 | 57 | } |
66 | 58 |
|
67 | 59 | private RecruitBoard getRecruitBoard(Long recruitBoardId) { |
68 | 60 | return recruitBoardRepository.findById(recruitBoardId).orElseThrow( |
69 | | - () -> new BadRequestException(NOT_EXISTS_RECRUIT_BOARD.getMessage()) |
| 61 | + () -> new BadRequestException(NOT_EXISTS_RECRUIT_BOARD.getMessage()) |
70 | 62 | ); |
71 | 63 | } |
72 | 64 |
|
73 | | - private void validateWriter(RecruitBoard recruitBoard, UUID centerId) { |
74 | | - if (recruitBoard.isWriter(centerId)) { |
75 | | - return; |
76 | | - } |
77 | | - |
78 | | - throw new BadRequestException(UNAUTHORIZED_RECRUIT_BOARD.getMessage()); |
79 | | - } |
80 | 65 | } |
0 commit comments