Skip to content

Commit

Permalink
Merge pull request #232 from 100-hours-a-week/fix-review
Browse files Browse the repository at this point in the history
Fix 패키지 이동
  • Loading branch information
trueS2 authored Sep 26, 2024
2 parents 2e4025c + d8624f5 commit 39b0cb8
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import connectripbe.connectrip_be.member.dto.ProfileDto;
import connectripbe.connectrip_be.member.dto.ProfileUpdateRequestDto;
import connectripbe.connectrip_be.member.dto.TokenAndHeaderInfoDto;
import connectripbe.connectrip_be.review.dto.AccompanyReviewResponse2;

public interface MemberService {

Expand All @@ -22,8 +21,6 @@ public interface MemberService {

ProfileDto getProfile(Long memberId); // 프로필 조회 (최신 3개 리뷰 포함)

AccompanyReviewResponse2 getAllReviews(Long memberId); // 모든 리뷰 조회

String calculateAgeGroup(int age); // 나이대 계산 메서드

void updateProfile(Long memberId, ProfileUpdateRequestDto dto); // 프로필 업데이트 메서드
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,10 @@
import connectripbe.connectrip_be.member.exception.DuplicateMemberNicknameException;
import connectripbe.connectrip_be.member.exception.NotFoundMemberException;
import connectripbe.connectrip_be.member.repository.MemberJpaRepository;
import connectripbe.connectrip_be.review.dto.AccompanyReviewDto;
import connectripbe.connectrip_be.review.dto.AccompanyReviewResponse;
import connectripbe.connectrip_be.review.dto.AccompanyReviewResponse2;
import connectripbe.connectrip_be.review.entity.AccompanyReviewEntity;
import connectripbe.connectrip_be.review.repository.AccompanyReviewRepository;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Period;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -168,51 +162,6 @@ public ProfileDto getProfile(Long memberId) {
}


/**
* 특정 회원이 받은 모든 리뷰를 조회하고, 각 리뷰를 AccompanyReviewResponse로 변환하여 반환하는 메서드.
*
* @param memberId 리뷰 대상이 되는 회원 ID
* @return 해당 회원이 받은 모든 리뷰 목록과 리뷰 대상자가 받은 전체 리뷰 수를 포함한 리스트
* @
*/
@Override
public AccompanyReviewResponse2 getAllReviews(Long memberId) {
// 전체 리뷰 목록을 조회
MemberEntity memberEntity = memberJpaRepository.findById(memberId)
.orElseThrow(NotFoundMemberException::new);

List<AccompanyReviewEntity> reviews = accompanyReviewRepository.findAllByTargetIdOrderByCreatedAtDesc(memberId);

List<AccompanyReviewDto> AccompanyReviewDto = reviews.stream()
.map(accompanyReviewEntity -> new AccompanyReviewDto(
accompanyReviewEntity.getId(),
accompanyReviewEntity.getReviewer().getId(),
accompanyReviewEntity.getReviewer().getNickname(),
accompanyReviewEntity.getReviewer().getProfileImagePath(),
accompanyReviewEntity.getContent(),
formatToUTC(accompanyReviewEntity.getCreatedAt())
))
.toList();

return new AccompanyReviewResponse2(
memberId,
memberEntity.getNickname(),
reviews.size(),
AccompanyReviewDto
);
}

// todo-noah: 추후 UTC 관련 utils로 분리
private final DateTimeFormatter UTC_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'");

private String formatToUTC(LocalDateTime dateTime) {
if (dateTime == null) {
return null;
}
return dateTime.atZone(ZoneId.systemDefault()) // 시스템 시간대 적용
.format(UTC_FORMATTER); // 형식에 맞춰 반환
}

/**
* 나이대 계산
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import connectripbe.connectrip_be.member.dto.ProfileUpdateRequestDto;
import connectripbe.connectrip_be.member.dto.TokenAndHeaderInfoDto;
import connectripbe.connectrip_be.member.service.MemberService;
import connectripbe.connectrip_be.review.dto.AccompanyReviewResponse2;
import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
Expand Down Expand Up @@ -73,7 +72,7 @@ public GlobalResponse<MemberHeaderInfoDto> getMemberHeaderInfo(
}

/**
* 회원의 프로필 정보와 최신 3개의 리뷰를 조회
* 회원의 프로필 정보 조회
*
* @param memberId 조회할 회원의 ID
* @return 회원의 프로필과 최신 3개 리뷰를 담은 ProfileDto
Expand All @@ -84,19 +83,6 @@ public ResponseEntity<ProfileDto> getProfile(@PathVariable Long memberId) {
return ResponseEntity.ok(profile);
}

/**
* 회원의 모든 리뷰 조회
*
* @param memberId 조회할 회원의 ID
* @return 회원이 받은 모든 리뷰 목록
*/
@GetMapping("/profile/{memberId}/reviews")
public ResponseEntity<AccompanyReviewResponse2> getAllReviews(@PathVariable Long memberId) {
AccompanyReviewResponse2 accompanyReviewResponse = memberService.getAllReviews(memberId);

return ResponseEntity.ok(accompanyReviewResponse);
}

/**
* 회원 프로필 수정 (닉네임 및 자기소개 수정 가능)
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.List;

public record AccompanyReviewResponse2(
public record AccompanyReviewListResponse(
Long targetId,
String targetNickname,
Integer reviewCount,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package connectripbe.connectrip_be.review.service;

import connectripbe.connectrip_be.review.dto.AccompanyReviewListResponse;
import connectripbe.connectrip_be.review.dto.AccompanyReviewRequest;
import connectripbe.connectrip_be.review.dto.AccompanyReviewResponse;
import connectripbe.connectrip_be.review.dto.AccompanyReviewSummaryResponse;
Expand All @@ -15,4 +16,7 @@ AccompanyReviewSummaryResponse getReviewSummary(
Long chatRoomId,
Long reviewerId,
Long revieweeId);

AccompanyReviewListResponse getAllReviews(Long memberId); // 모든 리뷰 조회

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
import connectripbe.connectrip_be.global.exception.GlobalException;
import connectripbe.connectrip_be.global.exception.type.ErrorCode;
import connectripbe.connectrip_be.member.entity.MemberEntity;
import connectripbe.connectrip_be.member.exception.NotFoundMemberException;
import connectripbe.connectrip_be.member.repository.MemberJpaRepository;
import connectripbe.connectrip_be.review.dto.AccompanyReviewDto;
import connectripbe.connectrip_be.review.dto.AccompanyReviewListResponse;
import connectripbe.connectrip_be.review.dto.AccompanyReviewRequest;
import connectripbe.connectrip_be.review.dto.AccompanyReviewResponse;
import connectripbe.connectrip_be.review.dto.AccompanyReviewSummaryResponse;
Expand Down Expand Up @@ -122,6 +125,40 @@ private String formatToUTC(LocalDateTime dateTime) {
.format(UTC_FORMATTER); // 형식에 맞춰 반환
}

/**
* 특정 회원이 받은 모든 리뷰를 조회하고, 각 리뷰를 AccompanyReviewResponse로 변환하여 반환하는 메서드.
*
* @param memberId 리뷰 대상이 되는 회원 ID
* @return 해당 회원이 받은 모든 리뷰 목록과 리뷰 대상자가 받은 전체 리뷰 수를 포함한 리스트
* @
*/
@Override
public AccompanyReviewListResponse getAllReviews(Long memberId) {
// 전체 리뷰 목록을 조회
MemberEntity memberEntity = memberJpaRepository.findById(memberId)
.orElseThrow(NotFoundMemberException::new);

List<AccompanyReviewEntity> reviews = accompanyReviewRepository.findAllByTargetIdOrderByCreatedAtDesc(memberId);

List<AccompanyReviewDto> AccompanyReviewDto = reviews.stream()
.map(accompanyReviewEntity -> new AccompanyReviewDto(
accompanyReviewEntity.getId(),
accompanyReviewEntity.getReviewer().getId(),
accompanyReviewEntity.getReviewer().getNickname(),
accompanyReviewEntity.getReviewer().getProfileImagePath(),
accompanyReviewEntity.getContent(),
formatToUTC(accompanyReviewEntity.getCreatedAt())
))
.toList();

return new AccompanyReviewListResponse(
memberId,
memberEntity.getNickname(),
reviews.size(),
AccompanyReviewDto
);
}

/**
* AccompanyReviewEntity 객체를 AccompanyReviewResponse로 변환하고 리뷰 개수를 포함시키는 메서드.
*
Expand Down Expand Up @@ -155,4 +192,5 @@ private ChatRoomEntity findChatRoomById(Long chatRoomId) {
return chatRoomRepository.findById(chatRoomId)
.orElseThrow(() -> new GlobalException(ErrorCode.NOT_FOUND_ACCOMPANY_POST));
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package connectripbe.connectrip_be.review.web;

import connectripbe.connectrip_be.review.dto.AccompanyReviewListResponse;
import connectripbe.connectrip_be.review.dto.AccompanyReviewRequest;
import connectripbe.connectrip_be.review.dto.AccompanyReviewResponse;
import connectripbe.connectrip_be.review.dto.AccompanyReviewSummaryResponse;
Expand All @@ -16,7 +17,7 @@
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/v1/chatrooms/{chatRoomId}/reviews")
@RequestMapping("/api/v1/reviews")
@RequiredArgsConstructor
public class AccompanyReviewController {

Expand All @@ -29,7 +30,7 @@ public class AccompanyReviewController {
* @param reviewRequest 리뷰 생성 요청 정보
* @return 생성된 리뷰 정보를 담은 ResponseEntity<AccompanyReviewResponse>
*/
@PostMapping
@PostMapping("/{chatRoomId}")
public ResponseEntity<AccompanyReviewResponse> createReview(
@AuthenticationPrincipal Long memberId,
@PathVariable Long chatRoomId,
Expand All @@ -40,6 +41,20 @@ public ResponseEntity<AccompanyReviewResponse> createReview(
return ResponseEntity.ok(response);
}

/**
* 회원의 모든 리뷰 조회
*
* @param memberId 조회할 회원의 ID
* @return 회원이 받은 모든 리뷰 목록
*/
@GetMapping("/profile/{memberId}")
public ResponseEntity<AccompanyReviewListResponse> getAllReviews(@PathVariable Long memberId) {
AccompanyReviewListResponse response =
accompanyReviewService.getAllReviews(memberId);

return ResponseEntity.ok(response);
}

// 해당 엔드-포인트 사용하지 않아서 주석 처리
// /**
// * 특정 채팅방에 달린 모든 리뷰 조회. 주어진 채팅방 ID에 해당하는 모든 리뷰를 조회하여 반환합니다.
Expand All @@ -58,7 +73,7 @@ public ResponseEntity<AccompanyReviewResponse> createReview(
*
* @return 리뷰
*/
@GetMapping
@GetMapping("/{chatRoomId}")
public ResponseEntity<AccompanyReviewSummaryResponse> getReviewSummary
(
@AuthenticationPrincipal Long memberId,
Expand Down

0 comments on commit 39b0cb8

Please sign in to comment.