Skip to content

Commit 3b7666f

Browse files
authored
[REFACTOR] 새로운 테이블에 따른 봉사지원 리팩토링 (#322)
* refactor(volunteer-apply): @currentuser -> @RoleId 변경 * test(volunteer-apply): @currentuser -> @RoleId 변경 테스트 * refactor(volunteer): 봉사 시간, 횟수 정산 NewVolunteer 추가 * test(volunteer-apply): 봉사 시간, 횟수 정산 NewVolunteer 추가 테스트 * test(volunteer): sonar qube 이슈 해결 커버리지 테스트 추가 * test(volunteer): sonar qube 이슈 해결 커버리지 테스트 추가 * chore(volunteer): 불필요한 import 제거
1 parent fa1eaf6 commit 3b7666f

13 files changed

+303
-178
lines changed

src/main/java/com/somemore/domains/volunteerapply/controller/CenterVolunteerApplyCommandApiController.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
import com.somemore.domains.volunteerapply.usecase.ApproveVolunteerApplyUseCase;
55
import com.somemore.domains.volunteerapply.usecase.RejectVolunteerApplyUseCase;
66
import com.somemore.domains.volunteerapply.usecase.SettleVolunteerApplyFacadeUseCase;
7-
import com.somemore.global.auth.annotation.CurrentUser;
7+
import com.somemore.global.auth.annotation.RoleId;
88
import com.somemore.global.common.response.ApiResponse;
99
import io.swagger.v3.oas.annotations.Operation;
1010
import io.swagger.v3.oas.annotations.tags.Tag;
1111
import jakarta.validation.Valid;
12+
import java.util.UUID;
1213
import lombok.RequiredArgsConstructor;
1314
import org.springframework.security.access.annotation.Secured;
1415
import org.springframework.web.bind.annotation.PatchMapping;
@@ -18,8 +19,6 @@
1819
import org.springframework.web.bind.annotation.RequestMapping;
1920
import org.springframework.web.bind.annotation.RestController;
2021

21-
import java.util.UUID;
22-
2322
@Tag(name = "Center Volunteer Apply Command API", description = "봉사 활동 지원 승인, 거절, 정산 API")
2423
@RequiredArgsConstructor
2524
@RequestMapping("/api")
@@ -34,7 +33,7 @@ public class CenterVolunteerApplyCommandApiController {
3433
@Operation(summary = "봉사 활동 지원 승인", description = "봉사 활동 지원을 승인합니다.")
3534
@PatchMapping("/volunteer-apply/{id}/approve")
3635
public ApiResponse<String> approve(
37-
@CurrentUser UUID centerId,
36+
@RoleId UUID centerId,
3837
@PathVariable Long id
3938
) {
4039

@@ -46,7 +45,7 @@ public ApiResponse<String> approve(
4645
@Operation(summary = "봉사 활동 지원 거절", description = "봉사 활동 지원을 거절합니다.")
4746
@PatchMapping("/volunteer-apply/{id}/reject")
4847
public ApiResponse<String> reject(
49-
@CurrentUser UUID centerId,
48+
@RoleId UUID centerId,
5049
@PathVariable Long id
5150
) {
5251

@@ -58,7 +57,7 @@ public ApiResponse<String> reject(
5857
@Operation(summary = "봉사 활동 지원 정산", description = "봉사 활동 지원을 정산(참석 처리, 봉사 시간 부여)합니다.")
5958
@PostMapping("/volunteer-applies/settle")
6059
public ApiResponse<String> settle(
61-
@CurrentUser UUID centerId,
60+
@RoleId UUID centerId,
6261
@Valid @RequestBody VolunteerApplySettleRequestDto requestDto
6362
) {
6463
settleVolunteerApplyFacadeUseCase.settleVolunteerApplies(requestDto, centerId);

src/main/java/com/somemore/domains/volunteerapply/controller/VolunteerApplyCommandApiController.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
import com.somemore.domains.volunteerapply.dto.request.VolunteerApplyCreateRequestDto;
44
import com.somemore.domains.volunteerapply.usecase.ApplyVolunteerApplyUseCase;
55
import com.somemore.domains.volunteerapply.usecase.WithdrawVolunteerApplyUseCase;
6-
import com.somemore.global.auth.annotation.CurrentUser;
6+
import com.somemore.global.auth.annotation.RoleId;
77
import com.somemore.global.common.response.ApiResponse;
88
import io.swagger.v3.oas.annotations.Operation;
99
import io.swagger.v3.oas.annotations.tags.Tag;
1010
import jakarta.validation.Valid;
11+
import java.util.UUID;
1112
import lombok.RequiredArgsConstructor;
1213
import org.springframework.security.access.annotation.Secured;
1314
import org.springframework.web.bind.annotation.DeleteMapping;
@@ -17,8 +18,6 @@
1718
import org.springframework.web.bind.annotation.RequestMapping;
1819
import org.springframework.web.bind.annotation.RestController;
1920

20-
import java.util.UUID;
21-
2221
@Tag(name = "Volunteer Apply Command API", description = "봉사 활동 지원, 철회 관련 API")
2322
@RequiredArgsConstructor
2423
@RequestMapping("/api")
@@ -32,7 +31,7 @@ public class VolunteerApplyCommandApiController {
3231
@Operation(summary = "봉사 활동 지원", description = "봉사 활동에 지원합니다.")
3332
@PostMapping("/volunteer-apply")
3433
public ApiResponse<Long> apply(
35-
@CurrentUser UUID volunteerId,
34+
@RoleId UUID volunteerId,
3635
@Valid @RequestBody VolunteerApplyCreateRequestDto requestDto
3736
) {
3837
return ApiResponse.ok(
@@ -46,7 +45,7 @@ public ApiResponse<Long> apply(
4645
@Operation(summary = "봉사 활동 지원 철회", description = "봉사 활동 지원을 철회합니다.")
4746
@DeleteMapping("/volunteer-apply/{id}")
4847
public ApiResponse<String> withdraw(
49-
@CurrentUser UUID volunteerId,
48+
@RoleId UUID volunteerId,
5049
@PathVariable Long id
5150
) {
5251
withdrawVolunteerApplyUseCase.withdraw(id, volunteerId);

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

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

3+
import static com.somemore.global.exception.ExceptionMessage.RECRUIT_BOARD_ID_MISMATCH;
4+
import static com.somemore.global.exception.ExceptionMessage.UNAUTHORIZED_RECRUIT_BOARD;
5+
import static com.somemore.global.exception.ExceptionMessage.VOLUNTEER_APPLY_LIST_MISMATCH;
6+
37
import com.somemore.domains.notification.domain.NotificationSubType;
48
import com.somemore.domains.recruitboard.domain.RecruitBoard;
59
import com.somemore.domains.recruitboard.usecase.RecruitBoardQueryUseCase;
6-
import com.somemore.domains.volunteer.usecase.UpdateVolunteerUseCase;
710
import com.somemore.domains.volunteerapply.domain.VolunteerApply;
811
import com.somemore.domains.volunteerapply.dto.request.VolunteerApplySettleRequestDto;
912
import com.somemore.domains.volunteerapply.event.VolunteerReviewRequestEvent;
@@ -13,17 +16,13 @@
1316
import com.somemore.global.common.event.ServerEventPublisher;
1417
import com.somemore.global.common.event.ServerEventType;
1518
import com.somemore.global.exception.BadRequestException;
19+
import com.somemore.volunteer.usecase.UpdateVolunteerUseCase;
20+
import java.util.List;
21+
import java.util.UUID;
1622
import lombok.RequiredArgsConstructor;
1723
import org.springframework.stereotype.Service;
1824
import org.springframework.transaction.annotation.Transactional;
1925

20-
import java.util.List;
21-
import java.util.UUID;
22-
23-
import static com.somemore.global.exception.ExceptionMessage.RECRUIT_BOARD_ID_MISMATCH;
24-
import static com.somemore.global.exception.ExceptionMessage.UNAUTHORIZED_RECRUIT_BOARD;
25-
import static com.somemore.global.exception.ExceptionMessage.VOLUNTEER_APPLY_LIST_MISMATCH;
26-
2726
@RequiredArgsConstructor
2827
@Transactional
2928
@Service
@@ -71,7 +70,7 @@ private void validateVolunteerApplyExistence(List<Long> ids, List<VolunteerApply
7170
}
7271

7372
private void validateRecruitBoardConsistency(List<VolunteerApply> applies,
74-
Long recruitBoardId) {
73+
Long recruitBoardId) {
7574
boolean anyMismatch = applies.stream()
7675
.anyMatch(apply -> !apply.getRecruitBoardId().equals(recruitBoardId));
7776

@@ -80,7 +79,8 @@ private void validateRecruitBoardConsistency(List<VolunteerApply> applies,
8079
}
8180
}
8281

83-
private void publishVolunteerReviewRequestEvent(VolunteerApply apply, RecruitBoard recruitBoard) {
82+
private void publishVolunteerReviewRequestEvent(VolunteerApply apply,
83+
RecruitBoard recruitBoard) {
8484
VolunteerReviewRequestEvent event = VolunteerReviewRequestEvent.builder()
8585
.type(ServerEventType.NOTIFICATION)
8686
.subType(NotificationSubType.VOLUNTEER_REVIEW_REQUEST)

src/main/java/com/somemore/volunteer/domain/NEWVolunteer.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,27 @@ public class NEWVolunteer extends BaseEntity {
4343
@Column(name = "tier", nullable = false, length = 20)
4444
private Tier tier;
4545

46+
@Column(name = "total_volunteer_hours", nullable = false)
47+
private int totalVolunteerHours;
48+
49+
@Column(name = "total_volunteer_count", nullable = false)
50+
private int totalVolunteerCount;
51+
4652
@Builder
4753
private NEWVolunteer(
4854
UUID userId,
4955
String nickname,
5056
Gender gender,
51-
Tier tier
57+
Tier tier,
58+
int totalVolunteerHours,
59+
int totalVolunteerCount
5260
) {
5361
this.userId = userId;
5462
this.nickname = nickname;
5563
this.gender = gender;
5664
this.tier = tier;
65+
this.totalVolunteerHours = totalVolunteerHours;
66+
this.totalVolunteerCount = totalVolunteerCount;
5767
}
5868

5969
public static NEWVolunteer createDefault(UUID userId) {
@@ -62,6 +72,14 @@ public static NEWVolunteer createDefault(UUID userId) {
6272
.nickname(userId.toString().substring(0, 8))
6373
.gender(Gender.getDefault())
6474
.tier(Tier.getDefault())
75+
.totalVolunteerHours(0)
76+
.totalVolunteerCount(0)
6577
.build();
6678
}
79+
80+
public void updateVolunteerStats(int hours, int count) {
81+
this.totalVolunteerHours += hours;
82+
this.totalVolunteerCount += count;
83+
}
84+
6785
}
Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
1-
package com.somemore.domains.volunteer.service;
1+
package com.somemore.volunteer.service;
2+
3+
import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_VOLUNTEER;
24

3-
import com.somemore.domains.volunteer.domain.Volunteer;
4-
import com.somemore.domains.volunteer.repository.VolunteerRepository;
5-
import com.somemore.domains.volunteer.usecase.UpdateVolunteerUseCase;
65
import com.somemore.global.exception.BadRequestException;
6+
import com.somemore.volunteer.domain.NEWVolunteer;
7+
import com.somemore.volunteer.repository.NEWVolunteerRepository;
8+
import com.somemore.volunteer.usecase.UpdateVolunteerUseCase;
9+
import java.util.UUID;
10+
import java.util.concurrent.TimeUnit;
711
import lombok.RequiredArgsConstructor;
812
import lombok.extern.slf4j.Slf4j;
913
import org.redisson.api.RLock;
1014
import org.redisson.api.RedissonClient;
1115
import org.springframework.stereotype.Service;
1216

13-
import java.util.UUID;
14-
import java.util.concurrent.TimeUnit;
15-
16-
import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_VOLUNTEER;
17-
1817
@Slf4j
1918
@RequiredArgsConstructor
2019
@Service
2120
public class UpdateVolunteerLockService implements UpdateVolunteerUseCase {
2221

23-
private final VolunteerRepository volunteerRepository;
22+
private final NEWVolunteerRepository volunteerRepository;
2423
private final RedissonClient redissonClient;
2524

2625
@Override
@@ -47,7 +46,7 @@ public void updateVolunteerStats(UUID id, int hours) {
4746
}
4847

4948
private void updateStatsWithLock(UUID id, int hours) {
50-
Volunteer volunteer = volunteerRepository.findById(id).orElseThrow(
49+
NEWVolunteer volunteer = volunteerRepository.findById(id).orElseThrow(
5150
() -> new BadRequestException(NOT_EXISTS_VOLUNTEER)
5251
);
5352

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.somemore.domains.volunteer.usecase;
1+
package com.somemore.volunteer.usecase;
22

33
import java.util.UUID;
44

src/test/java/com/somemore/domains/volunteer/service/UpdateVolunteerLockServiceTest.java

Lines changed: 0 additions & 86 deletions
This file was deleted.

src/test/java/com/somemore/domains/volunteerapply/controller/CenterVolunteerApplyCommandApiControllerTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import com.somemore.domains.volunteerapply.usecase.RejectVolunteerApplyUseCase;
1414
import com.somemore.domains.volunteerapply.usecase.SettleVolunteerApplyFacadeUseCase;
1515
import com.somemore.support.ControllerTestSupport;
16-
import com.somemore.support.annotation.WithMockCustomUser;
16+
import com.somemore.support.annotation.MockUser;
1717
import java.util.List;
1818
import java.util.UUID;
1919
import org.junit.jupiter.api.DisplayName;
@@ -33,7 +33,7 @@ class CenterVolunteerApplyCommandApiControllerTest extends ControllerTestSupport
3333

3434
@Test
3535
@DisplayName("봉사 활동 지원 승인 성공 테스트")
36-
@WithMockCustomUser(role = "CENTER")
36+
@MockUser(role = "ROLE_CENTER")
3737
void approve() throws Exception {
3838
// given
3939
Long id = 1L;
@@ -52,7 +52,7 @@ void approve() throws Exception {
5252

5353
@Test
5454
@DisplayName("봉사 활동 지원 거절 성공 테스트")
55-
@WithMockCustomUser(role = "CENTER")
55+
@MockUser(role = "ROLE_CENTER")
5656
void reject() throws Exception {
5757
// given
5858
Long id = 1L;
@@ -71,7 +71,7 @@ void reject() throws Exception {
7171

7272
@Test
7373
@DisplayName("봉사 활동 지원 정산 성공 테스트")
74-
@WithMockCustomUser(role = "CENTER")
74+
@MockUser(role = "ROLE_CENTER")
7575
void settle() throws Exception {
7676
// given
7777
VolunteerApplySettleRequestDto dto = VolunteerApplySettleRequestDto.builder()

src/test/java/com/somemore/domains/volunteerapply/controller/VolunteerApplyCommandApiControllerTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import com.somemore.domains.volunteerapply.usecase.ApplyVolunteerApplyUseCase;
1414
import com.somemore.domains.volunteerapply.usecase.WithdrawVolunteerApplyUseCase;
1515
import com.somemore.support.ControllerTestSupport;
16-
import com.somemore.support.annotation.WithMockCustomUser;
16+
import com.somemore.support.annotation.MockUser;
1717
import java.util.UUID;
1818
import org.junit.jupiter.api.DisplayName;
1919
import org.junit.jupiter.api.Test;
@@ -29,7 +29,7 @@ class VolunteerApplyCommandApiControllerTest extends ControllerTestSupport {
2929

3030
@Test
3131
@DisplayName("봉사 활동 지원 성공 테스트")
32-
@WithMockCustomUser
32+
@MockUser
3333
void apply() throws Exception {
3434
// given
3535
VolunteerApplyCreateRequestDto dto = VolunteerApplyCreateRequestDto.builder()
@@ -57,7 +57,7 @@ void apply() throws Exception {
5757

5858
@Test
5959
@DisplayName("봉사 활동 철회 성공 테스트")
60-
@WithMockCustomUser
60+
@MockUser
6161
void withdraw() throws Exception {
6262
// given
6363
Long id = 1L;

0 commit comments

Comments
 (0)