Skip to content

Commit

Permalink
Merge pull request #34 from Central-MakeUs/fix/popcornReview
Browse files Browse the repository at this point in the history
[fix] 팝콘작 리뷰
  • Loading branch information
AlmondBreez3 authored Jan 30, 2024
2 parents d78cd55 + 48eeb8b commit 4038db0
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.example.api.Popcorn.dto.response.PopcornReviewResponse;
import com.example.api.Popcorn.service.*;
import com.example.api.screening.dto.request.PostReviewRequest;
import com.example.api.screening.dto.response.ScreeningReviewUserResponse;
import com.example.domains.popcorn.entity.Popcorn;
import com.example.domains.popcorn.entity.dto.PopcornKeywordResponseDto;
import io.swagger.v3.oas.annotations.Operation;
Expand All @@ -29,6 +30,7 @@ public class PopcornController {

private final GetTopRatedPopcornKeyword getTopRatedPopcornKeyword;
private final GetPopcornDetailUseCase getPopcornDetailUseCase;
private final PostPopcornReviewComplainUseCase postPopcornReviewComplainUseCase;
@Operation(summary = "지난주 투표수 가장 높았던 3개 반환. 이번 주 상영작임", description = "이번 주 상영작 3개 가져오기")
@GetMapping
public List<PopcornResponse> getPopcorn() {
Expand Down Expand Up @@ -69,6 +71,15 @@ public List<PopcornReviewResponse> reviewResponseList(@PathVariable("popcornId")
return getPopcornReviewUseCase.execute(popcornId);
}

//TODO 팝콘작 리뷰
@Operation(summary = "팝콘작 리뷰 신고하기", description = "팝콘작 리뷰 신고하기")
@GetMapping("/review/complain/{popcornUserId}")
public void reviewsFromPopcorn(@PathVariable("popcornUserId") Long popcornUserId)
{
postPopcornReviewComplainUseCase.execute(popcornUserId);
}


//TODO 내가 쓴 팝콘작 리뷰
@Operation(summary = "팝콘작들에 대한 나의 리뷰 반환", description = "popcornId 가져와서 요청하기")
@GetMapping("/my/reviews")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.example.api.Popcorn.service;

import com.example.adaptor.UseCase;
import com.example.api.config.security.SecurityUtil;
import com.example.domains.block.adaptor.BlockAdaptor;
import com.example.domains.popcornUser.adaptor.PopcornUserAdaptor;
import com.example.domains.popcornUser.entity.PopcornUser;
import com.example.domains.popcornUser.repository.PopcornUserRepository;
import com.example.domains.screeningReview.entity.QScreeningReview;
import com.example.domains.screeningReview.entity.ScreeningReview;
import com.example.domains.user.entity.User;
import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Transactional;

@UseCase
@RequiredArgsConstructor
public class PostPopcornReviewComplainUseCase {
private final BlockAdaptor blockAdaptor;
private final PopcornUserAdaptor popcornUserAdaptor;
private final PopcornUserRepository popcornUserRepository;
public void execute(Long reviewId) {
Long userId = SecurityUtil.getCurrentUserId();
popcornUserAdaptor.postComplain(reviewId,userId);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
@RequiredArgsConstructor
public class BlockAdaptor {
private final BlockRepository blockRepository;
public void save(Long userId,Long reportedUserId, Long reviewId){
validateUser(userId,reviewId);
final Block result = Block.of(userId,reportedUserId,reviewId);
public void save(Long userId,Long reportedUserId, Long reviewId,Long popcornReviewId){
validateUser(userId,reviewId,popcornReviewId);
final Block result = Block.of(userId,reportedUserId,reviewId,popcornReviewId);
blockRepository.save(result);
}

private void validateUser(Long userId, Long reviewId) {
if(blockRepository.existsByUserIdAndScreeningReviewId(userId,reviewId)) {
private void validateUser(Long userId, Long reviewId,Long popcornReviewId) {
if(blockRepository.existsByUserIdAndScreeningReviewId(userId,reviewId)||blockRepository.existsByUserIdAndPopcornReviewId(userId,popcornReviewId)) {
throw DuplicateBlockRequest.EXCEPTION;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,21 @@ public class Block extends BaseTimeEntity {

private Long blockedUserId;
private Long screeningReviewId;
private Long popcornReviewId;

@Builder
public Block(Long userId, Long blockedUserId,Long screeningReviewId){
public Block(Long userId, Long blockedUserId,Long screeningReviewId,Long popcornReviewId){
this.userId=userId;
this.blockedUserId=blockedUserId;
this.screeningReviewId = screeningReviewId;
this.popcornReviewId = popcornReviewId;
}
public static Block of(Long userId, Long blockedUserId,Long screeningReviewId) {
public static Block of(Long userId, Long blockedUserId,Long screeningReviewId,Long popcornReviewId) {
return Block.builder()
.userId(userId)
.blockedUserId(blockedUserId)
.screeningReviewId(screeningReviewId)
.popcornReviewId(popcornReviewId)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@

public interface BlockRepository extends JpaRepository<Block,Long> {
boolean existsByUserIdAndScreeningReviewId(Long userId, Long screeningReviewId);

boolean existsByUserIdAndPopcornReviewId(Long userId, Long popcornReviewId);
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
package com.example.domains.popcornUser.adaptor;

import com.example.adaptor.Adaptor;
import com.example.domains.block.adaptor.BlockAdaptor;
import com.example.domains.popcorn.entity.Popcorn;
import com.example.domains.popcorn.entity.QPopcorn;
import com.example.domains.popcornUser.entity.PopcornUser;
import com.example.domains.popcornUser.entity.QPopcornUser;
import com.example.domains.popcornUser.repository.PopcornUserRepository;
import com.example.domains.screeningReview.entity.QScreeningReview;
import com.example.domains.screeningReview.entity.ScreeningReview;
import com.example.domains.user.entity.User;
import com.google.api.client.util.SecurityUtils;
import com.querydsl.jpa.impl.JPAQueryFactory;
import com.querydsl.jpa.impl.JPAUpdateClause;
import lombok.RequiredArgsConstructor;
import org.apache.catalina.security.SecurityUtil;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
Expand All @@ -17,6 +24,7 @@
public class PopcornUserAdaptor {
private final PopcornUserRepository popcornUserRepository;
private final JPAQueryFactory jpaQueryFactory;
private final BlockAdaptor blockAdaptor;
public void save(PopcornUser popcornUser) {
popcornUserRepository.save(popcornUser);
}
Expand Down Expand Up @@ -44,5 +52,64 @@ public List<PopcornUser> findAllByPopcornIdAndUserId(Long popcornId, Long userId
public List<PopcornUser> findAllByUserId(Long userId) {
return popcornUserRepository.findAllByUserId(userId);
}


//1-30일부터 ㄱㄱ

@Transactional
public void postComplain(Long reviewId,Long userId) {
PopcornUser popcornUser = findById(reviewId);

blockAdaptor.save(userId,popcornUser.getUser().getId(),null,reviewId);

int complainCount = popcornUser.getComplaintCount();
if (complainCount == 4) {
incrementComplaintCount(popcornUser);
// Get user from the screeningReview
User user = popcornUser.getUser();

deActivateUser(user);

// Delete the screeningReview
changeBlindStatus(popcornUser); // Assuming there is a method to delete screeningReview
} else {
incrementComplaintCount(popcornUser);
}
}


private PopcornUser findById(Long reviewId) {
return popcornUserRepository.findById(reviewId).get();
}

@Transactional
public void deActivateUser(User user) {
user.turnBlind();
}

@Transactional
public void changeBlindStatus(PopcornUser popcornUser) {
QPopcornUser qPopcornUser = QPopcornUser.popcornUser;
JPAUpdateClause updateClause = jpaQueryFactory.update(qPopcornUser);

// // Set blindStatus to true
updateClause
.set(qPopcornUser.isBlind, true)
.where(qPopcornUser.id.eq(popcornUser.getId()))
.execute();

}

@Transactional
public void incrementComplaintCount(PopcornUser popcornUser) {
QPopcornUser qPopcornUser = QPopcornUser.popcornUser;
JPAUpdateClause updateClause = jpaQueryFactory.update(qPopcornUser);

// // Set blindStatus to true
updateClause
.set(qPopcornUser.complaintCount, qPopcornUser.complaintCount.add(1))
.where(qPopcornUser.id.eq(popcornUser.getId()))
.execute();
}
// int total = popcornUserRepository.findAllByPopcornId(popcorn.getId()).size();
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ public interface PopcornUserRepository extends JpaRepository<PopcornUser, Long>
List<PopcornUser> findAllByPopcornIdAndUserId(Long popcornId, Long userId);

List<PopcornUser> findAllByUserId(Long userId);

Optional<PopcornUser> findById(Long id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public List<ScreeningWithReviewDto> getPostedScreeningReviews(Long userId) {
public void postComplain(Long reviewId,Long userId) {
ScreeningReview screeningReview = findById(reviewId);

blockAdaptor.save(userId,screeningReview.getUserScreening().getUser().getId(),reviewId);
blockAdaptor.save(userId,screeningReview.getUserScreening().getUser().getId(),reviewId,null);

int complainCount = screeningReview.getComplaintCount();
if (complainCount == 4) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public List<ScreeningReviewResponseDto> getReviewListByScreening(Long screeningI
.on(userScreening.id.eq(QScreeningReview.screeningReview.userScreening.id)
.and(userScreening.isHost.eq(false))
)
.where(userScreening.screening.id.eq(screeningId))
.where(userScreening.screening.id.eq(screeningId),QScreeningReview.screeningReview.isBlind.eq(false))
.fetch();


Expand Down

0 comments on commit 4038db0

Please sign in to comment.