Skip to content

Commit

Permalink
Merge pull request #92 from 100-hours-a-week/fix-postResponse
Browse files Browse the repository at this point in the history
fix: 채팅방 ID를 동반 게시물 응답에 포함
  • Loading branch information
49EHyeon42 authored Aug 26, 2024
2 parents b7a9926 + c8007b4 commit e110a4a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
8 changes: 8 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ dependencies {
annotationProcessor "com.querydsl:querydsl-apt:${dependencyManagement.importedProperties['querydsl.version']}:jakarta"
annotationProcessor "jakarta.annotation:jakarta.annotation-api"
annotationProcessor "jakarta.persistence:jakarta.persistence-api"

// MongoDB
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'

// RabbitMQ
implementation 'org.springframework.boot:spring-boot-starter-amqp'

// STOMP
}

tasks.named('bootBuildImage') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

import connectripbe.connectrip_be.chat.entity.ChatRoomEntity;
import java.util.List;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface ChatRoomRepository extends JpaRepository<ChatRoomEntity, Long> {

Optional<ChatRoomEntity> findByAccompanyPost_Id(long id);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package connectripbe.connectrip_be.post.dto;

import connectripbe.connectrip_be.chat.entity.ChatRoomEntity;
import connectripbe.connectrip_be.post.entity.AccompanyPostEntity;
import lombok.Builder;

Expand All @@ -11,6 +12,7 @@
public record AccompanyPostResponse(
Long id,
Long memberId,
Long leaderId,
String nickname,
String profileImagePath,
String title,
Expand All @@ -24,11 +26,13 @@ public record AccompanyPostResponse(
String createdAt
) {

public static AccompanyPostResponse fromEntity(AccompanyPostEntity accompanyPost, String status) {
public static AccompanyPostResponse fromEntity(AccompanyPostEntity accompanyPost, String status
, ChatRoomEntity chatRoom) {

return AccompanyPostResponse.builder()
.id(accompanyPost.getId())
.memberId(accompanyPost.getMemberEntity().getId())
.leaderId(chatRoom.getCurrentLeader().getMember().getId())
.nickname(accompanyPost.getMemberEntity().getNickname())
.profileImagePath(accompanyPost.getMemberEntity().getProfileImagePath())
.title(accompanyPost.getTitle())
Expand All @@ -44,7 +48,8 @@ public static AccompanyPostResponse fromEntity(AccompanyPostEntity accompanyPost

}

private static final DateTimeFormatter UTC_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'");
private static final DateTimeFormatter UTC_FORMATTER = DateTimeFormatter.ofPattern(
"yyyy-MM-dd'T'HH:mm:ss'Z'");

private static String formatToUTC(LocalDateTime dateTime) {
if (dateTime == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
import connectripbe.connectrip_be.accompany_status.entity.AccompanyStatusEntity;
import connectripbe.connectrip_be.accompany_status.entity.AccompanyStatusEnum;
import connectripbe.connectrip_be.accompany_status.repository.AccompanyStatusJpaRepository;
import connectripbe.connectrip_be.chat.entity.ChatRoomEntity;
import connectripbe.connectrip_be.chat.repository.ChatRoomRepository;
import connectripbe.connectrip_be.chat.service.ChatRoomService;
import connectripbe.connectrip_be.global.exception.GlobalException;
import connectripbe.connectrip_be.global.exception.type.ErrorCode;
import connectripbe.connectrip_be.member.exception.MemberNotOwnerException;
import connectripbe.connectrip_be.member.exception.NotFoundMemberException;
import connectripbe.connectrip_be.post.dto.*;
Expand Down Expand Up @@ -31,6 +35,7 @@ public class AccompanyPostServiceImpl implements AccompanyPostService {
private final AccompanyStatusJpaRepository accompanyStatusJpaRepository;

private final ChatRoomService chatRoomService;
private final ChatRoomRepository chatRoomRepository;

@Override
@Transactional
Expand Down Expand Up @@ -66,12 +71,16 @@ public void createAccompanyPost(Long memberId, CreateAccompanyPostRequest reques
@Transactional(readOnly = true)
public AccompanyPostResponse readAccompanyPost(long id) {
AccompanyPostEntity accompanyPostEntity = findAccompanyPostEntity(id);

AccompanyStatusEntity accompanyStatusEntity = accompanyStatusJpaRepository
.findTopByAccompanyPostEntityOrderByCreatedAtDesc(accompanyPostEntity)
.orElseThrow(NotFoundAccompanyPostException::new);

ChatRoomEntity chatRoom = chatRoomRepository.findByAccompanyPost_Id(id)
.orElseThrow(() -> new GlobalException(ErrorCode.CHAT_ROOM_NOT_FOUND));

return AccompanyPostResponse.fromEntity(accompanyPostEntity,
accompanyStatusEntity.getAccompanyStatusEnum().toString());
accompanyStatusEntity.getAccompanyStatusEnum().toString(), chatRoom);
}

@Override
Expand All @@ -96,9 +105,12 @@ public AccompanyPostResponse updateAccompanyPost(Long memberId, long id,
request.customUrl()
);

ChatRoomEntity chatRoom = chatRoomRepository.findByAccompanyPost_Id(id)
.orElseThrow(() -> new GlobalException(ErrorCode.CHAT_ROOM_NOT_FOUND));

// 수정된 데이터를 응답으로 반환
return AccompanyPostResponse.fromEntity(accompanyPostEntity, accompanyStatusEntity
.getAccompanyStatusEnum().toString());
.getAccompanyStatusEnum().toString(), chatRoom);
}

@Override
Expand Down

0 comments on commit e110a4a

Please sign in to comment.