Skip to content

Commit

Permalink
Merge pull request #43 from Kusitms-29th-Meetup-TeamE/feat/42/review
Browse files Browse the repository at this point in the history
Feat: 후기 관련 api
  • Loading branch information
Jeongho427 authored May 17, 2024
2 parents 76344ab + b99356d commit 2787804
Show file tree
Hide file tree
Showing 13 changed files with 160 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import org.hibernate.annotations.Comment;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Locale;

@NoArgsConstructor
@AllArgsConstructor
Expand All @@ -27,7 +29,7 @@ public class ActivityDetailsRes {

private String location;

private LocalDateTime time;
private String time;

private Long currentParticipants;

Expand All @@ -38,13 +40,15 @@ public class ActivityDetailsRes {
private List<String> activityImgs;

public static ActivityDetailsRes of(Activity activity) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM월 dd일 EEEE", new Locale("ko", "KR"));

return ActivityDetailsRes.builder()
.id(activity.getId())
.title(activity.getTitle())
.agency(activity.getAgency())
.agency(activity.getAgencyType().getDescription())
.location(activity.getLocation())
.time(activity.getTime())
.time(activity.getTime().format(formatter))
.currentParticipants(activity.getCurrentParticipants())
.maxParticipants(activity.getMaxParticipants())
.personalities(activity.getPersonalities())
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package com.meetup.teame.backend.domain.activity.dto.response;

import com.meetup.teame.backend.domain.activity.entity.Activity;
import com.meetup.teame.backend.domain.like.repository.ActivityLikeRepository;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import lombok.*;
import org.hibernate.annotations.Comment;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Locale;

import static java.time.format.DateTimeFormatter.ofPattern;

@RequiredArgsConstructor
@AllArgsConstructor
Expand All @@ -26,7 +25,7 @@ public class ActivitySummaryRes {

private String location;

private LocalDateTime time;
private String time;

private String activityThumbnail;

Expand All @@ -41,12 +40,14 @@ public static ActivitySummaryRes of(Activity activity, boolean isLiked) {
activityThumbnail = activityImgs.get(0);
}

DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM월 dd일 EEEE", new Locale("ko", "KR"));

return ActivitySummaryRes.builder()
.id(activity.getId())
.title(activity.getTitle())
.agency(activity.getAgency())
.agencyType(activity.getAgencyType().getDescription())
.time(activity.getTime())
.time(activity.getTime().format(formatter))
.activityThumbnail(activityThumbnail)
.isLiked(isLiked)
.build();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.meetup.teame.backend.domain.activity.dto.response;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.meetup.teame.backend.domain.activity.entity.Activity;
import com.meetup.teame.backend.domain.personality.Personality;
import lombok.*;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Locale;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
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();
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
package com.meetup.teame.backend.domain.review.dto.response;

import com.meetup.teame.backend.domain.chatroom.entity.DirectChatRoom;
import com.meetup.teame.backend.domain.experience.entity.Experience;
import com.meetup.teame.backend.domain.review.entity.Review;
import jakarta.persistence.FetchType;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import com.meetup.teame.backend.domain.user.entity.User;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Comment;

@NoArgsConstructor
@AllArgsConstructor
Expand All @@ -20,20 +15,40 @@ public class ReviewRes {

private Long id;

private String description;

private Long mentorId;

private Long menteeId;
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())
.mentorId(review.getMentor().getUser().getId())
.menteeId(review.getMentee().getMentee().getId())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class ReviewRepositoryImpl implements ReviewRepositoryCustom {
public List<Review> 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)));
}
Expand All @@ -27,7 +29,7 @@ public List<Review> findReviewsByUserId(Long userId, String type) {
.selectFrom(review)
.join(review.mentor, experience)
.fetchJoin()
.where(experience.user.id.eq(userId))
.where(builder)
.fetch();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class ReviewService {
private final ExperienceRepository experienceRepository;
private final DirectChatRoomRepository directChatRoomRepository;

@Transactional
//후기 작성하기
public ReviewRes createReview(CreateReviewReq createReviewReq) {
Experience mentor = experienceRepository.findById(createReviewReq.getMentorId())
Expand All @@ -32,6 +33,7 @@ public ReviewRes createReview(CreateReviewReq createReviewReq) {

Review review = reviewRepository.save(Review.of(createReviewReq.getDescription(), mentor, mentee));


return ReviewRes.of(review);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
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;
Expand Down Expand Up @@ -82,34 +84,46 @@ public ResponseEntity<ReadCalenderRes> readCalender(@ModelAttribute @Valid ReadC
추후 로그인 적용 시에는 jwt토큰도 같이 전달해서 요청해주셔야 합니다.
""")
//기본 정보 조회
@GetMapping("/{userId}/info")
public ResponseEntity<UserInfoRes> getUserInfo(@PathVariable long userId) {
UserInfoRes userInfo = userService.getUserInfo(userId);
@GetMapping("/info")
public ResponseEntity<UserInfoRes> getUserInfo() {
UserInfoRes userInfo = userService.getUserInfo();
return ResponseEntity.ok().body(userInfo);
}

@Operation(summary = "사용자 기본 정보 수정", description = """
사용자의 기본 정보를 수정하는 api입니다.
추후 로그인 적용 시에는 jwt토큰도 같이 전달해서 요청해주셔야 합니다.
name, email, imageUrl, location 데이터를 받습니다.
""")
//기본 정보 수정
@PutMapping("/{userId}/info")
public ResponseEntity<UserInfoRes> updateUserInfo(@PathVariable long userId, @RequestBody UpdateUserReq request) {
UserInfoRes userInfo = userService.updateUserInfo(userId, request);
@PutMapping("/info")
public ResponseEntity<UserInfoRes> updateUserInfo(@RequestBody UpdateUserReq request) {
UserInfoRes userInfo = userService.updateUserInfo(request);
return ResponseEntity.ok().body(userInfo);
}

@Operation(summary = "내 후기 목록 조회", description = """
내 후기 목록을 조회하는 api입니다.
경험 활동 유형을 param으로 보낼 수 있습니다.
변수명은 type입니다.
""")
//내 후기 목록 조회
@GetMapping("/{userId}/review")
public ResponseEntity<List<ReviewRes>> getMyReviews(@PathVariable long userId,
@RequestParam String type) {
List<ReviewRes> myReviews = userService.getMyReviews(userId, type);
@GetMapping("/reviews")
public ResponseEntity<List<MyReviewRes>> getMyReviews(@RequestParam String type) {
List<MyReviewRes> myReviews = userService.getMyReviews(type);
return ResponseEntity.ok().body(myReviews);
}

@Operation(summary = "내 활동 참여 목록 조회", description = """
내 활동 참여 목록을 조회하는 api입니다.
api 요청 시 보낼 데이터는 token 이외에 없습니다.
""")
@GetMapping("/activities")
public ResponseEntity<List<ActivitySummaryRes>> getMyActivities() {
List<ActivitySummaryRes> myActivities = userService.getMyActivities();
return ResponseEntity.ok().body(myActivities);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ public class UpdateUserReq {

private String email;

private String password;

private String imageUrl;

private String location;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ public class UserInfoRes {

private String email;

private String password;

private String imageUrl;

private String location;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ public void setPersonalities(List<Personality> personalities) {
public void update(UpdateUserReq request) {
this.name = request.getName();
this.email = request.getEmail();
this.password = request.getPassword();
this.imageUrl = request.getImageUrl();
this.location = request.getLocation();
}
Expand Down
Loading

0 comments on commit 2787804

Please sign in to comment.