Skip to content

Commit 88c4a05

Browse files
committed
refactor(recruit-board): 모집글 Validator 추가에 따른 리팩토링
1 parent 75b9093 commit 88c4a05

File tree

5 files changed

+42
-65
lines changed

5 files changed

+42
-65
lines changed
Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,35 @@
11
package com.somemore.domains.recruitboard.service.command;
22

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;
73
import com.somemore.domains.recruitboard.domain.RecruitBoard;
84
import com.somemore.domains.recruitboard.repository.RecruitBoardRepository;
5+
import com.somemore.domains.recruitboard.service.validator.RecruitBoardValidator;
96
import com.somemore.domains.recruitboard.usecase.command.DeleteRecruitBoardUseCase;
10-
import java.util.UUID;
7+
import com.somemore.global.exception.BadRequestException;
118
import lombok.RequiredArgsConstructor;
129
import org.springframework.stereotype.Service;
1310
import org.springframework.transaction.annotation.Transactional;
1411

12+
import java.util.UUID;
13+
14+
import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_RECRUIT_BOARD;
15+
1516
@RequiredArgsConstructor
1617
@Transactional
1718
@Service
1819
public class DeleteRecruitBoardService implements DeleteRecruitBoardUseCase {
1920

2021
private final RecruitBoardRepository recruitBoardRepository;
22+
private final RecruitBoardValidator recruitBoardValidator;
2123

2224
@Override
2325
public void deleteRecruitBoard(UUID centerId, Long recruitBoardId) {
2426
RecruitBoard recruitBoard = recruitBoardRepository.findById(recruitBoardId).orElseThrow(
25-
() -> new BadRequestException(NOT_EXISTS_RECRUIT_BOARD.getMessage())
27+
() -> new BadRequestException(NOT_EXISTS_RECRUIT_BOARD.getMessage())
2628
);
2729

28-
validateWriter(recruitBoard, centerId);
30+
recruitBoardValidator.validateAuthor(recruitBoard, centerId);
2931

3032
recruitBoard.markAsDeleted();
31-
recruitBoardRepository.save(recruitBoard);
3233
}
3334

34-
private void validateWriter(RecruitBoard recruitBoard, UUID centerId) {
35-
if (recruitBoard.isWriter(centerId)) {
36-
return;
37-
}
38-
39-
throw new BadRequestException(UNAUTHORIZED_RECRUIT_BOARD.getMessage());
40-
}
4135
}
Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,65 @@
11
package com.somemore.domains.recruitboard.service.command;
22

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;
73
import com.somemore.domains.location.usecase.command.UpdateLocationUseCase;
84
import com.somemore.domains.recruitboard.domain.RecruitBoard;
95
import com.somemore.domains.recruitboard.domain.RecruitStatus;
106
import com.somemore.domains.recruitboard.dto.request.RecruitBoardLocationUpdateRequestDto;
117
import com.somemore.domains.recruitboard.dto.request.RecruitBoardUpdateRequestDto;
128
import com.somemore.domains.recruitboard.repository.RecruitBoardRepository;
9+
import com.somemore.domains.recruitboard.service.validator.RecruitBoardValidator;
1310
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;
1612
import lombok.RequiredArgsConstructor;
1713
import org.springframework.stereotype.Service;
1814
import org.springframework.transaction.annotation.Transactional;
1915

16+
import java.time.LocalDateTime;
17+
import java.util.UUID;
18+
19+
import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_RECRUIT_BOARD;
2020

2121
@RequiredArgsConstructor
2222
@Transactional
2323
@Service
2424
public class UpdateRecruitBoardService implements UpdateRecruitBoardUseCase {
2525

2626
private final RecruitBoardRepository recruitBoardRepository;
27+
private final RecruitBoardValidator recruitBoardValidator;
2728
private final UpdateLocationUseCase updateLocationUseCase;
2829

2930
@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) {
3632
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());
3935

40-
recruitBoardRepository.save(recruitBoard);
36+
recruitBoard.updateWith(dto, imgUrl);
4137
}
4238

