Skip to content

Commit

Permalink
feat : 유저에 reviewCount 필드 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
KkomSang committed Aug 15, 2024
1 parent ef67978 commit 96f2358
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main/java/com/example/locavel/domain/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ public void prePersist() {
private Integer followingCount = 0;
@Builder.Default
private Integer followerCount = 0;
@Builder.Default
private Integer reviewCount = 0;

private int lastCalculatedMonths;

Expand Down Expand Up @@ -168,5 +170,7 @@ public void setTravelerGrade(Grade travelerGrade) {
public void setFollowerCountPlus(){this.followerCount++;}
public void setFollowingCountMinus(){this.followingCount--;}
public void setFollowerCountMinus(){this.followerCount--;}
public void setReviewCountPlus(){this.reviewCount++;}
public void setReviewCountMinus(){this.reviewCount--;}

}
11 changes: 11 additions & 0 deletions src/main/java/com/example/locavel/service/ReviewService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,30 @@
import com.example.locavel.apiPayload.code.status.ErrorStatus;
import com.example.locavel.apiPayload.exception.handler.ReviewsHandler;
import com.example.locavel.converter.ReviewConverter;
import com.example.locavel.converter.UserConverter;
import com.example.locavel.domain.Places;
import com.example.locavel.domain.ReviewImg;
import com.example.locavel.domain.Reviews;
import com.example.locavel.domain.User;
import com.example.locavel.domain.enums.Category;
import com.example.locavel.domain.enums.Traveler;
import com.example.locavel.repository.PlaceRepository;
import com.example.locavel.repository.ReviewImgRepository;
import com.example.locavel.repository.ReviewRepository;
import com.example.locavel.repository.UserRepository;
import com.example.locavel.web.dto.ReviewDTO.ReviewRequestDTO;
import com.example.locavel.web.dto.ReviewDTO.ReviewResponseDTO;
import com.example.locavel.web.dto.UserDTO.UserResponseDto;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.YearMonth;
import java.util.List;
import java.util.stream.Collectors;

Expand All @@ -43,6 +49,8 @@ public ReviewResponseDTO.ReviewResultDTO createReview(User user, Long placeId, R
uploadReviewImg(reviewImgUrls, savedReview, false);
}
placeService.setReview(place);
user.setReviewCountPlus();
userRepository.save(user);
return ReviewConverter.toReviewResultDTO(savedReview);
}

Expand All @@ -64,11 +72,14 @@ public ReviewResponseDTO.ReviewResultDTO deleteReview(Long reviewId) {
Places place = review.getPlace();
ReviewResponseDTO.ReviewResultDTO resultDTO = ReviewConverter.toReviewResultDTO(review);
List<ReviewImg> reviewImgList = reviewImgRepository.findAllByReviews(review);
User user = review.getUser();
for(ReviewImg imgUrl : reviewImgList) {
s3Uploader.deleteFile(imgUrl.getImgUrl());
}
reviewRepository.delete(review);
placeService.setReview(place);
user.setReviewCountMinus();
userRepository.save(user);
return resultDTO;
}
public void uploadReviewImg(List<MultipartFile> reviewImg, Reviews reviews, boolean update) {
Expand Down

0 comments on commit 96f2358

Please sign in to comment.