diff --git a/src/main/java/com/meetup/teame/backend/domain/activity/dto/response/ActivitySummaryRes.java b/src/main/java/com/meetup/teame/backend/domain/activity/dto/response/ActivitySummaryRes.java index 0f84b76..65db35f 100644 --- a/src/main/java/com/meetup/teame/backend/domain/activity/dto/response/ActivitySummaryRes.java +++ b/src/main/java/com/meetup/teame/backend/domain/activity/dto/response/ActivitySummaryRes.java @@ -9,7 +9,6 @@ import static java.time.format.DateTimeFormatter.ofPattern; -@RequiredArgsConstructor @AllArgsConstructor @Getter @Builder @@ -29,7 +28,7 @@ public class ActivitySummaryRes { private String activityThumbnail; - private boolean isLiked = false; + private boolean isLiked; public static ActivitySummaryRes of(Activity activity, boolean isLiked) { diff --git a/src/main/java/com/meetup/teame/backend/domain/chatroom/service/LastAppointmentScheduler.java b/src/main/java/com/meetup/teame/backend/domain/chatroom/service/LastAppointmentScheduler.java index 47ade2d..63933d1 100644 --- a/src/main/java/com/meetup/teame/backend/domain/chatroom/service/LastAppointmentScheduler.java +++ b/src/main/java/com/meetup/teame/backend/domain/chatroom/service/LastAppointmentScheduler.java @@ -4,12 +4,15 @@ import com.meetup.teame.backend.domain.chatroom.entity.GroupChatRoom; import com.meetup.teame.backend.domain.chatroom.repository.DirectChatRoomRepository; import com.meetup.teame.backend.domain.chatroom.repository.GroupChatRoomRepository; +import com.meetup.teame.backend.domain.review.entity.Review; +import com.meetup.teame.backend.domain.review.repository.ReviewRepository; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.ArrayList; import java.util.List; @Service @@ -19,17 +22,26 @@ public class LastAppointmentScheduler { private final DirectChatRoomRepository directChatRoomRepository; private final GroupChatRoomRepository groupChatRoomRepository; + private final ReviewRepository reviewRepository; @Scheduled(cron = "0 0 0 * * *") @Transactional public void updateLastAppointment() { log.info("-----updateLastAppointment-----"); + List reviews = new ArrayList<>(); List directChatRooms = directChatRoomRepository.findUpdatableRooms(); for (DirectChatRoom directChatRoom : directChatRooms) { + reviews.add(Review.of( + directChatRoom.getExperience(), + directChatRoom.getExperience().getUser(), + directChatRoom.getMentee(), + directChatRoom.getNextAppointment() + )); directChatRoom.setLastAppointment(directChatRoom.getNextAppointment()); directChatRoom.setNextAppointment(null); } + reviewRepository.saveAll(reviews); List groupChatRooms = groupChatRoomRepository.findUpdatableRooms(); for (GroupChatRoom groupChatRoom : groupChatRooms) { diff --git a/src/main/java/com/meetup/teame/backend/domain/experience/entity/Experience.java b/src/main/java/com/meetup/teame/backend/domain/experience/entity/Experience.java index b1209a4..e867c7e 100644 --- a/src/main/java/com/meetup/teame/backend/domain/experience/entity/Experience.java +++ b/src/main/java/com/meetup/teame/backend/domain/experience/entity/Experience.java @@ -30,6 +30,9 @@ public class Experience { @Comment("경험 설명") private String description; + @Comment("경험 상세 내용") + private String detail; + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "user_id") private User user; diff --git a/src/main/java/com/meetup/teame/backend/domain/review/controller/ReviewController.java b/src/main/java/com/meetup/teame/backend/domain/review/controller/ReviewController.java index f782372..6a9922e 100644 --- a/src/main/java/com/meetup/teame/backend/domain/review/controller/ReviewController.java +++ b/src/main/java/com/meetup/teame/backend/domain/review/controller/ReviewController.java @@ -1,7 +1,8 @@ package com.meetup.teame.backend.domain.review.controller; import com.meetup.teame.backend.domain.review.dto.request.CreateReviewReq; -import com.meetup.teame.backend.domain.review.dto.response.ReviewRes; +import com.meetup.teame.backend.domain.review.dto.response.ReadReviewsByMeRes; +import com.meetup.teame.backend.domain.review.dto.response.ReviewByMeRes; import com.meetup.teame.backend.domain.review.service.ReviewService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; @@ -12,6 +13,7 @@ @RequiredArgsConstructor @RestController @Tag(name = "review", description = "후기 관련 api") +@RequestMapping("/reviews") public class ReviewController { private final ReviewService reviewService; @@ -19,28 +21,42 @@ public class ReviewController { @Operation(summary = "후기 보내기", description = """ 후기 보내기 api 입니다. - 후기 내용, 멘토 id, 멘티 id를 입력하셔야합니다. - - 후기보내기가 정상적으로 요청되면 후기 id, 후기 내용, 멘토 id, 멘티 id을 반환해줍니다. + request body에 리뷰 내용을 입력해 전달해주세요. """) //후기 보내기 - @PostMapping("/review") - public ResponseEntity sendReview(@RequestBody CreateReviewReq request) { - ReviewRes response = reviewService.createReview(request); - return ResponseEntity.ok().body(response); + @PostMapping("/{reviewId}") + public ResponseEntity sendReview(@RequestBody CreateReviewReq request, @PathVariable Long reviewId) { + reviewService.sendReview(request,reviewId); + return ResponseEntity.ok().build(); } - @Operation(summary = "후기 조회하기", description = """ - 후기 조회하기 api 입니다. - - 후기 id로 후기에 대한 내용을 볼 수 있습니다. - - 후기 id, 후기 내용, 멘토 id, 멘티 id을 반환해줍니다. + @Operation(summary = "후기 보내기 페이지에서 해당 배움 정보 보기", description = """ + 후기 보내기 페이지에서 해당 배움 정보 보기 api 입니다. + """) + @GetMapping("/{reviewId}") + public ResponseEntity readReview(@PathVariable Long reviewId) { + return ResponseEntity + .ok(reviewService.readReview(reviewId)); + } + + @Operation(summary = "나의 배움 내역 보기", description = """ + 나의 배움 내역 보기 api 입니다. """) - //후기 조회하기 - @GetMapping("/review/{reviewId}") - public ResponseEntity getReview(@PathVariable long reviewId) { - ReviewRes response = reviewService.findReview(reviewId); - return ResponseEntity.ok().body(response); + @GetMapping("/byme") + public ResponseEntity readReviewsByMe() { + return ResponseEntity + .ok(reviewService.readReviewsByMe()); } + + +// @Operation(summary = "나의 후기 보기", description = """ +// 나의 후기 보기 api 입니다. +// """) +// @GetMapping("/aboutme") +// public ResponseEntity readReviewsAboutMe() { +// //todo api 작성 +// return null; +//// return ResponseEntity +//// .ok(reviewService.readReviewsAboutMe()); +// } } diff --git a/src/main/java/com/meetup/teame/backend/domain/review/dto/request/CreateReviewReq.java b/src/main/java/com/meetup/teame/backend/domain/review/dto/request/CreateReviewReq.java index 30da5e8..b9a92e3 100644 --- a/src/main/java/com/meetup/teame/backend/domain/review/dto/request/CreateReviewReq.java +++ b/src/main/java/com/meetup/teame/backend/domain/review/dto/request/CreateReviewReq.java @@ -1,17 +1,12 @@ package com.meetup.teame.backend.domain.review.dto.request; +import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; -@NoArgsConstructor -@AllArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) @Getter public class CreateReviewReq { - - private String description; - - private Long mentorId; - - private Long menteeId; + private String content; } diff --git a/src/main/java/com/meetup/teame/backend/domain/review/dto/response/MyReviewRes.java b/src/main/java/com/meetup/teame/backend/domain/review/dto/response/MyReviewRes.java deleted file mode 100644 index 5887ce4..0000000 --- a/src/main/java/com/meetup/teame/backend/domain/review/dto/response/MyReviewRes.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.meetup.teame.backend.domain.review.dto.response; - -import com.meetup.teame.backend.domain.review.entity.Review; -import com.meetup.teame.backend.domain.user.entity.User; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; - -@NoArgsConstructor -@AllArgsConstructor -@Getter -@Builder -public class MyReviewRes { - private Long id; - - private Long menteeId; - - private String menteeName; - - private Long age; - - private String gender; - - private String location; - - private String time; - - private String imageUrl; - - private String experienceType; - - private String title; - - private String description; - - public static MyReviewRes of(Review review) { - User mentee = review.getMentee().getMentee(); - - return MyReviewRes.builder() - .id(review.getId()) - .menteeId(mentee.getId()) - .menteeName(mentee.getName()) - .age(mentee.getAge()) - .gender(mentee.getGender().getDescription()) - .location(mentee.getLocation()) - .imageUrl(mentee.getImageUrl()) - .experienceType(review.getMentor().getType().getDescription()) - .title(review.getMentor().getDescription()) - .description(review.getDescription()) - .build(); - } -} diff --git a/src/main/java/com/meetup/teame/backend/domain/review/dto/response/ReadReviewsByMeRes.java b/src/main/java/com/meetup/teame/backend/domain/review/dto/response/ReadReviewsByMeRes.java new file mode 100644 index 0000000..c5a8991 --- /dev/null +++ b/src/main/java/com/meetup/teame/backend/domain/review/dto/response/ReadReviewsByMeRes.java @@ -0,0 +1,22 @@ +package com.meetup.teame.backend.domain.review.dto.response; + +import com.meetup.teame.backend.domain.review.entity.Review; +import lombok.*; + +import java.util.List; + +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Getter +@Builder +public class ReadReviewsByMeRes { + private List reviews; + + public static ReadReviewsByMeRes of(List reviews) { + return ReadReviewsByMeRes.builder() + .reviews(reviews.stream() + .map(ReviewByMeRes::of) + .toList()) + .build(); + } +} diff --git a/src/main/java/com/meetup/teame/backend/domain/review/dto/response/ReviewByMeRes.java b/src/main/java/com/meetup/teame/backend/domain/review/dto/response/ReviewByMeRes.java new file mode 100644 index 0000000..e43d802 --- /dev/null +++ b/src/main/java/com/meetup/teame/backend/domain/review/dto/response/ReviewByMeRes.java @@ -0,0 +1,63 @@ +package com.meetup.teame.backend.domain.review.dto.response; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.meetup.teame.backend.domain.review.entity.Review; +import com.meetup.teame.backend.domain.user.entity.Gender; +import lombok.*; + +import java.time.LocalDate; + +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Getter +@Builder +public class ReviewByMeRes { + private Long id; + + private String type; + + private String title; + + private String appointmentLocation; + + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy.MM.dd") + private LocalDate appointmentDate; + + private String imageUrl; + + private String name; + + private Long age; + + private String gender; + + private String location; + + private String experienceDetail; + + private String review; + + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy.MM.dd") + private LocalDate reviewDate; + + private Boolean isWritten; + + public static ReviewByMeRes of(Review review) { + return ReviewByMeRes.builder() + .id(review.getId()) + .type(review.getAppointmentType().getDescription()) + .title(review.getAppointmentTitle()) + .appointmentLocation(review.getAppointment().getAppointmentLocation()) + .appointmentDate(review.getAppointment().getAppointmentDate()) + .imageUrl(review.getMentor().getImageUrl()) + .name(review.getMentor().getName()) + .age(review.getMentor().getAge()) + .gender(review.getMentor().getGender().getDescription()) + .location(review.getMentor().getLocation()) + .experienceDetail(review.getAppointmentDetail()) + .review(review.getContent()) + .reviewDate(review.getReviewDate()) + .isWritten(review.getIsWritten()) + .build(); + } +} diff --git a/src/main/java/com/meetup/teame/backend/domain/review/dto/response/ReviewRes.java b/src/main/java/com/meetup/teame/backend/domain/review/dto/response/ReviewRes.java deleted file mode 100644 index 2fc498c..0000000 --- a/src/main/java/com/meetup/teame/backend/domain/review/dto/response/ReviewRes.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.meetup.teame.backend.domain.review.dto.response; - -import com.meetup.teame.backend.domain.review.entity.Review; -import com.meetup.teame.backend.domain.user.entity.User; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; - -@NoArgsConstructor -@AllArgsConstructor -@Getter -@Builder -public class ReviewRes { - - private Long id; - - private Long mentorId; - - private String mentorName; - - private Long age; - - private String gender; - - private String location; - - private String time; - - private String imageUrl; - - private String experienceType; - - private String title; - - private String description; - - public static ReviewRes of(Review review) { - User mentor = review.getMentor().getUser(); - - return ReviewRes.builder() - .id(review.getId()) - .mentorId(mentor.getId()) - .mentorName(mentor.getName()) - .age(mentor.getAge()) - .gender(mentor.getGender().getDescription()) - .location(mentor.getLocation()) - .imageUrl(mentor.getImageUrl()) - .experienceType(review.getMentor().getType().getDescription()) - .title(review.getMentor().getDescription()) - .description(review.getDescription()) - .build(); - } -} diff --git a/src/main/java/com/meetup/teame/backend/domain/review/entity/Review.java b/src/main/java/com/meetup/teame/backend/domain/review/entity/Review.java index eb287f2..e975b6a 100644 --- a/src/main/java/com/meetup/teame/backend/domain/review/entity/Review.java +++ b/src/main/java/com/meetup/teame/backend/domain/review/entity/Review.java @@ -1,11 +1,16 @@ package com.meetup.teame.backend.domain.review.entity; +import com.meetup.teame.backend.domain.chatroom.entity.Appointment; import com.meetup.teame.backend.domain.chatroom.entity.DirectChatRoom; import com.meetup.teame.backend.domain.experience.entity.Experience; +import com.meetup.teame.backend.domain.experience.entity.ExperienceType; +import com.meetup.teame.backend.domain.user.entity.User; import jakarta.persistence.*; import lombok.*; import org.hibernate.annotations.Comment; +import java.time.LocalDate; + @Entity @NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor(access = AccessLevel.PRIVATE) @@ -19,21 +24,46 @@ public class Review { private Long id; @Comment("내용") - private String description; + private String content; + + private String appointmentDetail; + + @Enumerated(EnumType.STRING) + private ExperienceType appointmentType; + + private String appointmentTitle; @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "mentor") - private Experience mentor; + @JoinColumn(name = "mentor_id") + private User mentor; @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "mentee") - private DirectChatRoom mentee; + @JoinColumn(name = "mentee_id") + private User mentee; + + @Embedded + private Appointment appointment; - public static Review of(String description, Experience mentor, DirectChatRoom mentee) { + @Comment("후기 작성 여부") + private Boolean isWritten; + + private LocalDate reviewDate; + + public static Review of(Experience experience, User mentor, User mentee, Appointment appointment) { return Review.builder() - .description(description) + .appointmentDetail(experience.getDetail()) + .appointmentType(experience.getType()) + .appointmentTitle(experience.getDescription()) .mentor(mentor) .mentee(mentee) + .appointment(appointment) + .isWritten(false) + .reviewDate(LocalDate.now()) .build(); } + + public void setContent(String content) { + this.content = content; + this.isWritten=true; + } } diff --git a/src/main/java/com/meetup/teame/backend/domain/review/repository/ReviewRepository.java b/src/main/java/com/meetup/teame/backend/domain/review/repository/ReviewRepository.java index b6c9795..412e3a7 100644 --- a/src/main/java/com/meetup/teame/backend/domain/review/repository/ReviewRepository.java +++ b/src/main/java/com/meetup/teame/backend/domain/review/repository/ReviewRepository.java @@ -2,7 +2,11 @@ import com.meetup.teame.backend.domain.review.entity.Review; import com.meetup.teame.backend.domain.review.repository.custom.ReviewRepositoryCustom; +import com.meetup.teame.backend.domain.user.entity.User; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; + public interface ReviewRepository extends JpaRepository, ReviewRepositoryCustom { + List findByMentee(User mentee); } diff --git a/src/main/java/com/meetup/teame/backend/domain/review/repository/custom/ReviewRepositoryCustom.java b/src/main/java/com/meetup/teame/backend/domain/review/repository/custom/ReviewRepositoryCustom.java index 890b526..30c4592 100644 --- a/src/main/java/com/meetup/teame/backend/domain/review/repository/custom/ReviewRepositoryCustom.java +++ b/src/main/java/com/meetup/teame/backend/domain/review/repository/custom/ReviewRepositoryCustom.java @@ -5,5 +5,5 @@ import java.util.List; public interface ReviewRepositoryCustom { - List findReviewsByUserId(Long userId, String type); + //List findReviewsByUserId(Long userId, String type); } diff --git a/src/main/java/com/meetup/teame/backend/domain/review/repository/custom/ReviewRepositoryImpl.java b/src/main/java/com/meetup/teame/backend/domain/review/repository/custom/ReviewRepositoryImpl.java index f4d9699..e59916c 100644 --- a/src/main/java/com/meetup/teame/backend/domain/review/repository/custom/ReviewRepositoryImpl.java +++ b/src/main/java/com/meetup/teame/backend/domain/review/repository/custom/ReviewRepositoryImpl.java @@ -15,22 +15,22 @@ public class ReviewRepositoryImpl implements ReviewRepositoryCustom { private final JPAQueryFactory jpaQueryFactory; - @Override - public List findReviewsByUserId(Long userId, String type) { - BooleanBuilder builder = new BooleanBuilder(); - - builder.and(experience.user.id.eq(userId)); - - if (type != null) { - builder.and(experience.type.eq(ExperienceType.of(type))); - } - - return jpaQueryFactory - .selectFrom(review) - .join(review.mentor, experience) - .fetchJoin() - .where(builder) - .fetch(); - } +// @Override +// public List findReviewsByUserId(Long userId, String type) { +// BooleanBuilder builder = new BooleanBuilder(); +// +// builder.and(experience.user.id.eq(userId)); +// +// if (type != null) { +// builder.and(experience.type.eq(ExperienceType.of(type))); +// } +// +// return jpaQueryFactory +// .selectFrom(review) +// .join(review.mentor, experience) +// .fetchJoin() +// .where(builder) +// .fetch(); +// } } diff --git a/src/main/java/com/meetup/teame/backend/domain/review/service/ReviewService.java b/src/main/java/com/meetup/teame/backend/domain/review/service/ReviewService.java index 5dc7218..db8f2a4 100644 --- a/src/main/java/com/meetup/teame/backend/domain/review/service/ReviewService.java +++ b/src/main/java/com/meetup/teame/backend/domain/review/service/ReviewService.java @@ -1,13 +1,12 @@ package com.meetup.teame.backend.domain.review.service; -import com.meetup.teame.backend.domain.chatroom.entity.DirectChatRoom; -import com.meetup.teame.backend.domain.chatroom.repository.DirectChatRoomRepository; -import com.meetup.teame.backend.domain.experience.entity.Experience; -import com.meetup.teame.backend.domain.experience.repository.ExperienceRepository; import com.meetup.teame.backend.domain.review.dto.request.CreateReviewReq; -import com.meetup.teame.backend.domain.review.dto.response.ReviewRes; +import com.meetup.teame.backend.domain.review.dto.response.ReadReviewsByMeRes; +import com.meetup.teame.backend.domain.review.dto.response.ReviewByMeRes; import com.meetup.teame.backend.domain.review.entity.Review; import com.meetup.teame.backend.domain.review.repository.ReviewRepository; +import com.meetup.teame.backend.domain.user.entity.User; +import com.meetup.teame.backend.domain.user.repository.UserRepository; import com.meetup.teame.backend.global.exception.CustomException; import com.meetup.teame.backend.global.exception.ExceptionContent; import lombok.RequiredArgsConstructor; @@ -20,28 +19,28 @@ public class ReviewService { private final ReviewRepository reviewRepository; - private final ExperienceRepository experienceRepository; - private final DirectChatRoomRepository directChatRoomRepository; + private final UserRepository userRepository; @Transactional //후기 작성하기 - public ReviewRes createReview(CreateReviewReq createReviewReq) { - Experience mentor = experienceRepository.findById(createReviewReq.getMentorId()) - .orElseThrow(() -> new CustomException(ExceptionContent.NOT_FOUND_EXPERIENCE)); - DirectChatRoom mentee = directChatRoomRepository.findById(createReviewReq.getMenteeId()) - .orElseThrow(() -> new CustomException(ExceptionContent.NOT_FOUND_CHAT_ROOM)); - - Review review = reviewRepository.save(Review.of(createReviewReq.getDescription(), mentor, mentee)); - + public void sendReview(CreateReviewReq createReviewReq, Long reviewId) { + Review review = reviewRepository.findById(reviewId) + .orElseThrow(() -> new CustomException(ExceptionContent.NOT_FOUND_REVIEW)); + if (review.getIsWritten()) + throw new CustomException(ExceptionContent.BAD_REQUEST_ALREADY_WRITTEN_REVIEW); + review.setContent(createReviewReq.getContent()); + } - return ReviewRes.of(review); + public ReadReviewsByMeRes readReviewsByMe() { + //todo : 현재는 더미 유저지만 추후에는 SecurityContextHolder 정보를 조회해서 유저 정보를 가져와야 함 + User user = userRepository.findById(5L) + .orElseThrow(() -> new CustomException(ExceptionContent.NOT_FOUND_USER)); + return ReadReviewsByMeRes.of(reviewRepository.findByMentee(user)); } - //후기 조회하기 - public ReviewRes findReview(Long reviewId) { + public ReviewByMeRes readReview(Long reviewId) { Review review = reviewRepository.findById(reviewId) .orElseThrow(() -> new CustomException(ExceptionContent.NOT_FOUND_REVIEW)); - return ReviewRes.of(review); + return ReviewByMeRes.of(review); } - } diff --git a/src/main/java/com/meetup/teame/backend/domain/user/controller/UserController.java b/src/main/java/com/meetup/teame/backend/domain/user/controller/UserController.java index 6dcc249..bea6997 100644 --- a/src/main/java/com/meetup/teame/backend/domain/user/controller/UserController.java +++ b/src/main/java/com/meetup/teame/backend/domain/user/controller/UserController.java @@ -1,8 +1,6 @@ package com.meetup.teame.backend.domain.user.controller; import com.meetup.teame.backend.domain.activity.dto.response.ActivitySummaryRes; -import com.meetup.teame.backend.domain.review.dto.response.MyReviewRes; -import com.meetup.teame.backend.domain.review.dto.response.ReviewRes; import com.meetup.teame.backend.domain.user.dto.request.OnboardingReq; import com.meetup.teame.backend.domain.user.dto.request.ReadCalenderReq; import com.meetup.teame.backend.domain.user.dto.request.UpdateUserReq; @@ -102,19 +100,19 @@ public ResponseEntity updateUserInfo(@RequestBody UpdateUserReq req return ResponseEntity.ok().body(userInfo); } - @Operation(summary = "내 후기 목록 조회", description = """ - 내 후기 목록을 조회하는 api입니다. - - 경험 활동 유형을 param으로 보낼 수 있습니다. - - 변수명은 type입니다. - """) - //내 후기 목록 조회 - @GetMapping("/reviews") - public ResponseEntity> getMyReviews(@RequestParam String type) { - List myReviews = userService.getMyReviews(type); - return ResponseEntity.ok().body(myReviews); - } +// @Operation(summary = "내 후기 목록 조회", description = """ +// 내 후기 목록을 조회하는 api입니다. +// +// 경험 활동 유형을 param으로 보낼 수 있습니다. +// +// 변수명은 type입니다. +// """) +// //내 후기 목록 조회 +// @GetMapping("/reviews") +// public ResponseEntity> getMyReviews(@RequestParam String type) { +// List myReviews = userService.getMyReviews(type); +// return ResponseEntity.ok().body(myReviews); +// } @Operation(summary = "내 활동 참여 목록 조회", description = """ 내 활동 참여 목록을 조회하는 api입니다. diff --git a/src/main/java/com/meetup/teame/backend/domain/user/entity/User.java b/src/main/java/com/meetup/teame/backend/domain/user/entity/User.java index 6bcc759..a316109 100644 --- a/src/main/java/com/meetup/teame/backend/domain/user/entity/User.java +++ b/src/main/java/com/meetup/teame/backend/domain/user/entity/User.java @@ -6,6 +6,7 @@ import com.meetup.teame.backend.domain.personality.Personality; import com.meetup.teame.backend.domain.experience.entity.Experience; import com.meetup.teame.backend.domain.like.entity.ActivityLike; +import com.meetup.teame.backend.domain.review.entity.Review; import com.meetup.teame.backend.domain.user.dto.request.UpdateUserReq; import jakarta.persistence.*; import lombok.*; @@ -66,6 +67,13 @@ public class User { @OneToMany(mappedBy = "mentee", cascade = CascadeType.ALL) private List learnedChatRooms; + @OneToMany(mappedBy = "mentor", cascade = CascadeType.ALL) + private List reviewsAboutMe; + + @OneToMany(mappedBy = "mentee", cascade = CascadeType.ALL) + private List reviewsByMe; + + public void setPersonalities(List personalities) { this.personalities = personalities; } diff --git a/src/main/java/com/meetup/teame/backend/domain/user/service/UserService.java b/src/main/java/com/meetup/teame/backend/domain/user/service/UserService.java index 2b1524b..2110a4a 100644 --- a/src/main/java/com/meetup/teame/backend/domain/user/service/UserService.java +++ b/src/main/java/com/meetup/teame/backend/domain/user/service/UserService.java @@ -1,21 +1,15 @@ package com.meetup.teame.backend.domain.user.service; import com.meetup.teame.backend.domain.activity.dto.response.ActivitySummaryRes; -import com.meetup.teame.backend.domain.activity.entity.Activity; import com.meetup.teame.backend.domain.activity.repository.ActivityRepository; import com.meetup.teame.backend.domain.auth.jwt.SecurityContextProvider; import com.meetup.teame.backend.domain.auth.oauth.dto.CreateUserRequest; import com.meetup.teame.backend.domain.chatroom.repository.DirectChatRoomRepository; import com.meetup.teame.backend.domain.chatroom.repository.GroupChatRoomRepository; -import com.meetup.teame.backend.domain.chatroom.entity.ChatRoom; import com.meetup.teame.backend.domain.chatroom.entity.GroupChatRoom; -import com.meetup.teame.backend.domain.chatroom.entity.UserChatRoom; -import com.meetup.teame.backend.domain.chatroom.repository.GroupChatRoomRepository; import com.meetup.teame.backend.domain.experience.repository.ExperienceRepository; import com.meetup.teame.backend.domain.like.repository.ActivityLikeRepository; import com.meetup.teame.backend.domain.personality.Personality; -import com.meetup.teame.backend.domain.review.dto.response.MyReviewRes; -import com.meetup.teame.backend.domain.review.dto.response.ReviewRes; import com.meetup.teame.backend.domain.review.entity.Review; import com.meetup.teame.backend.domain.review.repository.ReviewRepository; import com.meetup.teame.backend.domain.user.dto.request.OnboardingReq; @@ -34,7 +28,6 @@ import org.springframework.transaction.annotation.Transactional; import java.time.LocalDate; -import java.util.ArrayList; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; @@ -104,15 +97,15 @@ public UserInfoRes updateUserInfo(UpdateUserReq request) { return UserInfoRes.of(updatedUser); } - //내 후기 조회 - public List getMyReviews(String type) { - Long userId = SecurityContextProvider.getAuthenticatedUserId(); - List myReviews = reviewRepository.findReviewsByUserId(userId, type); - List reviews = myReviews.stream() - .map(MyReviewRes::of) - .toList(); - return reviews; - } +// //내 후기 조회 +// public List getMyReviews(String type) { +// Long userId = SecurityContextProvider.getAuthenticatedUserId(); +// List myReviews = reviewRepository.findReviewsByUserId(userId, type); +// List reviews = myReviews.stream() +// .map(MyReviewRes::of) +// .toList(); +// return reviews; +// } //내 활동 조회 public List getMyActivities() { diff --git a/src/main/java/com/meetup/teame/backend/global/exception/ExceptionContent.java b/src/main/java/com/meetup/teame/backend/global/exception/ExceptionContent.java index 5c35c41..e39c10e 100644 --- a/src/main/java/com/meetup/teame/backend/global/exception/ExceptionContent.java +++ b/src/main/java/com/meetup/teame/backend/global/exception/ExceptionContent.java @@ -23,6 +23,7 @@ public enum ExceptionContent { BAD_REQUEST_ALREADY_JOIN_CHATROOM(BAD_REQUEST, "이미 참여한 채팅방입니다."), BAD_REQUEST_AGENCY_TYPE(BAD_REQUEST, "잘못된 요청입니다. 유효하지 않은 기관 유형입니다."), BAD_REQUEST_GENDER(BAD_REQUEST, "잘못된 요청입니다. 유효하지 않은 성별입니다."), + BAD_REQUEST_ALREADY_WRITTEN_REVIEW(BAD_REQUEST, "이미 작성한 후기입니다."), NOT_FOUND_USER(NOT_FOUND, "존재하지 않는 사용자입니다."), NOT_FOUND_PERSONALITY(NOT_FOUND, "존재하지 않는 성격입니다."), @@ -31,8 +32,7 @@ public enum ExceptionContent { NOT_FOUND_AGENCY_TYPE(NOT_FOUND, "존재하지 않는 기관 유형입니다."), NOT_FOUND_EXPERIENCE(NOT_FOUND, "존재하지 않는 경험입니다."), NOT_FOUND_CHAT_ROOM(NOT_FOUND, "존재하지 않는 채팅방입니다."), - NOT_FOUND_REVIEW(NOT_FOUND, "존재하지 않는 후기입니다."), - ; + NOT_FOUND_REVIEW(NOT_FOUND, "존재하지 않는 후기입니다."); private final HttpStatus httpStatus; private final String message;