From f65d2ccb87f68d349f58136e3746d376d225ac03 Mon Sep 17 00:00:00 2001 From: chaechaen Date: Thu, 2 Jan 2025 21:22:06 +0900 Subject: [PATCH 1/4] =?UTF-8?q?feat:=20=ED=8A=B9=EC=A0=95=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=EC=9E=90=EA=B0=80=20=ED=8A=B9=EC=A0=95=20=EB=8F=99?= =?UTF-8?q?=ED=96=89=EA=B8=80=EC=97=90=20=EB=8C=80=ED=95=9C=20=EB=8F=99?= =?UTF-8?q?=ED=96=89=20=EC=8B=A0=EC=B2=AD=20=EC=83=81=ED=83=9C=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20api=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); + } } From 11f85f849973b2bf1b369d3b654a361b8e56af03 Mon Sep 17 00:00:00 2001 From: Lee Haewon Date: Fri, 3 Jan 2025 17:29:58 +0900 Subject: [PATCH 2/4] =?UTF-8?q?fix:=20=EC=B1=84=ED=8C=85=EB=B0=A9=20?= =?UTF-8?q?=EB=AA=A9=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=20=EC=BF=BC=EB=A6=AC=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/on/server/domain/chat/application/ChatService.java | 2 -- .../chat/domain/repository/ChattingRoomRepository.java | 7 ++++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/on/server/domain/chat/application/ChatService.java b/src/main/java/com/on/server/domain/chat/application/ChatService.java index 7bcd1912..d7afc2d9 100644 --- a/src/main/java/com/on/server/domain/chat/application/ChatService.java +++ b/src/main/java/com/on/server/domain/chat/application/ChatService.java @@ -83,7 +83,6 @@ public Page getCompanyChatRoomList(User user, Pageable p lastChatTime ); }) - .sorted(Comparator.comparing(CompanyRoomDto::getLastChatTime).reversed()) // 최신순 정렬 .toList(); @@ -129,7 +128,6 @@ public Page getMarketChatRoomList(User user, Pageable pag lastChatTime ); }) - .sorted(Comparator.comparing(MarketRoomDto::getLastChatTime).reversed()) // 최신순 정렬 .toList(); diff --git a/src/main/java/com/on/server/domain/chat/domain/repository/ChattingRoomRepository.java b/src/main/java/com/on/server/domain/chat/domain/repository/ChattingRoomRepository.java index 334c49d0..8189f93f 100644 --- a/src/main/java/com/on/server/domain/chat/domain/repository/ChattingRoomRepository.java +++ b/src/main/java/com/on/server/domain/chat/domain/repository/ChattingRoomRepository.java @@ -14,7 +14,12 @@ public interface ChattingRoomRepository extends JpaRepository { - @Query("SELECT cr FROM ChattingRoom cr WHERE (cr.chatUserOne = :user OR cr.chatUserTwo = :user) AND cr.chattingRoomType = :chattingRoomType") + @Query("SELECT cr FROM ChattingRoom cr " + + "LEFT JOIN Chat c ON c.chattingRoom = cr " + + "WHERE (cr.chatUserOne = :user OR cr.chatUserTwo = :user) " + + "AND cr.chattingRoomType = :chattingRoomType " + + "GROUP BY cr " + + "ORDER BY COALESCE(MAX(c.createdAt), cr.createdAt) DESC") Page findByChatUserOneOrChatUserTwoAndChattingRoomType( @Param("user") User user, @Param("chattingRoomType") ChatType chattingRoomType, From 56acfd1716d25838018f4e323fa5686c4ad1dbdd Mon Sep 17 00:00:00 2001 From: chaechaen Date: Sat, 4 Jan 2025 01:53:27 +0900 Subject: [PATCH 3/4] =?UTF-8?q?fix:=20=EC=B1=84=ED=8C=85=EB=B0=A9=20ID?= =?UTF-8?q?=EB=A5=BC=20=EB=B0=9B=EB=8F=84=EB=A1=9D=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?=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CompanyParticipantService.java | 42 +++++++++++++------ .../CompanyParticipantRepository.java | 3 +- .../dto/CompanyParticipantResponseDTO.java | 6 ++- .../CompanyParticipantController.java | 10 ++--- 4 files changed, 41 insertions(+), 20 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 a8c683e3..4d638c7c 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,6 +3,10 @@ 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.chat.domain.ChattingRoom; +import com.on.server.domain.chat.domain.SpecialChat; +import com.on.server.domain.chat.domain.repository.ChattingRoomRepository; +import com.on.server.domain.chat.domain.repository.SpecialChatRepository; 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; @@ -15,8 +19,7 @@ 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; @@ -30,6 +33,8 @@ public class CompanyParticipantService { private final UserRepository userRepository; private final FcmService fcmService; private final AlertService alertService; + private final ChattingRoomRepository chattingRoomRepository; + private final SpecialChatRepository specialChatRepository; public CompanyParticipantResponseDTO applyToCompanyPost(User user, CompanyParticipantRequestDTO requestDTO) { @@ -62,18 +67,31 @@ public CompanyParticipantResponseDTO applyToCompanyPost(User user, CompanyPartic } - // 특정 사용자가 특정 동행글에 대한 동행 신청 상태 확인 + // 특정 채팅방의 동행 신청자의 동행 신청 상태 확인 @Transactional(readOnly = true) - public List getCompanyParticipantStatus(Long userId, Long companyPostId) { + public CompanyParticipantResponseDTO getCompanyParticipantStatus(Long userId, Long chattingRoomId) { + + // 채팅방이 존재하는지 확인 + ChattingRoom chattingRoom = chattingRoomRepository.findById(chattingRoomId) + .orElseThrow(() -> new BadRequestException(ResponseCode.ROW_DOES_NOT_EXIST, "채팅방을 찾을 수 없습니다.")); + + // userId로 User 조회 + userRepository.findById(userId) + .orElseThrow(() -> new BadRequestException(ResponseCode.ROW_DOES_NOT_EXIST, "사용자를 찾을 수 없습니다.")); + + // SpecialChat 조회 + SpecialChat specialChat = specialChatRepository.findByChattingRoom(chattingRoom); + + // SpecialChat에서 CompanyPost 정보 가져오기 + CompanyPost companyPost = specialChat.getCompanyPost(); + + // CompanyParticipant 조회 (status 확인용) + CompanyParticipant companyParticipant = companyParticipantRepository.findByUser_IdAndCompanyPost_Id(userId, companyPost.getId()); - 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)); + if (companyParticipant == null) { // 없으면 null 반환 + return null; + } - return companyParticipantRepository.findByUser_IdAndCompanyPost_Id(userId, companyPostId) - .stream() - .map(CompanyParticipantResponseDTO::from) - .collect(Collectors.toList()); + return CompanyParticipantResponseDTO.from(companyParticipant, chattingRoomId); } } 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 942e4caa..450bf562 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 @@ -12,6 +12,5 @@ public interface CompanyParticipantRepository extends JpaRepository findByUser_IdAndCompanyPost_Id(Long userId, Long companyPostId); - + CompanyParticipant 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 69b759c6..76160834 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 @@ -20,16 +20,20 @@ public class CompanyParticipantResponseDTO { // 동행 구하기 글 ID private Long companyPostId; + // 채팅룸 번호 + private Long chattingRoomId; + // 작성자 ID private Long userId; // 상태 private CompanyParticipantStatus companyParticipantStatus; - public static CompanyParticipantResponseDTO from(CompanyParticipant companyParticipant) { + public static CompanyParticipantResponseDTO from(CompanyParticipant companyParticipant, Long chattingRoomId) { return CompanyParticipantResponseDTO.builder() .companyParticipantId(companyParticipant.getId()) .companyPostId(companyParticipant.getCompanyPost().getId()) + .chattingRoomId(chattingRoomId) .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 da1c0ca2..932ebf34 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 @@ -39,13 +39,13 @@ public ResponseEntity applyToCompanyPost ( return ResponseEntity.ok(responseDTO); } - @Operation(summary = "특정 사용자가 특정 동행글에 대한 동행 신청 상태 확인") + @Operation(summary = "특정 채팅방의 동행 신청자의 동행 신청 상태 확인") @PreAuthorize("@securityService.isNotTemporaryUser()") - @GetMapping("/status/{userId}/{companyPostId}") - public ResponseEntity> getCompanyParticipantStatus(@PathVariable Long userId, - @PathVariable Long companyPostId) { + @GetMapping("/status/{userId}/{chattingRoomId}") + public ResponseEntity getCompanyParticipantStatus(@PathVariable Long userId, + @PathVariable Long chattingRoomId) { - List status = companyParticipantService.getCompanyParticipantStatus(userId, companyPostId); + CompanyParticipantResponseDTO status = companyParticipantService.getCompanyParticipantStatus(userId, chattingRoomId); return ResponseEntity.ok(status); } } From 2f11b26eeac56489f3d598dfb27f8981effd4a80 Mon Sep 17 00:00:00 2001 From: chaechaen Date: Sat, 4 Jan 2025 15:39:38 +0900 Subject: [PATCH 4/4] =?UTF-8?q?fix:=20=EB=8F=99=ED=96=89=EA=B5=AC=ED=95=98?= =?UTF-8?q?=EA=B8=B0=EA=B8=80=20=EA=B5=AD=EA=B0=80=20=ED=95=84=ED=84=B0?= =?UTF-8?q?=EB=A7=81=20=EC=BF=BC=EB=A6=AC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/CompanyPostService.java | 14 +------------- .../domain/repository/CompanyPostRepository.java | 7 +++++-- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/on/server/domain/companyPost/application/CompanyPostService.java b/src/main/java/com/on/server/domain/companyPost/application/CompanyPostService.java index 2cad6a34..f61503db 100644 --- a/src/main/java/com/on/server/domain/companyPost/application/CompanyPostService.java +++ b/src/main/java/com/on/server/domain/companyPost/application/CompanyPostService.java @@ -14,7 +14,6 @@ import com.on.server.global.common.exceptions.UnauthorizedException; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; @@ -36,18 +35,7 @@ public class CompanyPostService { // 필터링 기능 추가 public Page getFilteredCompanyPosts(LocalDate startDate, LocalDate endDate, Gender gender, String country, Pageable pageable) { - Page posts = companyPostRepository.findFilteredCompanyPostsWithoutCountry(startDate, endDate, gender, pageable); - - if (country != null && !country.isEmpty()) { - posts = posts.stream() - .filter(post -> post.getTravelArea().stream() - .anyMatch(area -> { - String firstWord = area.split(" ")[0]; // travelArea의 첫 번째 단어 추출 - return firstWord.equalsIgnoreCase(country); - })) - .collect(Collectors.collectingAndThen(Collectors.toList(), list -> new PageImpl<>(list, pageable, list.size()))); - } - + Page posts = companyPostRepository.findFilteredCompanyPosts(startDate, endDate, gender, country, pageable); return posts.map(CompanyPostResponseDTO::from); } diff --git a/src/main/java/com/on/server/domain/companyPost/domain/repository/CompanyPostRepository.java b/src/main/java/com/on/server/domain/companyPost/domain/repository/CompanyPostRepository.java index 2afbcf6c..6ba49311 100644 --- a/src/main/java/com/on/server/domain/companyPost/domain/repository/CompanyPostRepository.java +++ b/src/main/java/com/on/server/domain/companyPost/domain/repository/CompanyPostRepository.java @@ -19,14 +19,17 @@ public interface CompanyPostRepository extends JpaRepository { // 필터링을 위한 쿼리 - @Query("SELECT cp FROM CompanyPost cp WHERE (:startDate IS NULL OR cp.startDate >= :startDate) " + + @Query("SELECT DISTINCT cp FROM CompanyPost cp JOIN cp.travelArea ta WHERE " + + "(:startDate IS NULL OR cp.startDate >= :startDate) " + "AND (:endDate IS NULL OR cp.endDate <= :endDate) " + "AND (:gender IS NULL OR cp.user.gender = :gender) " + + "AND (:country IS NULL OR SUBSTRING(ta, 1, LOCATE(' ', ta) - 1) = :country) " + "ORDER BY cp.createdAt DESC") - Page findFilteredCompanyPostsWithoutCountry( + Page findFilteredCompanyPosts( @Param("startDate") LocalDate startDate, @Param("endDate") LocalDate endDate, @Param("gender") Gender gender, + @Param("country") String country, Pageable pageable); // 최신 4개의 글을 최신순으로 가져오기