Skip to content

Commit e085aed

Browse files
committed
refactor(recruit-board): 시간 검증 로직 변경
- Service 계층에서 Clock 사용
1 parent b8b4c81 commit e085aed

File tree

3 files changed

+29
-32
lines changed

3 files changed

+29
-32
lines changed

src/main/java/com/somemore/domains/recruitboard/controller/RecruitBoardCommandApiController.java

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.somemore.domains.recruitboard.controller;
22

33

4+
import static org.springframework.http.MediaType.MULTIPART_FORM_DATA_VALUE;
5+
46
import com.somemore.domains.recruitboard.dto.request.RecruitBoardCreateRequestDto;
57
import com.somemore.domains.recruitboard.dto.request.RecruitBoardLocationUpdateRequestDto;
68
import com.somemore.domains.recruitboard.dto.request.RecruitBoardStatusUpdateRequestDto;
@@ -15,16 +17,20 @@
1517
import io.swagger.v3.oas.annotations.Operation;
1618
import io.swagger.v3.oas.annotations.tags.Tag;
1719
import jakarta.validation.Valid;
20+
import java.util.UUID;
1821
import lombok.RequiredArgsConstructor;
1922
import org.springframework.security.access.annotation.Secured;
20-
import org.springframework.web.bind.annotation.*;
23+
import org.springframework.web.bind.annotation.DeleteMapping;
24+
import org.springframework.web.bind.annotation.PatchMapping;
25+
import org.springframework.web.bind.annotation.PathVariable;
26+
import org.springframework.web.bind.annotation.PostMapping;
27+
import org.springframework.web.bind.annotation.PutMapping;
28+
import org.springframework.web.bind.annotation.RequestBody;
29+
import org.springframework.web.bind.annotation.RequestMapping;
30+
import org.springframework.web.bind.annotation.RequestPart;
31+
import org.springframework.web.bind.annotation.RestController;
2132
import org.springframework.web.multipart.MultipartFile;
2233

