diff --git a/src/main/java/org/gagu/gagubackend/GaguBackendApplication.java b/src/main/java/org/gagu/gagubackend/GaguBackendApplication.java index 15f2dbf..1852a3b 100644 --- a/src/main/java/org/gagu/gagubackend/GaguBackendApplication.java +++ b/src/main/java/org/gagu/gagubackend/GaguBackendApplication.java @@ -4,10 +4,7 @@ import io.swagger.v3.oas.annotations.servers.Server; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.Bean; import org.springframework.data.jpa.repository.config.EnableJpaAuditing; -import org.springframework.web.servlet.config.annotation.CorsRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @OpenAPIDefinition(servers = {@Server(url = "https://gagu.me", description = "Default Server url")} ) @SpringBootApplication diff --git a/src/main/java/org/gagu/gagubackend/estimate/controller/EstimateController.java b/src/main/java/org/gagu/gagubackend/estimate/controller/EstimateController.java index d73d20c..504a6e4 100644 --- a/src/main/java/org/gagu/gagubackend/estimate/controller/EstimateController.java +++ b/src/main/java/org/gagu/gagubackend/estimate/controller/EstimateController.java @@ -78,8 +78,8 @@ public ResponseEntity getEstimates(HttpServletRequest request, @RequestParam( String token = jwtTokenProvider.extractToken(request); String nickname = jwtTokenProvider.getUserNickName(token); - Pageable pageable = PageRequest.of(page,4, Sort.Direction.DESC,"modifiedDate"); - return ResponseEntity.ok(estimateService.getEstimate(nickname,pageable)); + Pageable pageable = PageRequest.of(page,4); + return ResponseEntity.ok(estimateService.getEstimate(nickname, pageable)); } @Operation(summary = "저장한 가구 삭제", description = "사용자가 저장한 2D, 3D 이미지를 삭제합니다.") diff --git a/src/main/java/org/gagu/gagubackend/estimate/dao/EstimateDAO.java b/src/main/java/org/gagu/gagubackend/estimate/dao/EstimateDAO.java index 48d5cf3..e0130f0 100644 --- a/src/main/java/org/gagu/gagubackend/estimate/dao/EstimateDAO.java +++ b/src/main/java/org/gagu/gagubackend/estimate/dao/EstimateDAO.java @@ -26,7 +26,7 @@ public interface EstimateDAO { Page getMyFurniture(String nickname, Pageable pageable); /** - * 저장한 견적서 반환 + * 공방관계자가 견적 선정을 끝낸 견적서를 반환합니다. * @param nickname * @param pageable * @return diff --git a/src/main/java/org/gagu/gagubackend/estimate/dao/impl/EstimateDAOImpl.java b/src/main/java/org/gagu/gagubackend/estimate/dao/impl/EstimateDAOImpl.java index 386dbd5..17b95d3 100644 --- a/src/main/java/org/gagu/gagubackend/estimate/dao/impl/EstimateDAOImpl.java +++ b/src/main/java/org/gagu/gagubackend/estimate/dao/impl/EstimateDAOImpl.java @@ -81,36 +81,21 @@ public Page getMyFurniture(String nickname, Pageable pag public Page getMyEstimates(String nickname, Pageable pageable) { try{ log.info("[GET-MY-FURNITURE] collecting my furnitures..."); - User user = userRepository.findByNickName(nickname); - Page estimates = estimateRepository.findByNickName(user, pageable); + Optional optionalUser = userRepository.findUserByNickname(nickname); - AtomicInteger cnt = new AtomicInteger(); - List estimatesDto = estimates.stream() - .map(estimate -> { + Page estimates = estimateRepository.findCompletedEstimates(optionalUser.get(), pageable); - ResponseCompleteEstimate dto = new ResponseCompleteEstimate(); - if(estimate.getDescription() != null && estimate.getPrice() != null){ - cnt.getAndIncrement(); - dto.setId(estimate.getId()); - dto.setFurniture2DUrl(estimate.getFurniture2DUrl()); - dto.setFurnitureGlbUrl(estimate.getFurnitureGlbUrl()); - dto.setFurnitureGltfUrl(estimate.getFurnitureGltfUrl()); - dto.setFurnitureName(estimate.getFurnitureName()); - dto.setPrice(estimate.getPrice()); - dto.setDescription(estimate.getDescription()); - dto.setCreatedDate(estimate.getCreatedDate()); - return dto; - } - return null; - }).collect(Collectors.toList()); + List estimatesDto = estimates.stream() + .map(v -> { + return new ResponseCompleteEstimate(v); + }).collect(Collectors.toList()); return new PageImpl<>(estimatesDto, pageable, estimatesDto.size()); }catch (Exception e){ log.error("[GET-MY-FURNITURE] fail to collect my furnitures"); e.printStackTrace(); + return null; } - - return null; } @Override diff --git a/src/main/java/org/gagu/gagubackend/estimate/dto/response/ResponseCompleteEstimate.java b/src/main/java/org/gagu/gagubackend/estimate/dto/response/ResponseCompleteEstimate.java index 3476c23..707fb3a 100644 --- a/src/main/java/org/gagu/gagubackend/estimate/dto/response/ResponseCompleteEstimate.java +++ b/src/main/java/org/gagu/gagubackend/estimate/dto/response/ResponseCompleteEstimate.java @@ -2,6 +2,7 @@ import lombok.*; import org.gagu.gagubackend.chat.dto.response.ResponseChatDto; +import org.gagu.gagubackend.estimate.domain.Estimate; @Getter @Setter @@ -15,7 +16,20 @@ public class ResponseCompleteEstimate { private String furniture2DUrl; private String furnitureGlbUrl; private String furnitureGltfUrl; - private String createdDate; + private String modifiedDate; + private String makerName; private String price; private String description; + + public ResponseCompleteEstimate(Estimate estimate){ + this.id = estimate.getId(); + this.furnitureName = estimate.getFurnitureName(); + this.furniture2DUrl = estimate.getFurniture2DUrl(); + this.furnitureGlbUrl = estimate.getFurnitureGlbUrl(); + this.furnitureGltfUrl = estimate.getFurnitureGltfUrl(); + this.modifiedDate = estimate.getModifiedDate(); + this.makerName = estimate.getMakerName(); + this.price = estimate.getPrice(); + this.description = estimate.getDescription(); + } } diff --git a/src/main/java/org/gagu/gagubackend/estimate/repository/custom/EstimateRepositoryCustom.java b/src/main/java/org/gagu/gagubackend/estimate/repository/custom/EstimateRepositoryCustom.java index 8f78707..d0dde41 100644 --- a/src/main/java/org/gagu/gagubackend/estimate/repository/custom/EstimateRepositoryCustom.java +++ b/src/main/java/org/gagu/gagubackend/estimate/repository/custom/EstimateRepositoryCustom.java @@ -1,9 +1,13 @@ package org.gagu.gagubackend.estimate.repository.custom; +import org.gagu.gagubackend.auth.domain.User; import org.gagu.gagubackend.estimate.domain.Estimate; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import java.util.Optional; public interface EstimateRepositoryCustom { Optional findEstimateById(Long id); + Page findCompletedEstimates(User user, Pageable pageable); } diff --git a/src/main/java/org/gagu/gagubackend/estimate/repository/custom/impl/EstimateRepositoryCustomImpl.java b/src/main/java/org/gagu/gagubackend/estimate/repository/custom/impl/EstimateRepositoryCustomImpl.java index 2d7b464..66ae9f2 100644 --- a/src/main/java/org/gagu/gagubackend/estimate/repository/custom/impl/EstimateRepositoryCustomImpl.java +++ b/src/main/java/org/gagu/gagubackend/estimate/repository/custom/impl/EstimateRepositoryCustomImpl.java @@ -1,12 +1,18 @@ package org.gagu.gagubackend.estimate.repository.custom.impl; +import com.querydsl.jpa.JPQLQuery; import com.querydsl.jpa.impl.JPAQueryFactory; import jakarta.persistence.EntityManager; +import org.gagu.gagubackend.auth.domain.User; import org.gagu.gagubackend.estimate.domain.Estimate; import org.gagu.gagubackend.estimate.domain.QEstimate; import org.gagu.gagubackend.estimate.repository.custom.EstimateRepositoryCustom; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.support.PageableExecutionUtils; import org.springframework.stereotype.Service; +import java.util.List; import java.util.Optional; @Service public class EstimateRepositoryCustomImpl implements EstimateRepositoryCustom { @@ -26,4 +32,33 @@ public Optional findEstimateById(Long id) { .where(qEstimate.id.eq(id)) .fetchOne()); } + + @Override + public Page findCompletedEstimates(User user, Pageable pageable) { + QEstimate qEstimate = QEstimate.estimate; + + int limit = pageable.getPageSize(); + int pageNumber = pageable.getPageNumber(); + long offset = (long) limit * pageNumber; + + List estimateList = jpaQueryFactory.select(qEstimate) + .from(qEstimate) + .where(qEstimate.nickName.eq(user) + .and(qEstimate.makerName.isNotNull()) + .and(qEstimate.price.isNotNull()) + .and(qEstimate.description.isNotNull())) + .offset(offset) + .limit(limit) + .orderBy(qEstimate.modifiedDate.desc()) + .fetch(); + + JPQLQuery count = jpaQueryFactory.select(qEstimate.count()) + .from(qEstimate) + .where(qEstimate.nickName.eq(user) + .and(qEstimate.makerName.isNotNull()) + .and(qEstimate.price.isNotNull()) + .and(qEstimate.description.isNotNull())); + + return PageableExecutionUtils.getPage(estimateList, pageable, count::fetchOne); + } } diff --git a/src/main/java/org/gagu/gagubackend/estimate/service/EstimateService.java b/src/main/java/org/gagu/gagubackend/estimate/service/EstimateService.java index 3f465a1..eb2c659 100644 --- a/src/main/java/org/gagu/gagubackend/estimate/service/EstimateService.java +++ b/src/main/java/org/gagu/gagubackend/estimate/service/EstimateService.java @@ -40,7 +40,7 @@ public interface EstimateService { ResponseEntity saveEstimate(EstimateChatContentsDto dto, String nickname); /** - * 공방관계자가 작성한 견적서를 반환합니다. + * 공방관계자가 견적 선정을 끝낸 견적서를 반환합니다. * @param nickname * @param pageable * @return paging