Skip to content

Commit

Permalink
feat:page 값 수정 , reviewList 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
hyojoonm committed Nov 30, 2022
1 parent cbab4bc commit b8c8c47
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public ResponseEntity<Long> delete(@PathVariable Long productsId){
public ResponseEntity getLists(@RequestParam int page,@PathVariable int filterId){
int size= 15;
log.info("getLists 실행 ");
Page<Product> pageProduct = productService.getLists(page, size,filterId);
Page<Product> pageProduct = productService.getLists(page-1, size,filterId);
log.info(" 페이징 리스트로 변환 ");
List<Product> response = pageProduct.getContent();
log.info(" 상품 목록 조회 완료 ");
Expand All @@ -88,7 +88,7 @@ public ResponseEntity getListReview(@PathVariable Long productsId){
public ResponseEntity getListCategory(@PathVariable Long categoryId,@RequestParam int page,@PathVariable int filterId){
int size= 15;
log.info(" getListCategory 실행 ");
Page<Product> pageProduct = productService.getCategory(categoryId,filterId, page, size);
Page<Product> pageProduct = productService.getCategory(categoryId,filterId, page-1, size);
log.info(" getcategory 리스트로 변환 ");
List<Product> content = pageProduct.getContent();
log.info(" getListCategory 완료 ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public ResponseEntity getLest(@CurrentUser CustomUserDetails authUser, @RequestP
}
Long userId = authUser.getUser().getUserId();
log.info("userId : ",userId);
Page<Review> reviewPage = reviewService.getList(userId, page, size);
Page<Review> reviewPage = reviewService.getList(userId, page-1, size);
log.info("reviewPage :",reviewPage);
List<Review> content = reviewPage.getContent();
log.info("content : ",content);
Expand All @@ -92,7 +92,7 @@ public ResponseEntity getLest(@CurrentUser CustomUserDetails authUser, @RequestP
public ResponseEntity getLestProduct(@PathVariable Long productId, @RequestParam int page){
int size = 15;
log.info("getLestProduct 실행 ");
Page<Review> reviews = reviewService.getListProduct(productId, page, size);
Page<Review> reviews = reviewService.getListProduct(productId, page-1, size);
log.info("reviews : " , reviews);
List<Review> content = reviews.getContent();
log.info("content : ",content);
Expand All @@ -105,7 +105,7 @@ public ResponseEntity getLestProduct(@PathVariable Long productId, @RequestParam
public ResponseEntity getProductReview(@CurrentUser CustomUserDetails authUser,@RequestParam int page){
int size = 15;
Long userId = authUser.getUser().getUserId();
Page<Review> reviews = reviewService.getProductReview(userId, page, size);
Page<Review> reviews = reviewService.getProductReview(userId, page-1, size);
List<Review> content = reviews.getContent();
return new ResponseEntity(new MultiResponse<>(reviewMapper.reviewsToReviewResponseDto(content),reviews),HttpStatus.OK);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,11 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

@Service
Expand Down Expand Up @@ -138,23 +135,8 @@ public Review getRead(Long reviewId) {

@Transactional(readOnly = true)
public Page<Review> getProductReview(Long userId,int page,int size) {
log.info("getProductReview 실행");
return reviewRepository.findByUserId(userId,PageRequest.of(page,size,Sort.by("reviewId").descending()));

List<Review> response = new ArrayList<>();
PageRequest pageable = PageRequest.of(page, size, Sort.by("reviewId").descending());

User user = userRepository.findById(userId).orElseThrow(MemberNotFound::new);
List<Product> product = productRepository.findByUserId(userId);
// TODO : 쿼리가 너무 많이 나감 더 줄일 방법이 분명히 있음.
for (Product list : product) {
List<Review> byProductId = reviewRepository.findByProductId(list.getProductId());
response.addAll(byProductId);
}


int start =(int) pageable.getOffset();
int end = Math.min((start+ pageable.getPageSize()), response.size());
Page<Review> reviewPage = new PageImpl<>(response.subList(start,end),pageable, response.size());

return reviewPage;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ public interface ReviewRepository extends JpaRepository<Review,Long> {
@Query("select r from Review r where r.product.productId = :productId")
List<Review> findByProductId(@Param("productId") long productId);

@Query("select r from Review r join Product p on p.productId = r.proId where p.user.userId = :userId")
Page<Review> findByUserId(@Param("userId") Long userId,Pageable pageable);
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.backend.global.config.auth.dto;

import com.backend.domain.point.application.PointService;
import com.backend.domain.point.domain.PointType;
import com.backend.domain.user.domain.User;
import lombok.Builder;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.crypto.password.PasswordEncoder;

import java.util.Map;

Expand Down Expand Up @@ -92,7 +95,7 @@ private static OAuthAttributes ofKakao(String registrationId, String userNameAtt
.build();
}

public User toEntity(PointService pointService, PasswordEncoder passwordEncoder) {
public User toEntity() {
User user = User.builder()
.userRole("ROLE_USER")
.profileImage(profileImage)
Expand All @@ -102,11 +105,6 @@ public User toEntity(PointService pointService, PasswordEncoder passwordEncoder)
// .about("안녕하세요. " + name + "입니다.")
.build();

user.setPassword(passwordEncoder.encode(user.getNickname()));

pointService.addCash(user, 1000000, PointType.SignUpPoint);
log.info("회원가입 포인트 지급");

return user;

}
Expand Down

0 comments on commit b8c8c47

Please sign in to comment.