Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
import com.somemore.domains.volunteerapply.usecase.ApproveVolunteerApplyUseCase;
import com.somemore.domains.volunteerapply.usecase.RejectVolunteerApplyUseCase;
import com.somemore.domains.volunteerapply.usecase.SettleVolunteerApplyFacadeUseCase;
import com.somemore.global.auth.annotation.CurrentUser;
import com.somemore.global.auth.annotation.RoleId;
import com.somemore.global.common.response.ApiResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.annotation.Secured;
import org.springframework.web.bind.annotation.PatchMapping;
Expand All @@ -18,8 +19,6 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

@Tag(name = "Center Volunteer Apply Command API", description = "봉사 활동 지원 승인, 거절, 정산 API")
@RequiredArgsConstructor
@RequestMapping("/api")
Expand All @@ -34,7 +33,7 @@ public class CenterVolunteerApplyCommandApiController {
@Operation(summary = "봉사 활동 지원 승인", description = "봉사 활동 지원을 승인합니다.")
@PatchMapping("/volunteer-apply/{id}/approve")
public ApiResponse<String> approve(
@CurrentUser UUID centerId,
@RoleId UUID centerId,
@PathVariable Long id
) {

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

Expand All @@ -58,7 +57,7 @@ public ApiResponse<String> reject(
@Operation(summary = "봉사 활동 지원 정산", description = "봉사 활동 지원을 정산(참석 처리, 봉사 시간 부여)합니다.")
@PostMapping("/volunteer-applies/settle")
public ApiResponse<String> settle(
@CurrentUser UUID centerId,
@RoleId UUID centerId,
@Valid @RequestBody VolunteerApplySettleRequestDto requestDto
) {
settleVolunteerApplyFacadeUseCase.settleVolunteerApplies(requestDto, centerId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
import com.somemore.domains.volunteerapply.dto.request.VolunteerApplyCreateRequestDto;
import com.somemore.domains.volunteerapply.usecase.ApplyVolunteerApplyUseCase;
import com.somemore.domains.volunteerapply.usecase.WithdrawVolunteerApplyUseCase;
import com.somemore.global.auth.annotation.CurrentUser;
import com.somemore.global.auth.annotation.RoleId;
import com.somemore.global.common.response.ApiResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.annotation.Secured;
import org.springframework.web.bind.annotation.DeleteMapping;
Expand All @@ -17,8 +18,6 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

@Tag(name = "Volunteer Apply Command API", description = "봉사 활동 지원, 철회 관련 API")
@RequiredArgsConstructor
@RequestMapping("/api")
Expand All @@ -32,7 +31,7 @@ public class VolunteerApplyCommandApiController {
@Operation(summary = "봉사 활동 지원", description = "봉사 활동에 지원합니다.")
@PostMapping("/volunteer-apply")
public ApiResponse<Long> apply(
@CurrentUser UUID volunteerId,
@RoleId UUID volunteerId,
@Valid @RequestBody VolunteerApplyCreateRequestDto requestDto
) {
return ApiResponse.ok(
Expand All @@ -46,7 +45,7 @@ public ApiResponse<Long> apply(
@Operation(summary = "봉사 활동 지원 철회", description = "봉사 활동 지원을 철회합니다.")
@DeleteMapping("/volunteer-apply/{id}")
public ApiResponse<String> withdraw(
@CurrentUser UUID volunteerId,
@RoleId UUID volunteerId,
@PathVariable Long id
) {
withdrawVolunteerApplyUseCase.withdraw(id, volunteerId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.somemore.domains.volunteerapply.service;

import static com.somemore.global.exception.ExceptionMessage.RECRUIT_BOARD_ID_MISMATCH;
import static com.somemore.global.exception.ExceptionMessage.UNAUTHORIZED_RECRUIT_BOARD;
import static com.somemore.global.exception.ExceptionMessage.VOLUNTEER_APPLY_LIST_MISMATCH;

import com.somemore.domains.notification.domain.NotificationSubType;
import com.somemore.domains.recruitboard.domain.RecruitBoard;
import com.somemore.domains.recruitboard.usecase.RecruitBoardQueryUseCase;
import com.somemore.domains.volunteer.usecase.UpdateVolunteerUseCase;
import com.somemore.domains.volunteerapply.domain.VolunteerApply;
import com.somemore.domains.volunteerapply.dto.request.VolunteerApplySettleRequestDto;
import com.somemore.domains.volunteerapply.event.VolunteerReviewRequestEvent;
Expand All @@ -13,17 +16,13 @@
import com.somemore.global.common.event.ServerEventPublisher;
import com.somemore.global.common.event.ServerEventType;
import com.somemore.global.exception.BadRequestException;
import com.somemore.volunteer.usecase.UpdateVolunteerUseCase;
import java.util.List;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.UUID;

import static com.somemore.global.exception.ExceptionMessage.RECRUIT_BOARD_ID_MISMATCH;
import static com.somemore.global.exception.ExceptionMessage.UNAUTHORIZED_RECRUIT_BOARD;
import static com.somemore.global.exception.ExceptionMessage.VOLUNTEER_APPLY_LIST_MISMATCH;

@RequiredArgsConstructor
@Transactional
@Service
Expand Down Expand Up @@ -71,7 +70,7 @@ private void validateVolunteerApplyExistence(List<Long> ids, List<VolunteerApply
}

private void validateRecruitBoardConsistency(List<VolunteerApply> applies,
Long recruitBoardId) {
Long recruitBoardId) {
boolean anyMismatch = applies.stream()
.anyMatch(apply -> !apply.getRecruitBoardId().equals(recruitBoardId));

Expand All @@ -80,7 +79,8 @@ private void validateRecruitBoardConsistency(List<VolunteerApply> applies,
}
}

private void publishVolunteerReviewRequestEvent(VolunteerApply apply, RecruitBoard recruitBoard) {
private void publishVolunteerReviewRequestEvent(VolunteerApply apply,
RecruitBoard recruitBoard) {
VolunteerReviewRequestEvent event = VolunteerReviewRequestEvent.builder()
.type(ServerEventType.NOTIFICATION)
.subType(NotificationSubType.VOLUNTEER_REVIEW_REQUEST)
Expand Down
20 changes: 19 additions & 1 deletion src/main/java/com/somemore/volunteer/domain/NEWVolunteer.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,27 @@ public class NEWVolunteer extends BaseEntity {
@Column(name = "tier", nullable = false, length = 20)
private Tier tier;

@Column(name = "total_volunteer_hours", nullable = false)
private int totalVolunteerHours;

@Column(name = "total_volunteer_count", nullable = false)
private int totalVolunteerCount;

@Builder
private NEWVolunteer(
UUID userId,
String nickname,
Gender gender,
Tier tier
Tier tier,
int totalVolunteerHours,
int totalVolunteerCount
) {
this.userId = userId;
this.nickname = nickname;
this.gender = gender;
this.tier = tier;
this.totalVolunteerHours = totalVolunteerHours;
this.totalVolunteerCount = totalVolunteerCount;
}

public static NEWVolunteer createDefault(UUID userId) {
Expand All @@ -62,6 +72,14 @@ public static NEWVolunteer createDefault(UUID userId) {
.nickname(userId.toString().substring(0, 8))
.gender(Gender.getDefault())
.tier(Tier.getDefault())
.totalVolunteerHours(0)
.totalVolunteerCount(0)
.build();
}

public void updateVolunteerStats(int hours, int count) {
this.totalVolunteerHours += hours;
this.totalVolunteerCount += count;
}

}
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
package com.somemore.domains.volunteer.service;
package com.somemore.volunteer.service;

import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_VOLUNTEER;

import com.somemore.domains.volunteer.domain.Volunteer;
import com.somemore.domains.volunteer.repository.VolunteerRepository;
import com.somemore.domains.volunteer.usecase.UpdateVolunteerUseCase;
import com.somemore.global.exception.BadRequestException;
import com.somemore.volunteer.domain.NEWVolunteer;
import com.somemore.volunteer.repository.NEWVolunteerRepository;
import com.somemore.volunteer.usecase.UpdateVolunteerUseCase;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.stereotype.Service;

import java.util.UUID;
import java.util.concurrent.TimeUnit;

import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_VOLUNTEER;

@Slf4j
@RequiredArgsConstructor
@Service
public class UpdateVolunteerLockService implements UpdateVolunteerUseCase {

private final VolunteerRepository volunteerRepository;
private final NEWVolunteerRepository volunteerRepository;
private final RedissonClient redissonClient;

@Override
Expand All @@ -47,7 +46,7 @@ public void updateVolunteerStats(UUID id, int hours) {
}

private void updateStatsWithLock(UUID id, int hours) {
Volunteer volunteer = volunteerRepository.findById(id).orElseThrow(
NEWVolunteer volunteer = volunteerRepository.findById(id).orElseThrow(
() -> new BadRequestException(NOT_EXISTS_VOLUNTEER)
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.somemore.domains.volunteer.usecase;
package com.somemore.volunteer.usecase;

import java.util.UUID;

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import com.somemore.domains.volunteerapply.usecase.RejectVolunteerApplyUseCase;
import com.somemore.domains.volunteerapply.usecase.SettleVolunteerApplyFacadeUseCase;
import com.somemore.support.ControllerTestSupport;
import com.somemore.support.annotation.WithMockCustomUser;
import com.somemore.support.annotation.MockUser;
import java.util.List;
import java.util.UUID;
import org.junit.jupiter.api.DisplayName;
Expand All @@ -33,7 +33,7 @@ class CenterVolunteerApplyCommandApiControllerTest extends ControllerTestSupport

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

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

@Test
@DisplayName("봉사 활동 지원 정산 성공 테스트")
@WithMockCustomUser(role = "CENTER")
@MockUser(role = "ROLE_CENTER")
void settle() throws Exception {
// given
VolunteerApplySettleRequestDto dto = VolunteerApplySettleRequestDto.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import com.somemore.domains.volunteerapply.usecase.ApplyVolunteerApplyUseCase;
import com.somemore.domains.volunteerapply.usecase.WithdrawVolunteerApplyUseCase;
import com.somemore.support.ControllerTestSupport;
import com.somemore.support.annotation.WithMockCustomUser;
import com.somemore.support.annotation.MockUser;
import java.util.UUID;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
Expand All @@ -29,7 +29,7 @@ class VolunteerApplyCommandApiControllerTest extends ControllerTestSupport {

@Test
@DisplayName("봉사 활동 지원 성공 테스트")
@WithMockCustomUser
@MockUser
void apply() throws Exception {
// given
VolunteerApplyCreateRequestDto dto = VolunteerApplyCreateRequestDto.builder()
Expand Down Expand Up @@ -57,7 +57,7 @@ void apply() throws Exception {

@Test
@DisplayName("봉사 활동 철회 성공 테스트")
@WithMockCustomUser
@MockUser
void withdraw() throws Exception {
// given
Long id = 1L;
Expand Down
Loading
Loading