4339
@Override
44-
public void updateRecruitBoardLocation(RecruitBoardLocationUpdateRequestDto requestDto,
45-
Long recruitBoardId, UUID centerId) {
46-
40+
public void updateRecruitBoardLocation(RecruitBoardLocationUpdateRequestDto requestDto, Long recruitBoardId,
41+
UUID centerId) {
4742
RecruitBoard recruitBoard = getRecruitBoard(recruitBoardId);
48-
validateWriter(recruitBoard, centerId);
43+
recruitBoardValidator.validateAuthor(recruitBoard, centerId);
4944

50-
updateLocationUseCase.updateLocation(requestDto.toLocationUpdateRequestDto(),
51-
recruitBoard.getLocationId());
45+
updateLocationUseCase.updateLocation(requestDto.toLocationUpdateRequestDto(), recruitBoard.getLocationId());
5246

5347
recruitBoard.updateWith(requestDto.region());
54-
recruitBoardRepository.save(recruitBoard);
5548
}
5649

5750
@Override
5851
public void updateRecruitBoardStatus(RecruitStatus status, Long recruitBoardId, UUID centerId,
59-
LocalDateTime currentDateTime) {
52+
LocalDateTime currentDateTime) {
6053
RecruitBoard recruitBoard = getRecruitBoard(recruitBoardId);
61-
validateWriter(recruitBoard, centerId);
54+
recruitBoardValidator.validateAuthor(recruitBoard, centerId);
6255

6356
recruitBoard.changeRecruitStatus(status, currentDateTime);
64-
recruitBoardRepository.save(recruitBoard);
6557
}
6658

6759
private RecruitBoard getRecruitBoard(Long recruitBoardId) {
6860
return recruitBoardRepository.findById(recruitBoardId).orElseThrow(
69-
() -> new BadRequestException(NOT_EXISTS_RECRUIT_BOARD.getMessage())
61+
() -> new BadRequestException(NOT_EXISTS_RECRUIT_BOARD.getMessage())
7062
);
7163
}
7264

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-
}
8065
}

src/main/java/com/somemore/domains/volunteerapply/service/SettleVolunteerApplyFacadeService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public void settleVolunteerApplies(VolunteerApplySettleRequestDto dto, UUID cent
5252
}
5353

