Skip to content

Commit

Permalink
Merge pull request #48 from Kusitms-29th-Meetup-TeamE/feat/42/review
Browse files Browse the repository at this point in the history
Feat: 나의 후기 확인 api
  • Loading branch information
nohy6630 authored May 18, 2024
2 parents dd79f5b + a2d0e70 commit 009010b
Show file tree
Hide file tree
Showing 14 changed files with 209 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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.chatroom.dto.response.DirectChatRoomRes;
import com.meetup.teame.backend.domain.chatroom.dto.response.GroupChatRoomRes;
import com.meetup.teame.backend.domain.chatroom.dto.response.ReadDirectChatRoomsRes;
Expand Down Expand Up @@ -39,8 +40,8 @@ public class ChatRoomService {
private final ChattingRepository chattingRepository;

public ReadGroupChatRoomsRes readGroupChatRooms() {
//todo : 현재는 더미 유저지만 추후에는 SecurityContextHolder 정보를 조회해서 유저 정보를 가져와야 함
User user = userRepository.findById(5L)
Long userId = SecurityContextProvider.getAuthenticatedUserId();
User user = userRepository.findById(userId)
.orElseThrow(() -> new CustomException(ExceptionContent.NOT_FOUND_USER));
return ReadGroupChatRoomsRes.of(
user,
Expand All @@ -56,8 +57,8 @@ public ReadGroupChatRoomsRes readGroupChatRooms() {
}

public ReadDirectChatRoomsRes readDirectChatRooms() {
//todo : 현재는 더미 유저지만 추후에는 SecurityContextHolder 정보를 조회해서 유저 정보를 가져와야 함
User user = userRepository.findById(5L)
Long userId = SecurityContextProvider.getAuthenticatedUserId();
User user = userRepository.findById(userId)
.orElseThrow(() -> new CustomException(ExceptionContent.NOT_FOUND_USER));
return ReadDirectChatRoomsRes.of(
user,
Expand All @@ -74,8 +75,8 @@ public ReadDirectChatRoomsRes readDirectChatRooms() {

@Transactional
public Long joinGroupChatRoom(Long activityId) {
//todo SecurityContextHolder 적용
User user = userRepository.findById(5L)
Long userId = SecurityContextProvider.getAuthenticatedUserId();
User user = userRepository.findById(userId)
.orElseThrow(() -> new CustomException(ExceptionContent.NOT_FOUND_USER));
GroupChatRoom groupChatRoom = groupChatRoomRepository.findByActivityId(activityId)
.orElseGet(() -> {
Expand All @@ -91,8 +92,8 @@ public Long joinGroupChatRoom(Long activityId) {

@Transactional
public Long joinDirectChatRoom(Long experienceId) {
//todo SecurityContextHolder 적용
User user = userRepository.findById(5L)
Long userId = SecurityContextProvider.getAuthenticatedUserId();
User user = userRepository.findById(userId)
.orElseThrow(() -> new CustomException(ExceptionContent.NOT_FOUND_USER));
Experience experience = experienceRepository.findById(experienceId)
.orElseThrow(() -> new CustomException(ExceptionContent.NOT_FOUND_EXPERIENCE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class Experience {
@Enumerated(EnumType.STRING)
private ExperienceType type;

@Comment("경험 설명")
@Comment("경험 제목")
private String description;

@Comment("경험 상세 내용")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.meetup.teame.backend.domain.experience.service;

import com.meetup.teame.backend.domain.auth.jwt.SecurityContextProvider;
import com.meetup.teame.backend.domain.experience.dto.request.ReadExperiencesReq;
import com.meetup.teame.backend.domain.experience.dto.response.ReadExperiencesRes;
import com.meetup.teame.backend.domain.experience.dto.response.MyExperienceProfileRes;
Expand Down Expand Up @@ -38,9 +39,9 @@ else if (sort.equals("review"))
}

public MyExperienceProfileRes readMyExperienceProfile() {
//todo : 현재는 더미 유저지만 추후에는 SecurityContextHolder 정보를 조회해서 유저 정보를 가져와야 함
Long userId = SecurityContextProvider.getAuthenticatedUserId();
//todo 1+N문제 발생가능 테스트해보고 default_fetch_batch_size 적용
User user = userRepository.findById(5L)
User user = userRepository.findById(userId)
.orElseThrow(() -> new CustomException(ExceptionContent.NOT_FOUND_USER));
return MyExperienceProfileRes.of(user);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.meetup.teame.backend.domain.like.controller;

import com.meetup.teame.backend.domain.like.service.LikeService;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@RequiredArgsConstructor
@RestController
public class LikeController {

private final LikeService likeService;

@Operation(summary = "활동 좋아요 활성화", description = """
활동 좋아요를 활성화 하는 api입니다.
활동 id를 받아서 활동 좋아요를 추가합니다.
""")
//활동 좋아요 활성화
@PostMapping("/activate-like/{activityId}")
public ResponseEntity<Void> activateLike(@PathVariable long activityId) {
likeService.activateLike(activityId);
return ResponseEntity.ok().build();
}

@Operation(summary = "활동 좋아요 비활성화", description = """
활동 좋아요를 비활성화 하는 api입니다.
활동 id를 받아서 활동 좋아요를 삭제합니다.
""")
//활동 좋아요 비활성화
@PostMapping("/deactivate-like/{activityId}")
public ResponseEntity<Void> deactivateLike(@PathVariable long activityId) {
likeService.deactivateLike(activityId);
return ResponseEntity.ok().build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,11 @@ public class ActivityLike {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
private User user;

public static ActivityLike of(Activity activity, User user) {
return ActivityLike.builder()
.activity(activity)
.user(user)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.meetup.teame.backend.domain.like.repository;

import com.meetup.teame.backend.domain.activity.entity.Activity;
import com.meetup.teame.backend.domain.like.entity.ActivityLike;
import com.meetup.teame.backend.domain.user.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

Expand All @@ -13,4 +15,5 @@ public interface ActivityLikeRepository extends JpaRepository<ActivityLike, Long
@Query("SELECT al.activity.id FROM ActivityLike al WHERE al.user.id = :userId")
List<Long> findLikedActivityIdsByUserId(Long userId);

ActivityLike findByActivityAndUser(Activity activity, User user);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.meetup.teame.backend.domain.like.service;

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.like.entity.ActivityLike;
import com.meetup.teame.backend.domain.like.repository.ActivityLikeRepository;
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;
import org.springframework.stereotype.Service;

@RequiredArgsConstructor
@Service
public class LikeService {

private final UserRepository userRepository;
private final ActivityRepository activityRepository;
private final ActivityLikeRepository activityLikeRepository;

//활동 좋아요 활성화
public void activateLike(Long activityId) {
Long userId = SecurityContextProvider.getAuthenticatedUserId();
User user = userRepository.findById(userId)
.orElseThrow(() -> new CustomException(ExceptionContent.NOT_FOUND_USER));
Activity activity = activityRepository.findById(activityId)
.orElseThrow(() -> new CustomException(ExceptionContent.NOT_FOUND_ACTIVITY));

ActivityLike like = ActivityLike.of(activity, user);
activityLikeRepository.save(like);
}

//활동 좋아요 비활성화
public void deactivateLike(Long activityId) {
Long userId = SecurityContextProvider.getAuthenticatedUserId();
User user = userRepository.findById(userId)
.orElseThrow(() -> new CustomException(ExceptionContent.NOT_FOUND_USER));
Activity activity = activityRepository.findById(activityId)
.orElseThrow(() -> new CustomException(ExceptionContent.NOT_FOUND_ACTIVITY));

ActivityLike like = activityLikeRepository.findByActivityAndUser(activity, user);
activityLikeRepository.delete(like);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
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.User;
import lombok.*;

import java.time.LocalDate;

@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@Getter
@Builder
public class MyReviewRes {

private Long id;

private String type;

private String title;

private String experienceDetail;

private String name;

private String imageUrl;

@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy.MM.dd")
private LocalDate appointmentDate;

private String review;

public static MyReviewRes of(Review review) {

return MyReviewRes.builder()
.id(review.getId())
.type(review.getAppointmentType().getDescription())
.title(review.getAppointmentTitle())
.experienceDetail(review.getAppointmentDetail())
.name(review.getMentee().getName())
.imageUrl(review.getMentee().getImageUrl())
.appointmentDate(review.getReviewDate())
.review(review.getContent())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ public class Review {
@Comment("내용")
private String content;

@Comment("경험 상세 내용")
private String appointmentDetail;

@Enumerated(EnumType.STRING)
private ExperienceType appointmentType;

@Comment("경험 제목")
private String appointmentTitle;

@ManyToOne(fetch = FetchType.LAZY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
import java.util.List;

public interface ReviewRepositoryCustom {
//List<Review> findReviewsByUserId(Long userId, String type);
List<Review> findReviewsByUserId(Long userId, String type);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.meetup.teame.backend.domain.review.repository.custom;

import com.meetup.teame.backend.domain.experience.entity.ExperienceType;
import com.meetup.teame.backend.domain.review.entity.QReview;
import com.meetup.teame.backend.domain.review.entity.Review;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.jpa.impl.JPAQueryFactory;
Expand All @@ -11,26 +12,26 @@
import static com.meetup.teame.backend.domain.experience.entity.QExperience.experience;
import static com.meetup.teame.backend.domain.review.entity.QReview.review;


@RequiredArgsConstructor
public class ReviewRepositoryImpl implements ReviewRepositoryCustom {
private final JPAQueryFactory jpaQueryFactory;

// @Override
// 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)));
// }
//
// return jpaQueryFactory
// .selectFrom(review)
// .join(review.mentor, experience)
// .fetchJoin()
// .where(builder)
// .fetch();
// }
@Override
public List<Review> findReviewsByUserId(Long userId, String type) {
BooleanBuilder builder = new BooleanBuilder();

builder.and(review.mentor.id.eq(userId));

if (type != null) {
builder.and(review.appointmentType.eq(ExperienceType.of(type)));
}

return jpaQueryFactory
.selectFrom(review)
.where(builder)
.orderBy(review.id.desc())
.fetch();
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.meetup.teame.backend.domain.review.service;

import com.meetup.teame.backend.domain.auth.jwt.SecurityContextProvider;
import com.meetup.teame.backend.domain.review.dto.request.CreateReviewReq;
import com.meetup.teame.backend.domain.review.dto.response.ReadReviewsByMeRes;
import com.meetup.teame.backend.domain.review.dto.response.ReviewByMeRes;
Expand Down Expand Up @@ -32,8 +33,8 @@ public void sendReview(CreateReviewReq createReviewReq, Long reviewId) {
}

public ReadReviewsByMeRes readReviewsByMe() {
//todo : 현재는 더미 유저지만 추후에는 SecurityContextHolder 정보를 조회해서 유저 정보를 가져와야 함
User user = userRepository.findById(5L)
Long userId = SecurityContextProvider.getAuthenticatedUserId();
User user = userRepository.findById(userId)
.orElseThrow(() -> new CustomException(ExceptionContent.NOT_FOUND_USER));
return ReadReviewsByMeRes.of(reviewRepository.findByMentee(user));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +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.user.dto.request.OnboardingReq;
import com.meetup.teame.backend.domain.user.dto.request.ReadCalenderReq;
import com.meetup.teame.backend.domain.user.dto.request.UpdateUserReq;
Expand Down Expand Up @@ -100,19 +101,19 @@ public ResponseEntity<UserInfoRes> updateUserInfo(@RequestBody UpdateUserReq req
return ResponseEntity.ok().body(userInfo);
}

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

@Operation(summary = "내 활동 참여 목록 조회", description = """
내 활동 참여 목록을 조회하는 api입니다.
Expand Down
Loading

0 comments on commit 009010b

Please sign in to comment.