Skip to content

Commit

Permalink
Merge pull request #116 from gague-jinsim-in-jadeul/refact/115_change…
Browse files Browse the repository at this point in the history
…_res-estimate_dto

⚡ Change resp estimate dto field
  • Loading branch information
MinkeySon authored Jan 24, 2025
2 parents df98c55 + c7b54fa commit e18c34f
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 이미지를 삭제합니다.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public interface EstimateDAO {
Page<ResponseMyFurnitureDto> getMyFurniture(String nickname, Pageable pageable);

/**
* 저장한 견적서 반환
* 공방관계자가 견적 선정을 끝낸 견적서를 반환합니다.
* @param nickname
* @param pageable
* @return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,36 +81,21 @@ public Page<ResponseMyFurnitureDto> getMyFurniture(String nickname, Pageable pag
public Page<ResponseCompleteEstimate> getMyEstimates(String nickname, Pageable pageable) {
try{
log.info("[GET-MY-FURNITURE] collecting my furnitures...");
User user = userRepository.findByNickName(nickname);
Page<Estimate> estimates = estimateRepository.findByNickName(user, pageable);
Optional<User> optionalUser = userRepository.findUserByNickname(nickname);

AtomicInteger cnt = new AtomicInteger();
List<ResponseCompleteEstimate> estimatesDto = estimates.stream()
.map(estimate -> {
Page<Estimate> 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<ResponseCompleteEstimate> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.*;
import org.gagu.gagubackend.chat.dto.response.ResponseChatDto;
import org.gagu.gagubackend.estimate.domain.Estimate;

@Getter
@Setter
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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<Estimate> findEstimateById(Long id);
Page<Estimate> findCompletedEstimates(User user, Pageable pageable);
}
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -26,4 +32,33 @@ public Optional<Estimate> findEstimateById(Long id) {
.where(qEstimate.id.eq(id))
.fetchOne());
}

@Override
public Page<Estimate> findCompletedEstimates(User user, Pageable pageable) {
QEstimate qEstimate = QEstimate.estimate;

int limit = pageable.getPageSize();
int pageNumber = pageable.getPageNumber();
long offset = (long) limit * pageNumber;

List<Estimate> 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<Long> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public interface EstimateService {
ResponseEntity<?> saveEstimate(EstimateChatContentsDto dto, String nickname);

/**
* 공방관계자가 작성한 견적서를 반환합니다.
* 공방관계자가 견적 선정을 끝낸 견적서를 반환합니다.
* @param nickname
* @param pageable
* @return paging
Expand Down

0 comments on commit e18c34f

Please sign in to comment.