diff --git a/src/main/java/com/seoultech/synergybe/domain/apply/dto/response/GetApplyResponse.java b/src/main/java/com/seoultech/synergybe/domain/apply/dto/response/GetApplyResponse.java index 19460827..51564945 100644 --- a/src/main/java/com/seoultech/synergybe/domain/apply/dto/response/GetApplyResponse.java +++ b/src/main/java/com/seoultech/synergybe/domain/apply/dto/response/GetApplyResponse.java @@ -2,11 +2,16 @@ import com.querydsl.core.annotations.QueryProjection; import com.seoultech.synergybe.domain.apply.ApplyStatus; -import lombok.Builder; -@Builder public record GetApplyResponse( String applyId, - ApplyStatus status + String status ) { + @QueryProjection + public GetApplyResponse(String applyId, ApplyStatus status) { + this( + applyId, + status.getName() + ); + } } diff --git a/src/main/java/com/seoultech/synergybe/domain/apply/service/ApplyService.java b/src/main/java/com/seoultech/synergybe/domain/apply/service/ApplyService.java index 6df65153..f1c6aee0 100644 --- a/src/main/java/com/seoultech/synergybe/domain/apply/service/ApplyService.java +++ b/src/main/java/com/seoultech/synergybe/domain/apply/service/ApplyService.java @@ -20,11 +20,10 @@ import org.springframework.transaction.annotation.Transactional; import java.util.List; -import java.util.Optional; @Slf4j @Service -@Transactional +@Transactional(readOnly = true) @RequiredArgsConstructor public class ApplyService { private final ApplyRepository applyRepository; @@ -34,8 +33,10 @@ public class ApplyService { private final NotificationService notificationService; private final IdGenerator idGenerator; - public GetApplyResponse createApply(User user, String projectId) { + @Transactional + public String createApply(String userId, String projectId) { Project project = projectService.findProjectById(projectId); + User user = userService.getUser(userId); String applyId = idGenerator.generateId(IdPrefix.APPLY); Apply apply = Apply.builder() @@ -47,26 +48,20 @@ public GetApplyResponse createApply(User user, String projectId) { // User leader = userService.getUser(projectService.getProject(projectId).leaderId()); // notificationService.send(leader, NotificationType.PROJECT_APPLY, "프로젝트 신청이 완료되었습니다.", projectId); - GetApplyResponse getApplyResponse = GetApplyResponse.builder().build(); - - return getApplyResponse; + return savedApply.getId(); } - public void deleteApply(String userId, String projectId) { - Optional applyOptional = applyRepository.findApplyByUserIdAndProjectId(userId, projectId); - - if (applyOptional.isPresent()) { - applyRepository.delete(applyOptional.get()); - - } else { - throw new ApplyNotFoundException("존재하지 않는 신청내역입니다."); - } + @Transactional + public void deleteApply(String applyId) { + // todo + // 사용자 권한 검증 + Apply apply = getApply(applyId); + applyRepository.delete(apply); } - public void acceptApply(String userId, String projectId) { - Apply apply = applyRepository.findApplyByUserIdAndProjectId(userId, projectId) - .orElseThrow(() -> new ApplyNotFoundException("존재하지 않는 신청내역입니다.")); - + @Transactional + public void updateApplyStatusToAccept(String userId, String projectId) { + Apply apply = applyRepository.findApplyByUserIdAndProjectId(userId, projectId); apply.changeStatusToAccept(); Project project = projectService.findProjectById(projectId); User user = userService.getUser(userId); @@ -79,16 +74,13 @@ public void acceptApply(String userId, String projectId) { projectUserRepository.save(projectUser); User applyUser = userService.getUser(userId); - // apply 삭제 -// applyRepository.delete(apply); - // 알림 발송 // notificationService.send(applyUser, NotificationType.PROJECT_ACCEPT, "신청이 수락되었습니다.", projectId); } - public void rejectApply(String userId, String projectId) { - Apply apply = applyRepository.findApplyByUserIdAndProjectId(userId, projectId) - .orElseThrow(() -> new ApplyNotFoundException("존재하지 않는 신청내역입니다.")); + @Transactional + public void updateApplyStatusToReject(String userId, String projectId) { + Apply apply = applyRepository.findApplyByUserIdAndProjectId(userId, projectId); apply.changeStatusToReject(); // apply 삭제 @@ -101,13 +93,11 @@ public void rejectApply(String userId, String projectId) { // return RejectApplyResponse.from(apply); } - public GetListApplyResponse getMyApplyList(User user) { + public GetListApplyResponse getMyApplyList(String userId) { + User user = userService.getUser(userId); List applies = applyRepository.findAllProcessByUserId(user.getUserId()); - GetListApplyResponse getListApplyResponse = GetListApplyResponse.builder().build(); - - return getListApplyResponse; - + return ApplyMapperEntityToDto.applyListToResponse(applies); } public GetListApplyUserResponse getApplyUserList(String projectId) { @@ -116,8 +106,10 @@ public GetListApplyUserResponse getApplyUserList(String projectId) { // user_id 는 PK가 아닌 UNIQUE KEY 이므로 findAllById() 사용 못함 List users = userService.getUsers(userIds); - GetListApplyUserResponse getListApplyUserResponse = GetListApplyUserResponse.builder().build(); + return ApplyMapperEntityToDto.userListToResponse(users); + } - return getListApplyUserResponse; + public Apply getApply(String applyId) { + return applyRepository.findById(applyId).orElseThrow(() -> new ApplyNotFoundException("신청내역이 존재하지 않습니다.")); } }