23-
import java.time.LocalDateTime;
24-
import java.util.UUID;
25-
26-
import static org.springframework.http.MediaType.MULTIPART_FORM_DATA_VALUE;
27-
2834
@Tag(name = "Recruit Board Command API", description = "봉사 활동 모집글 생성 수정 삭제 API")
2935
@RequiredArgsConstructor
3036
@RequestMapping("/api")
@@ -44,7 +50,6 @@ public ApiResponse<Long> createRecruitBoard(
4450
@Valid @RequestPart("data") RecruitBoardCreateRequestDto requestDto,
4551
@RequestPart(value = "img_file", required = false) MultipartFile image
4652
) {
47-
4853
String imgUrl = imageUploadUseCase.uploadImage(new ImageUploadRequestDto(image));
4954
return ApiResponse.ok(
5055
201,
@@ -63,9 +68,7 @@ public ApiResponse<String> updateRecruitBoard(
6368
@RequestPart(value = "img_file", required = false) MultipartFile image
6469
) {
6570
String imgUrl = imageUploadUseCase.uploadImage(new ImageUploadRequestDto(image));
66-
LocalDateTime now = LocalDateTime.now();
67-
updateRecruitBoardUseCase.updateRecruitBoard(requestDto, id, userId, imgUrl, now);
68-
71+
updateRecruitBoardUseCase.updateRecruitBoard(requestDto, id, userId, imgUrl);
6972
return ApiResponse.ok("봉사 활동 모집글 수정 성공");
7073
}
7174

@@ -77,8 +80,7 @@ public ApiResponse<String> updateRecruitBoardLocation(
7780
@PathVariable Long id,
7881
@Valid @RequestBody RecruitBoardLocationUpdateRequestDto requestDto
7982
) {
80-
LocalDateTime now = LocalDateTime.now();
81-
updateRecruitBoardUseCase.updateRecruitBoardLocation(requestDto, id, userId, now);
83+
updateRecruitBoardUseCase.updateRecruitBoardLocation(requestDto, id, userId);
8284
return ApiResponse.ok("봉사 활동 모집글 위치 수정 성공");
8385
}
8486

@@ -90,9 +92,7 @@ public ApiResponse<String> updateRecruitBoardStatus(
9092
@PathVariable Long id,
9193
@RequestBody RecruitBoardStatusUpdateRequestDto requestDto
9294
) {
93-
LocalDateTime now = LocalDateTime.now();
94-
updateRecruitBoardUseCase.updateRecruitBoardStatus(requestDto.status(), id, userId, now);
95-
95+
updateRecruitBoardUseCase.updateRecruitBoardStatus(requestDto.status(), id, userId);
9696
return ApiResponse.ok("봉사 활동 모집글 상태 수정 성공");
9797
}
9898

@@ -106,5 +106,4 @@ public ApiResponse<String> deleteRecruitBoard(
106106
deleteRecruitBoardUseCase.deleteRecruitBoard(userId, id);
107107
return ApiResponse.ok("봉사 활동 모집글 삭제 성공");
108108
}
109-
110109
}

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.somemore.domains.recruitboard.service.validator.RecruitBoardValidator;
99
import com.somemore.domains.recruitboard.usecase.RecruitBoardQueryUseCase;
1010
import com.somemore.domains.recruitboard.usecase.UpdateRecruitBoardUseCase;
11+
import java.time.Clock;
1112
import java.time.LocalDateTime;
1213
import java.util.UUID;
1314
import lombok.RequiredArgsConstructor;
@@ -22,12 +23,13 @@ public class UpdateRecruitBoardService implements UpdateRecruitBoardUseCase {
2223
private final RecruitBoardQueryUseCase recruitBoardQueryUseCase;
2324
private final UpdateLocationUseCase updateLocationUseCase;
2425
private final RecruitBoardValidator recruitBoardValidator;
26+
private final Clock clock;
2527

2628
@Override
2729
public void updateRecruitBoard(RecruitBoardUpdateRequestDto dto, Long id, UUID centerId,
28-
String imgUrl, LocalDateTime current) {
30+
String imgUrl) {
2931
RecruitBoard recruitBoard = getRecruitBoard(id);
30-
validateUpdatableAndWriter(recruitBoard, centerId, current);
32+
validateUpdatableAndWriter(recruitBoard, centerId);
3133

3234
recruitBoardValidator.validateUpdateRecruitBoardTime(recruitBoard.getCreatedAt(),
3335
dto.volunteerStartDateTime(), dto.volunteerEndDateTime());
@@ -37,27 +39,26 @@ public void updateRecruitBoard(RecruitBoardUpdateRequestDto dto, Long id, UUID c
3739

3840
@Override
3941
public void updateRecruitBoardLocation(RecruitBoardLocationUpdateRequestDto requestDto, Long id,
40-
UUID centerId, LocalDateTime current) {
42+
UUID centerId) {
4143
RecruitBoard recruitBoard = getRecruitBoard(id);
42-
validateUpdatableAndWriter(recruitBoard, centerId, current);
44+
validateUpdatableAndWriter(recruitBoard, centerId);
4345

4446
updateLocationUseCase.updateLocation(requestDto.toLocationUpdateRequestDto(),
4547
recruitBoard.getLocationId());
4648
recruitBoard.updateWith(requestDto.region());
4749
}
4850

4951
@Override
50-
public void updateRecruitBoardStatus(RecruitStatus status, Long id, UUID centerId,
51-
LocalDateTime current) {
52+
public void updateRecruitBoardStatus(RecruitStatus status, Long id, UUID centerId) {
5253
RecruitBoard recruitBoard = getRecruitBoard(id);
53-
validateUpdatableAndWriter(recruitBoard, centerId, current);
54+
validateUpdatableAndWriter(recruitBoard, centerId);
5455
recruitBoardValidator.validateRecruitStatus(status);
5556

5657
recruitBoard.updateRecruitStatus(status);
5758
}
5859

59-
private void validateUpdatableAndWriter(RecruitBoard recruitBoard, UUID centerId,
60-
LocalDateTime current) {
60+
private void validateUpdatableAndWriter(RecruitBoard recruitBoard, UUID centerId) {
61+
LocalDateTime current = LocalDateTime.now(clock);
6162
recruitBoardValidator.validateUpdatable(recruitBoard, current);
6263
recruitBoardValidator.validateWriter(recruitBoard, centerId);
6364
}

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,15 @@
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-
import java.time.LocalDateTime;
76
import java.util.UUID;
87

98
public interface UpdateRecruitBoardUseCase {
109

11-
void updateRecruitBoard(RecruitBoardUpdateRequestDto dto, Long id, UUID centerId, String imgUrl,
12-
LocalDateTime current);
13-
10+
void updateRecruitBoard(RecruitBoardUpdateRequestDto dto, Long id, UUID centerId,
11+
String imgUrl);
1412

1513
void updateRecruitBoardLocation(RecruitBoardLocationUpdateRequestDto requestDto, Long id,
16-
UUID centerId, LocalDateTime current);
14+
UUID centerId);
1715

18-
void updateRecruitBoardStatus(RecruitStatus status, Long id, UUID centerId,
19-
LocalDateTime currentDateTime);
16+
void updateRecruitBoardStatus(RecruitStatus status, Long id, UUID centerId);
2017
}

0 commit comments

Comments
 (0)