From f65d2ccb87f68d349f58136e3746d376d225ac03 Mon Sep 17 00:00:00 2001 From: chaechaen Date: Thu, 2 Jan 2025 21:22:06 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=ED=8A=B9=EC=A0=95=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=EC=9E=90=EA=B0=80=20=ED=8A=B9=EC=A0=95=20=EB=8F=99=ED=96=89?= =?UTF-8?q?=EA=B8=80=EC=97=90=20=EB=8C=80=ED=95=9C=20=EB=8F=99=ED=96=89=20?= =?UTF-8?q?=EC=8B=A0=EC=B2=AD=20=EC=83=81=ED=83=9C=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?api=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CompanyParticipantService.java | 25 ++++++++++++++++--- .../CompanyParticipantRepository.java | 5 ++++ .../dto/CompanyParticipantResponseDTO.java | 12 +++++++++ .../CompanyParticipantController.java | 13 ++++++++-- 4 files changed, 50 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/on/server/domain/companyParticipant/application/CompanyParticipantService.java b/src/main/java/com/on/server/domain/companyParticipant/application/CompanyParticipantService.java index 60822621..a8c683e3 100644 --- a/src/main/java/com/on/server/domain/companyParticipant/application/CompanyParticipantService.java +++ b/src/main/java/com/on/server/domain/companyParticipant/application/CompanyParticipantService.java @@ -3,7 +3,6 @@ import com.on.server.domain.alarm.application.AlertService; import com.on.server.domain.alarm.application.FcmService; import com.on.server.domain.alarm.domain.AlertType; -import com.on.server.domain.alarm.dto.FcmRequestDto; import com.on.server.domain.companyParticipant.domain.repository.CompanyParticipantRepository; import com.on.server.domain.companyParticipant.dto.CompanyParticipantRequestDTO; import com.on.server.domain.companyParticipant.dto.CompanyParticipantResponseDTO; @@ -12,12 +11,15 @@ import com.on.server.domain.companyPost.domain.CompanyPost; import com.on.server.domain.companyPost.domain.repository.CompanyPostRepository; import com.on.server.domain.user.domain.User; +import com.on.server.domain.user.domain.repository.UserRepository; +import com.on.server.global.common.ResponseCode; +import com.on.server.global.common.exceptions.BadRequestException; import lombok.RequiredArgsConstructor; +import java.util.List; +import java.util.stream.Collectors; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.io.IOException; - @Service @RequiredArgsConstructor @Transactional @@ -25,6 +27,7 @@ public class CompanyParticipantService { private final CompanyParticipantRepository companyParticipantRepository; private final CompanyPostRepository companyPostRepository; + private final UserRepository userRepository; private final FcmService fcmService; private final AlertService alertService; @@ -57,4 +60,20 @@ public CompanyParticipantResponseDTO applyToCompanyPost(User user, CompanyPartic .companyParticipantStatus(companyParticipant.getCompanyParticipantstatus()) .build(); } + + + // 특정 사용자가 특정 동행글에 대한 동행 신청 상태 확인 + @Transactional(readOnly = true) + public List getCompanyParticipantStatus(Long userId, Long companyPostId) { + + userRepository.findById(userId). + orElseThrow(() -> new BadRequestException(ResponseCode.ROW_DOES_NOT_EXIST, "사용자를 찾을 수 없습니다. ID: " + userId)); + companyPostRepository.findById(companyPostId) + .orElseThrow(() -> new BadRequestException(ResponseCode.ROW_DOES_NOT_EXIST, "게시글을 찾을 수 없습니다. ID: " + companyPostId)); + + return companyParticipantRepository.findByUser_IdAndCompanyPost_Id(userId, companyPostId) + .stream() + .map(CompanyParticipantResponseDTO::from) + .collect(Collectors.toList()); + } } diff --git a/src/main/java/com/on/server/domain/companyParticipant/domain/repository/CompanyParticipantRepository.java b/src/main/java/com/on/server/domain/companyParticipant/domain/repository/CompanyParticipantRepository.java index 1f8a4451..942e4caa 100644 --- a/src/main/java/com/on/server/domain/companyParticipant/domain/repository/CompanyParticipantRepository.java +++ b/src/main/java/com/on/server/domain/companyParticipant/domain/repository/CompanyParticipantRepository.java @@ -5,8 +5,13 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import java.util.List; + @Repository public interface CompanyParticipantRepository extends JpaRepository { CompanyParticipant findByUserAndCompanyPostId(User userParticipant, Long companyPostId); + + List findByUser_IdAndCompanyPost_Id(Long userId, Long companyPostId); + } diff --git a/src/main/java/com/on/server/domain/companyParticipant/dto/CompanyParticipantResponseDTO.java b/src/main/java/com/on/server/domain/companyParticipant/dto/CompanyParticipantResponseDTO.java index 43cbe2c0..69b759c6 100644 --- a/src/main/java/com/on/server/domain/companyParticipant/dto/CompanyParticipantResponseDTO.java +++ b/src/main/java/com/on/server/domain/companyParticipant/dto/CompanyParticipantResponseDTO.java @@ -1,5 +1,8 @@ package com.on.server.domain.companyParticipant.dto; +import com.on.server.domain.companyParticipant.domain.CompanyParticipant; import com.on.server.domain.companyParticipant.domain.CompanyParticipantStatus; +import com.on.server.domain.companyPost.domain.CompanyPost; +import com.on.server.domain.companyPost.dto.CompanyPostResponseDTO; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; @@ -22,4 +25,13 @@ public class CompanyParticipantResponseDTO { // 상태 private CompanyParticipantStatus companyParticipantStatus; + + public static CompanyParticipantResponseDTO from(CompanyParticipant companyParticipant) { + return CompanyParticipantResponseDTO.builder() + .companyParticipantId(companyParticipant.getId()) + .companyPostId(companyParticipant.getCompanyPost().getId()) + .userId(companyParticipant.getUser().getId()) + .companyParticipantStatus(companyParticipant.getCompanyParticipantstatus()) + .build(); + } } diff --git a/src/main/java/com/on/server/domain/companyParticipant/presentation/CompanyParticipantController.java b/src/main/java/com/on/server/domain/companyParticipant/presentation/CompanyParticipantController.java index bd09a9b4..da1c0ca2 100644 --- a/src/main/java/com/on/server/domain/companyParticipant/presentation/CompanyParticipantController.java +++ b/src/main/java/com/on/server/domain/companyParticipant/presentation/CompanyParticipantController.java @@ -13,8 +13,7 @@ import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.web.bind.annotation.*; - -import java.io.IOException; +import java.util.List; @Tag(name = "동행 신청하기") @RestController @@ -39,4 +38,14 @@ public ResponseEntity applyToCompanyPost ( return ResponseEntity.ok(responseDTO); } + + @Operation(summary = "특정 사용자가 특정 동행글에 대한 동행 신청 상태 확인") + @PreAuthorize("@securityService.isNotTemporaryUser()") + @GetMapping("/status/{userId}/{companyPostId}") + public ResponseEntity> getCompanyParticipantStatus(@PathVariable Long userId, + @PathVariable Long companyPostId) { + + List status = companyParticipantService.getCompanyParticipantStatus(userId, companyPostId); + return ResponseEntity.ok(status); + } }