Skip to content

Commit 8a65a51

Browse files
committed
refactor(recruit-board): 모집글 조회시 QueryUseCase 의존하도록 리팩토링
1 parent bb47aa4 commit 8a65a51

File tree

5 files changed

+19
-47
lines changed

5 files changed

+19
-47
lines changed

src/main/java/com/somemore/domains/recruitboard/service/command/DeleteRecruitBoardService.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.somemore.domains.recruitboard.repository.RecruitBoardRepository;
55
import com.somemore.domains.recruitboard.service.validator.RecruitBoardValidator;
66
import com.somemore.domains.recruitboard.usecase.command.DeleteRecruitBoardUseCase;
7+
import com.somemore.domains.recruitboard.usecase.query.RecruitBoardQueryUseCase;
78
import com.somemore.global.exception.BadRequestException;
89
import lombok.RequiredArgsConstructor;
910
import org.springframework.stereotype.Service;
@@ -18,15 +19,12 @@
1819
@Service
1920
public class DeleteRecruitBoardService implements DeleteRecruitBoardUseCase {
2021

21-
private final RecruitBoardRepository recruitBoardRepository;
22+
private final RecruitBoardQueryUseCase recruitBoardQueryUseCase;
2223
private final RecruitBoardValidator recruitBoardValidator;
2324

2425
@Override
25-
public void deleteRecruitBoard(UUID centerId, Long recruitBoardId) {
26-
RecruitBoard recruitBoard = recruitBoardRepository.findById(recruitBoardId).orElseThrow(
27-
() -> new BadRequestException(NOT_EXISTS_RECRUIT_BOARD.getMessage())
28-
);
29-
26+
public void deleteRecruitBoard(UUID centerId, Long id) {
27+
RecruitBoard recruitBoard = recruitBoardQueryUseCase.getById(id);
3028
recruitBoardValidator.validateAuthor(recruitBoard, centerId);
3129

3230
recruitBoard.markAsDeleted();

src/main/java/com/somemore/domains/recruitboard/service/command/UpdateRecruitBoardService.java

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,37 @@
55
import com.somemore.domains.recruitboard.domain.RecruitStatus;
66
import com.somemore.domains.recruitboard.dto.request.RecruitBoardLocationUpdateRequestDto;
77
import com.somemore.domains.recruitboard.dto.request.RecruitBoardUpdateRequestDto;
8-
import com.somemore.domains.recruitboard.repository.RecruitBoardRepository;
98
import com.somemore.domains.recruitboard.service.validator.RecruitBoardValidator;
109
import com.somemore.domains.recruitboard.usecase.command.UpdateRecruitBoardUseCase;
11-
import com.somemore.global.exception.BadRequestException;
10+
import com.somemore.domains.recruitboard.usecase.query.RecruitBoardQueryUseCase;
1211
import lombok.RequiredArgsConstructor;
1312
import org.springframework.stereotype.Service;
1413
import org.springframework.transaction.annotation.Transactional;
1514

1615
import java.time.LocalDateTime;
1716
import java.util.UUID;
1817

19-
import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_RECRUIT_BOARD;
20-
2118
@RequiredArgsConstructor
2219
@Transactional
2320
@Service
2421
public class UpdateRecruitBoardService implements UpdateRecruitBoardUseCase {
2522

26-
private final RecruitBoardRepository recruitBoardRepository;
27-
private final RecruitBoardValidator recruitBoardValidator;
23+
private final RecruitBoardQueryUseCase recruitBoardQueryUseCase;
2824
private final UpdateLocationUseCase updateLocationUseCase;
25+
private final RecruitBoardValidator recruitBoardValidator;
2926

3027
@Override
31-
public void updateRecruitBoard(RecruitBoardUpdateRequestDto dto, Long recruitBoardId, UUID centerId, String imgUrl) {
32-
RecruitBoard recruitBoard = getRecruitBoard(recruitBoardId);
28+
public void updateRecruitBoard(RecruitBoardUpdateRequestDto dto, Long id, UUID centerId, String imgUrl) {
29+
RecruitBoard recruitBoard = recruitBoardQueryUseCase.getById(id);
3330
recruitBoardValidator.validateAuthor(recruitBoard, centerId);
3431
recruitBoardValidator.validateRecruitBoardTime(dto.volunteerStartDateTime(), dto.volunteerEndDateTime());
3532

3633
recruitBoard.updateWith(dto, imgUrl);
3734
}
3835

3936
@Override
40-
public void updateRecruitBoardLocation(RecruitBoardLocationUpdateRequestDto requestDto, Long recruitBoardId,
41-
UUID centerId) {
42-
RecruitBoard recruitBoard = getRecruitBoard(recruitBoardId);
37+
public void updateRecruitBoardLocation(RecruitBoardLocationUpdateRequestDto requestDto, Long id, UUID centerId) {
38+
RecruitBoard recruitBoard = recruitBoardQueryUseCase.getById(id);
4339
recruitBoardValidator.validateAuthor(recruitBoard, centerId);
4440

4541
updateLocationUseCase.updateLocation(requestDto.toLocationUpdateRequestDto(), recruitBoard.getLocationId());
@@ -48,18 +44,11 @@ public void updateRecruitBoardLocation(RecruitBoardLocationUpdateRequestDto requ
4844
}
4945

5046
@Override
51-
public void updateRecruitBoardStatus(RecruitStatus status, Long recruitBoardId, UUID centerId,
52-
LocalDateTime currentDateTime) {
53-
RecruitBoard recruitBoard = getRecruitBoard(recruitBoardId);
47+
public void updateRecruitBoardStatus(RecruitStatus status, Long id, UUID centerId, LocalDateTime currentDateTime) {
48+
RecruitBoard recruitBoard = recruitBoardQueryUseCase.getById(id);
5449
recruitBoardValidator.validateAuthor(recruitBoard, centerId);
5550

5651
recruitBoard.changeRecruitStatus(status, currentDateTime);
5752
}
5853

59-
private RecruitBoard getRecruitBoard(Long recruitBoardId) {
60-
return recruitBoardRepository.findById(recruitBoardId).orElseThrow(
61-
() -> new BadRequestException(NOT_EXISTS_RECRUIT_BOARD.getMessage())
62-
);
63-
}
64-
6554
}

src/main/java/com/somemore/domains/recruitboard/service/validator/RecruitBoardValidator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ public void validateAuthor(RecruitBoard recruitBoard, UUID centerId) {
2626
return;
2727
}
2828

29-
throw new BadRequestException(UNAUTHORIZED_RECRUIT_BOARD.getMessage());
29+
throw new BadRequestException(UNAUTHORIZED_RECRUIT_BOARD);
3030
}
3131
}

src/main/java/com/somemore/domains/recruitboard/usecase/command/DeleteRecruitBoardUseCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44

55
public interface DeleteRecruitBoardUseCase {
66

7-
void deleteRecruitBoard(UUID centerId, Long recruitBoardId);
7+
void deleteRecruitBoard(UUID centerId, Long id);
88
}

src/main/java/com/somemore/domains/recruitboard/usecase/command/UpdateRecruitBoardUseCase.java

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,14 @@
33
import com.somemore.domains.recruitboard.domain.RecruitStatus;
44
import com.somemore.domains.recruitboard.dto.request.RecruitBoardLocationUpdateRequestDto;
55
import com.somemore.domains.recruitboard.dto.request.RecruitBoardUpdateRequestDto;
6+
67
import java.time.LocalDateTime;
78
import java.util.UUID;
89

910
public interface UpdateRecruitBoardUseCase {
11+
void updateRecruitBoard(RecruitBoardUpdateRequestDto requestDto, Long id, UUID centerId, String imgUrl);
1012

11-
void updateRecruitBoard(
12-
RecruitBoardUpdateRequestDto requestDto,
13-
Long recruitBoardId,
14-
UUID centerId,
15-
String imgUrl
16-
);
17-
18-
void updateRecruitBoardLocation(
19-
RecruitBoardLocationUpdateRequestDto requestDto,
20-
Long recruitBoardId,
21-
UUID centerId
22-
);
23-
24-
void updateRecruitBoardStatus(
25-
RecruitStatus status,
26-
Long recruitBoardId,
27-
UUID centerId,
28-
LocalDateTime currentDateTime
29-
);
13+
void updateRecruitBoardLocation(RecruitBoardLocationUpdateRequestDto requestDto, Long id, UUID centerId);
3014

15+
void updateRecruitBoardStatus(RecruitStatus status, Long id, UUID centerId, LocalDateTime currentDateTime);
3116
}

0 commit comments

Comments
 (0)