5454
private void validateAuth(RecruitBoard recruitBoard, UUID centerId) {
55-
if (recruitBoard.isWriter(centerId)) {
55+
if (recruitBoard.isAuthor(centerId)) {
5656
return;
5757
}
5858
throw new BadRequestException(UNAUTHORIZED_RECRUIT_BOARD);

src/main/java/com/somemore/domains/volunteerapply/service/VolunteerApplyQueryFacadeService.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
package com.somemore.domains.volunteerapply.service;
22

3-
import static com.somemore.global.exception.ExceptionMessage.UNAUTHORIZED_RECRUIT_BOARD;
4-
53
import com.somemore.domains.recruitboard.domain.RecruitBoard;
64
import com.somemore.domains.recruitboard.usecase.query.RecruitBoardQueryUseCase;
5+
import com.somemore.domains.volunteer.repository.mapper.VolunteerSimpleInfo;
76
import com.somemore.domains.volunteer.usecase.VolunteerQueryUseCase;
7+
import com.somemore.domains.volunteerapply.domain.VolunteerApply;
88
import com.somemore.domains.volunteerapply.dto.condition.VolunteerApplySearchCondition;
99
import com.somemore.domains.volunteerapply.dto.response.VolunteerApplyRecruitInfoResponseDto;
1010
import com.somemore.domains.volunteerapply.dto.response.VolunteerApplyVolunteerInfoResponseDto;
1111
import com.somemore.domains.volunteerapply.usecase.VolunteerApplyQueryFacadeUseCase;
1212
import com.somemore.domains.volunteerapply.usecase.VolunteerApplyQueryUseCase;
1313
import com.somemore.global.exception.BadRequestException;
14-
import com.somemore.domains.volunteer.repository.mapper.VolunteerSimpleInfo;
15-
import com.somemore.domains.volunteerapply.domain.VolunteerApply;
14+
import lombok.RequiredArgsConstructor;
15+
import org.springframework.data.domain.Page;
16+
import org.springframework.stereotype.Service;
17+
import org.springframework.transaction.annotation.Transactional;
1618

1719
import java.util.List;
1820
import java.util.Map;
1921
import java.util.UUID;
2022
import java.util.stream.Collectors;
21-
import lombok.RequiredArgsConstructor;
22-
import org.springframework.data.domain.Page;
23-
import org.springframework.stereotype.Service;
24-
import org.springframework.transaction.annotation.Transactional;
23+
24+
import static com.somemore.global.exception.ExceptionMessage.UNAUTHORIZED_RECRUIT_BOARD;
2525

2626
@RequiredArgsConstructor
2727
@Transactional(readOnly = true)
@@ -68,7 +68,7 @@ public Page<VolunteerApplyRecruitInfoResponseDto> getVolunteerAppliesByVolunteer
6868

6969
private void validateAuthorization(Long recruitId, UUID centerId) {
7070
RecruitBoard recruitBoard = recruitBoardQueryUseCase.getById(recruitId);
71-
if (recruitBoard.isWriter(centerId)) {
71+
if (recruitBoard.isAuthor(centerId)) {
7272
return;
7373
}
7474

src/main/java/com/somemore/domains/volunteerapply/service/VolunteerApplyStatusChangeService.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,23 @@
22

33
import com.somemore.domains.recruitboard.domain.RecruitBoard;
44
import com.somemore.domains.recruitboard.usecase.query.RecruitBoardQueryUseCase;
5+
import com.somemore.domains.volunteerapply.domain.ApplyStatus;
6+
import com.somemore.domains.volunteerapply.domain.VolunteerApply;
57
import com.somemore.domains.volunteerapply.event.VolunteerApplyStatusChangeEvent;
68
import com.somemore.domains.volunteerapply.repository.VolunteerApplyRepository;
79
import com.somemore.domains.volunteerapply.usecase.ApproveVolunteerApplyUseCase;
810
import com.somemore.domains.volunteerapply.usecase.RejectVolunteerApplyUseCase;
911
import com.somemore.global.common.event.ServerEventPublisher;
1012
import com.somemore.global.exception.BadRequestException;
11-
import com.somemore.domains.volunteerapply.domain.ApplyStatus;
12-
import com.somemore.domains.volunteerapply.domain.VolunteerApply;
1313
import lombok.RequiredArgsConstructor;
1414
import org.springframework.stereotype.Service;
1515
import org.springframework.transaction.annotation.Transactional;
1616

1717
import java.util.UUID;
1818

19-
import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_VOLUNTEER_APPLY;
20-
import static com.somemore.global.exception.ExceptionMessage.RECRUIT_BOARD_ALREADY_COMPLETED;
21-
import static com.somemore.global.exception.ExceptionMessage.UNAUTHORIZED_RECRUIT_BOARD;
2219
import static com.somemore.domains.volunteerapply.domain.ApplyStatus.APPROVED;
2320
import static com.somemore.domains.volunteerapply.domain.ApplyStatus.REJECTED;
21+
import static com.somemore.global.exception.ExceptionMessage.*;
2422

2523
@RequiredArgsConstructor
2624
@Transactional
@@ -61,7 +59,7 @@ private VolunteerApply getVolunteerApply(Long id) {
6159
}
6260

6361
private void validateWriter(RecruitBoard recruitBoard, UUID centerId) {
64-
if (recruitBoard.isWriter(centerId)) {
62+
if (recruitBoard.isAuthor(centerId)) {
6563
return;
6664
}
6765
throw new BadRequestException(UNAUTHORIZED_RECRUIT_BOARD);
@@ -81,4 +79,4 @@ private void publishVolunteerApplyStatusChangeEvent(VolunteerApply apply,
8179
}
8280
serverEventPublisher.publish(VolunteerApplyStatusChangeEvent.from(apply, recruitBoard, oldStatus));
8381
}
84-
}
82+
}

0 commit comments

Comments
 (0)