From b38211176ba46aeb3c1dfc9f2688771ce9355c39 Mon Sep 17 00:00:00 2001 From: PicturePark1101 Date: Wed, 9 Oct 2024 17:08:54 +0900 Subject: [PATCH 01/14] =?UTF-8?q?refactor=20:=20Scrap=20-=20limjang=20?= =?UTF-8?q?=EA=B4=80=EA=B3=84=20=EB=B3=80=EA=B2=BD=20#241?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../umc/th/juinjang/model/entity/Limjang.java | 20 +++---------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/src/main/java/umc/th/juinjang/model/entity/Limjang.java b/src/main/java/umc/th/juinjang/model/entity/Limjang.java index a3d24dd..f56bab9 100644 --- a/src/main/java/umc/th/juinjang/model/entity/Limjang.java +++ b/src/main/java/umc/th/juinjang/model/entity/Limjang.java @@ -81,7 +81,7 @@ public class Limjang extends BaseEntity { @OneToMany(mappedBy = "limjangId", cascade = CascadeType.ALL, orphanRemoval = true) private List answerList = new ArrayList<>(); - @OneToOne(fetch = FetchType.LAZY, mappedBy = "limjangId", cascade = CascadeType.ALL, orphanRemoval = true) + @OneToOne(mappedBy = "limjangId", cascade = CascadeType.ALL, orphanRemoval = true) private Report report; @OneToMany(mappedBy = "limjangId", cascade = CascadeType.ALL, orphanRemoval = true) @@ -91,8 +91,8 @@ public class Limjang extends BaseEntity { @BatchSize(size = 100) private List imageList = new ArrayList<>(); - @OneToOne(fetch = FetchType.LAZY, mappedBy = "limjangId", cascade = CascadeType.ALL, orphanRemoval = true) - private Scrap scrap; + @OneToMany(mappedBy = "limjangId", cascade = CascadeType.ALL, orphanRemoval = true) + private List scrap = new ArrayList<>(); @Column(name = "record_count") @ColumnDefault("0") //default 0 @@ -106,15 +106,6 @@ public void saveMemberAndPrice(Member member, LimjangPrice limjangPrice){ this.memberId = member; } - public void addScrap(Scrap scrap) { - this.scrap = scrap; - scrap.saveLimjang(this); - } - - public void removeScrap(){ - this.scrap = null; - } - public void updateLimjang(String address, String addressDetail, String nickname, LimjangPriceType priceType){ this.address = address; this.addressDetail = addressDetail; @@ -128,9 +119,4 @@ public void updateMemo(String memo){ public void saveImages(Image image){ this.imageList.add(image); } - - public void saveReport(Report report){ - this.report = report; - } - } \ No newline at end of file From b5ea432e629700042ccfce6b95fd08e4b6e4145e Mon Sep 17 00:00:00 2001 From: PicturePark1101 Date: Wed, 9 Oct 2024 17:09:26 +0900 Subject: [PATCH 02/14] =?UTF-8?q?refactor=20:=20=EC=9E=84=EC=9E=A5=20?= =?UTF-8?q?=EA=B2=80=EC=83=89=20responseDTO=20=EB=B3=80=EA=B2=BD=20#241?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../limjang/LimjangTotalListConverter.java | 58 ------------------- .../LimjangsGetByKeywordResponse.java | 40 +++++++++++++ 2 files changed, 40 insertions(+), 58 deletions(-) delete mode 100644 src/main/java/umc/th/juinjang/converter/limjang/LimjangTotalListConverter.java create mode 100644 src/main/java/umc/th/juinjang/model/dto/limjang/response/LimjangsGetByKeywordResponse.java diff --git a/src/main/java/umc/th/juinjang/converter/limjang/LimjangTotalListConverter.java b/src/main/java/umc/th/juinjang/converter/limjang/LimjangTotalListConverter.java deleted file mode 100644 index 5f7adc0..0000000 --- a/src/main/java/umc/th/juinjang/converter/limjang/LimjangTotalListConverter.java +++ /dev/null @@ -1,58 +0,0 @@ -package umc.th.juinjang.converter.limjang; - -import static umc.th.juinjang.service.LimjangService.LimjangPriceBridge.makePriceListVersion2; - -import java.util.Comparator; -import java.util.List; -import java.util.Optional; -import umc.th.juinjang.model.dto.limjang.response.LimjangTotalListResponseDTO; -import umc.th.juinjang.model.dto.limjang.response.LimjangTotalListResponseDTO.LimjangListDto; -import umc.th.juinjang.model.entity.Image; -import umc.th.juinjang.model.entity.Limjang; -import umc.th.juinjang.model.entity.LimjangPrice; - - -public class LimjangTotalListConverter { - - public static LimjangTotalListResponseDTO.TotalListDto toLimjangTotalList( - List limjangList - ) { - - List limjangListDto = limjangList.stream() - .map(limjang -> LimjangTotalListConverter.toLimjangList(limjang, limjang.getLimjangPrice())) - .toList(); - - return LimjangTotalListResponseDTO.TotalListDto.builder() - .limjangList(limjangListDto) - .build(); - } - - public static LimjangListDto toLimjangList( - Limjang limjang, LimjangPrice limjangPrice) { - - int limitImageListSize = limjang.getScrap() == null ? 1 : 3; - - List urlList = limjang.getImageList().stream() - .sorted(Comparator.comparing(Image::getCreatedAt)) // image를 createdAt 기준으로 정렬 - .map(Image::getImageUrl) - .limit(limitImageListSize) - .toList(); - - List priceList = makePriceListVersion2(limjang.getPriceType(), limjang.getPurpose(), limjangPrice); - - return LimjangListDto.builder() - .limjangId(limjang.getLimjangId()) - .images(urlList) - .nickname(limjang.getNickname()) - .isScraped(limjang.getScrap() != null) - .purposeCode(limjang.getPurpose().getValue()) - .priceType(limjang.getPriceType().getValue()) - .priceList(priceList) - .totalAverage(Optional.ofNullable(limjang.getReport()) - .flatMap(report -> Optional.ofNullable(report.getTotalRate()) - .map(Object::toString)) - .orElse(null)) - .address(limjang.getAddress()) - .build(); - } -} diff --git a/src/main/java/umc/th/juinjang/model/dto/limjang/response/LimjangsGetByKeywordResponse.java b/src/main/java/umc/th/juinjang/model/dto/limjang/response/LimjangsGetByKeywordResponse.java new file mode 100644 index 0000000..8c36bb8 --- /dev/null +++ b/src/main/java/umc/th/juinjang/model/dto/limjang/response/LimjangsGetByKeywordResponse.java @@ -0,0 +1,40 @@ +package umc.th.juinjang.model.dto.limjang.response; + +import static umc.th.juinjang.service.LimjangService.LimjangPriceBridge.makePriceListVersion2; + +import java.util.List; +import java.util.Map; +import umc.th.juinjang.model.entity.Image; +import umc.th.juinjang.model.entity.Limjang; + +public record LimjangsGetByKeywordResponse(List limjangList) { + record LimjangByKeywordResponse( + long limjangId, + List images, + int purposeCode, + boolean isScraped, + String nickname, + int priceType, + List priceList, + String totalAverage, + String address + ) { + static LimjangByKeywordResponse of(Limjang limjang, boolean isScraped) { + return new LimjangByKeywordResponse( + limjang.getLimjangId(), + limjang.getImageList().stream().map(Image::getImageUrl).toList(), + limjang.getPurpose().getValue(), + isScraped, + limjang.getNickname(), + limjang.getPriceType().getValue(), + makePriceListVersion2(limjang.getPriceType(), limjang.getPurpose(), limjang.getLimjangPrice()), + limjang.getReport() == null ? null : limjang.getReport().getTotalRate().toString(), + limjang.getAddress() + ); + } + } + + public static LimjangsGetByKeywordResponse of(List limjangList, Map mapLimjangToScrapStatus) { + return new LimjangsGetByKeywordResponse(limjangList.stream().map(it -> LimjangByKeywordResponse.of(it, mapLimjangToScrapStatus.get(it.getLimjangId()))).toList()); + } +} From 63211f8d162d420da853dc7c427189ee1b01c1f9 Mon Sep 17 00:00:00 2001 From: PicturePark1101 Date: Wed, 9 Oct 2024 17:09:42 +0900 Subject: [PATCH 03/14] =?UTF-8?q?refactor=20:=20=ED=95=A8=EC=88=98?= =?UTF-8?q?=ED=99=94=20#241?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../limjang/LimjangQueryDslRepositoryImpl.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/umc/th/juinjang/repository/limjang/LimjangQueryDslRepositoryImpl.java b/src/main/java/umc/th/juinjang/repository/limjang/LimjangQueryDslRepositoryImpl.java index 3b4d7b9..5e06944 100644 --- a/src/main/java/umc/th/juinjang/repository/limjang/LimjangQueryDslRepositoryImpl.java +++ b/src/main/java/umc/th/juinjang/repository/limjang/LimjangQueryDslRepositoryImpl.java @@ -33,14 +33,13 @@ public LimjangQueryDslRepositoryImpl(EntityManager em) { @Override public List searchLimjangs(Member member, String keyword) { - String rKeyword = keyword.replaceAll(" ", ""); - + String rKeyword = removeKeywordBlank(keyword); return queryFactory .selectFrom(limjang) .leftJoin(limjang.report, report).fetchJoin() - .leftJoin(limjang.scrap, scrap).fetchJoin() .leftJoin(limjang.limjangPrice, limjangPrice).fetchJoin() .leftJoin(limjang.imageList, image).fetchJoin() + .where(limjang.deleted.isFalse()) .where(limjang.memberId.eq(member), keywordOf( removeBlank(limjang.nickname).containsIgnoreCase(rKeyword), @@ -50,6 +49,10 @@ public List searchLimjangs(Member member, String keyword) { .fetch(); } + private String removeKeywordBlank(String keyword) { + return keyword.replaceAll(" ", ""); + } + @Override public Limjang findByIdWithLimjangPrice(long memberId, long limjangId) { return queryFactory @@ -69,6 +72,7 @@ public List findAllByMemberAndOrderByParam(Member member, LimjangSortOp .leftJoin(limjang.report, report).fetchJoin() .leftJoin(limjang.scrap, scrap).fetchJoin() .where(limjang.memberId.eq(member)) + .where(limjang.deleted.isFalse()) .orderBy(getOrderByLimjangSortOptions(sort)) .fetch(); } From fdf4e9cb95063e5f3d408838d97d62af02f6aeee Mon Sep 17 00:00:00 2001 From: PicturePark1101 Date: Wed, 9 Oct 2024 17:10:59 +0900 Subject: [PATCH 04/14] =?UTF-8?q?refactor=20:=20=EC=9E=84=EC=9E=A5=20-=20?= =?UTF-8?q?=EC=8A=A4=ED=81=AC=EB=9E=A9=20=EB=A7=A4=ED=95=91=ED=95=98?= =?UTF-8?q?=EB=8A=94=20Map=20=EA=B5=AC=ED=98=84,=20=EA=B4=80=EA=B3=84=20?= =?UTF-8?q?=EB=B0=94=EB=80=90=20=EA=B2=83=20=EB=B0=98=EC=98=81=20#241?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../umc/th/juinjang/model/entity/Scrap.java | 4 +-- .../repository/limjang/LimjangRepository.java | 3 +- .../repository/limjang/ScrapRepository.java | 7 ++-- .../LimjangService/LimjangQueryService.java | 3 +- .../LimjangQueryServiceImpl.java | 36 +++++++++++++------ 5 files changed, 34 insertions(+), 19 deletions(-) diff --git a/src/main/java/umc/th/juinjang/model/entity/Scrap.java b/src/main/java/umc/th/juinjang/model/entity/Scrap.java index 3621a41..2a001b1 100644 --- a/src/main/java/umc/th/juinjang/model/entity/Scrap.java +++ b/src/main/java/umc/th/juinjang/model/entity/Scrap.java @@ -8,7 +8,7 @@ import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; -import jakarta.persistence.OneToOne; +import jakarta.persistence.ManyToOne; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Builder; @@ -29,7 +29,7 @@ public class Scrap extends BaseEntity { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long scrapId; - @OneToOne(fetch = FetchType.LAZY) + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "limjang_id") private Limjang limjangId; diff --git a/src/main/java/umc/th/juinjang/repository/limjang/LimjangRepository.java b/src/main/java/umc/th/juinjang/repository/limjang/LimjangRepository.java index 0da9f3d..0432ece 100644 --- a/src/main/java/umc/th/juinjang/repository/limjang/LimjangRepository.java +++ b/src/main/java/umc/th/juinjang/repository/limjang/LimjangRepository.java @@ -30,7 +30,7 @@ public interface LimjangRepository extends JpaRepository, Limjang void softDeleteByIds(@Param("ids") List ids); @Modifying - @Query(value ="DELETE FROM limjang l WHERE l.deleted = true AND l.updated_at < :dateTime", nativeQuery = true) + @Query(value = "DELETE FROM limjang l WHERE l.deleted = true AND l.updated_at < :dateTime", nativeQuery = true) void hardDelete(@Param("dateTime") LocalDateTime dateTime); // 가장 최근에 update된 5개 순서대로 @@ -57,4 +57,3 @@ public interface LimjangRepository extends JpaRepository, Limjang Optional findByLimjangIdAndMemberIdWithLimjangPriceAndDeletedIsFalse(@Param("id") Long id, @Param("member") Member member); } - diff --git a/src/main/java/umc/th/juinjang/repository/limjang/ScrapRepository.java b/src/main/java/umc/th/juinjang/repository/limjang/ScrapRepository.java index 0bcb047..d4a4e6d 100644 --- a/src/main/java/umc/th/juinjang/repository/limjang/ScrapRepository.java +++ b/src/main/java/umc/th/juinjang/repository/limjang/ScrapRepository.java @@ -1,5 +1,6 @@ package umc.th.juinjang.repository.limjang; +import java.util.List; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; @@ -11,8 +12,6 @@ import umc.th.juinjang.model.entity.Scrap; public interface ScrapRepository extends JpaRepository { - Scrap findScrapByLimjangId(Limjang limjangId); - @Query("select s from Scrap s where s.limjangId = :limjang") Optional serachByLimjang(@Param("limjang")Limjang limjang); @@ -23,5 +22,7 @@ public interface ScrapRepository extends JpaRepository { @Transactional @Modifying @Query(value = "DELETE FROM scrap s WHERE s.limjang_id = :limjangId", nativeQuery = true) - void deleteByLimjangId(@Param("limjangId") Long limjangId);; + void deleteByLimjangId(@Param("limjangId") Long limjangId); + + List findAllByLimjangIdIn(List limjangs); } \ No newline at end of file diff --git a/src/main/java/umc/th/juinjang/service/LimjangService/LimjangQueryService.java b/src/main/java/umc/th/juinjang/service/LimjangService/LimjangQueryService.java index d626823..cace7b9 100644 --- a/src/main/java/umc/th/juinjang/service/LimjangService/LimjangQueryService.java +++ b/src/main/java/umc/th/juinjang/service/LimjangService/LimjangQueryService.java @@ -4,6 +4,7 @@ import umc.th.juinjang.model.dto.limjang.response.LimjangTotalListResponseDTO; import umc.th.juinjang.model.dto.limjang.enums.LimjangSortOptions; +import umc.th.juinjang.model.dto.limjang.response.LimjangsGetByKeywordResponse; import umc.th.juinjang.model.dto.limjang.response.LimjangsGetResponse; import umc.th.juinjang.model.dto.limjang.response.LimjangsMainGetResponse; import umc.th.juinjang.model.entity.Member; @@ -14,7 +15,7 @@ public interface LimjangQueryService { LimjangsMainGetResponse getLimjangsMain(Member member); - LimjangTotalListResponseDTO.TotalListDto getLimjangSearchList(Member member, String keyword); + LimjangsGetByKeywordResponse getLimjangSearchList(Member member, String keyword); LimjangDetailResponseDTO.DetailDto getLimjangDetail(Long limjangId); } diff --git a/src/main/java/umc/th/juinjang/service/LimjangService/LimjangQueryServiceImpl.java b/src/main/java/umc/th/juinjang/service/LimjangService/LimjangQueryServiceImpl.java index 9ada514..2134c33 100644 --- a/src/main/java/umc/th/juinjang/service/LimjangService/LimjangQueryServiceImpl.java +++ b/src/main/java/umc/th/juinjang/service/LimjangService/LimjangQueryServiceImpl.java @@ -1,6 +1,10 @@ package umc.th.juinjang.service.LimjangService; +import java.util.HashSet; import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -9,9 +13,8 @@ import umc.th.juinjang.apiPayload.exception.handler.LimjangHandler; import umc.th.juinjang.apiPayload.exception.handler.MemberHandler; import umc.th.juinjang.converter.limjang.LimjangDetailConverter; -import umc.th.juinjang.converter.limjang.LimjangTotalListConverter; import umc.th.juinjang.model.dto.limjang.response.LimjangDetailResponseDTO.DetailDto; -import umc.th.juinjang.model.dto.limjang.response.LimjangTotalListResponseDTO; +import umc.th.juinjang.model.dto.limjang.response.LimjangsGetByKeywordResponse; import umc.th.juinjang.model.dto.limjang.response.LimjangsGetResponse; import umc.th.juinjang.model.dto.limjang.response.LimjangsMainGetResponse; import umc.th.juinjang.model.entity.Limjang; @@ -19,6 +22,7 @@ import umc.th.juinjang.model.dto.limjang.enums.LimjangSortOptions; import umc.th.juinjang.repository.limjang.LimjangRepository; import umc.th.juinjang.repository.limjang.MemberRepository; +import umc.th.juinjang.repository.limjang.ScrapRepository; @Slf4j @Service @@ -27,29 +31,39 @@ public class LimjangQueryServiceImpl implements LimjangQueryService{ private final LimjangRepository limjangRepository; private final MemberRepository memberRepository; + private final ScrapRepository scrapRepository; @Override @Transactional(readOnly = true) public LimjangsGetResponse getLimjangTotalList(Member member, LimjangSortOptions sort) { - return LimjangsGetResponse.of(limjangRepository.findAllByMemberAndOrderByParam(findMemberById(member), sort)); + return LimjangsGetResponse.of(limjangRepository.findAllByMemberAndOrderByParam(checkMemberExist(member), sort)); } @Override @Transactional(readOnly = true) public LimjangsMainGetResponse getLimjangsMain(final Member member) { - return LimjangsMainGetResponse.of(limjangRepository.findMainScreenContentsLimjang(findMemberById(member))); + return LimjangsMainGetResponse.of(limjangRepository.findMainScreenContentsLimjang( + checkMemberExist(member))); } @Override @Transactional(readOnly = true) - public LimjangTotalListResponseDTO.TotalListDto getLimjangSearchList(Member member, String keyword) { - - Member findMember = memberRepository.findById(member.getMemberId()) - .orElseThrow(() -> new MemberHandler(ErrorStatus.MEMBER_NOT_FOUND)); + public LimjangsGetByKeywordResponse getLimjangSearchList(Member member, String keyword) { + checkMemberExist(member); + List limjangList = limjangRepository.searchLimjangs(member, keyword).stream().toList(); + return LimjangsGetByKeywordResponse.of(limjangList, mapLimjangToScrapStatus(limjangList)); + } - List findLimjangListByKeyword = limjangRepository.searchLimjangs(findMember, keyword).stream().toList(); + private Map mapLimjangToScrapStatus(List limjangList) { + Set limjangIdsInScrap = getLimjangIdsInScrap(limjangList); + return limjangList.stream().collect(Collectors.toMap( + Limjang::getLimjangId, + it -> limjangIdsInScrap.contains(it.getLimjangId()) + )); + } - return LimjangTotalListConverter.toLimjangTotalList(findLimjangListByKeyword); + private Set getLimjangIdsInScrap(List limjangList) { + return new HashSet<>(scrapRepository.findAllByLimjangIdIn(limjangList).stream().map(it -> it.getLimjangId().getLimjangId()).toList()); } @Override @@ -62,7 +76,7 @@ public DetailDto getLimjangDetail(Long limjangId) { return LimjangDetailConverter.toDetail(findLimjang, findLimjang.getLimjangPrice()); } - private Member findMemberById(Member member) { + private Member checkMemberExist(Member member) { return memberRepository.findById(member.getMemberId()).orElseThrow(() -> new MemberHandler(ErrorStatus.MEMBER_NOT_FOUND)); } } From 2562a4eb6a22c0669b34571f6f714ce2c9908bd8 Mon Sep 17 00:00:00 2001 From: PicturePark1101 Date: Wed, 9 Oct 2024 17:11:16 +0900 Subject: [PATCH 05/14] =?UTF-8?q?refactor=20:=20responseDTO=20=EB=B0=94?= =?UTF-8?q?=EB=80=90=20=EA=B2=83=20=EB=B0=98=EC=98=81=20#241?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/umc/th/juinjang/controller/LimjangController.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/main/java/umc/th/juinjang/controller/LimjangController.java b/src/main/java/umc/th/juinjang/controller/LimjangController.java index 93b0d48..d217601 100644 --- a/src/main/java/umc/th/juinjang/controller/LimjangController.java +++ b/src/main/java/umc/th/juinjang/controller/LimjangController.java @@ -25,6 +25,7 @@ import umc.th.juinjang.model.dto.limjang.response.LimjangDetailResponseDTO; import umc.th.juinjang.model.dto.limjang.response.LimjangPostResponse; import umc.th.juinjang.model.dto.limjang.response.LimjangTotalListResponseDTO; +import umc.th.juinjang.model.dto.limjang.response.LimjangsGetByKeywordResponse; import umc.th.juinjang.model.dto.limjang.response.LimjangsGetResponse; import umc.th.juinjang.model.dto.limjang.response.LimjangsMainGetResponse; import umc.th.juinjang.model.entity.Member; @@ -74,11 +75,7 @@ public ApiResponse deleteLimjang(@RequestBody @Valid LimjangsDeleteRequest delet @CrossOrigin @Operation(summary = "임장 검색", description = "임장 게시글을 검색하는 api입니다. 집별명, 일반주소, 상세주소로 검색이 가능합니다.") @GetMapping("/{keyword}") - public ApiResponse searchLimjangs( - @AuthenticationPrincipal Member member, - @PathVariable(name = "keyword") @Valid String keyword - ) { - + public ApiResponse searchLimjangs(@AuthenticationPrincipal Member member, @PathVariable(name = "keyword") String keyword) { return ApiResponse.onSuccess(limjangQueryService.getLimjangSearchList(member, keyword)); } From 125c728007c5b059a8bb0a7bbaf8ad8d3789cc34 Mon Sep 17 00:00:00 2001 From: PicturePark1101 Date: Wed, 9 Oct 2024 17:45:36 +0900 Subject: [PATCH 06/14] =?UTF-8?q?refactor=20:=20=EC=9E=84=EC=9E=A5=20?= =?UTF-8?q?=EC=A0=84=EC=B2=B4=20=EC=A1=B0=ED=9A=8C=20=EC=BF=BC=EB=A6=AC=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20#241?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/limjang/LimjangQueryDslRepositoryImpl.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/umc/th/juinjang/repository/limjang/LimjangQueryDslRepositoryImpl.java b/src/main/java/umc/th/juinjang/repository/limjang/LimjangQueryDslRepositoryImpl.java index 5e06944..80a3622 100644 --- a/src/main/java/umc/th/juinjang/repository/limjang/LimjangQueryDslRepositoryImpl.java +++ b/src/main/java/umc/th/juinjang/repository/limjang/LimjangQueryDslRepositoryImpl.java @@ -70,7 +70,7 @@ public List findAllByMemberAndOrderByParam(Member member, LimjangSortOp .selectFrom(limjang) .join(limjang.limjangPrice, limjangPrice).fetchJoin() .leftJoin(limjang.report, report).fetchJoin() - .leftJoin(limjang.scrap, scrap).fetchJoin() + .leftJoin(limjang.imageList, image).fetchJoin() .where(limjang.memberId.eq(member)) .where(limjang.deleted.isFalse()) .orderBy(getOrderByLimjangSortOptions(sort)) @@ -85,9 +85,8 @@ private OrderSpecifier[] getOrderByLimjangSortOptions(LimjangSortOptions sort) { orders.add(new OrderSpecifier<>(DESC, report.totalRate.coalesce(0f), OrderSpecifier.NullHandling.NullsLast)); orders.add(new OrderSpecifier<>(DESC, limjang.createdAt)); } - case CREATED -> new OrderSpecifier<>(DESC, limjang.createdAt); + case CREATED -> orders.add(new OrderSpecifier<>(DESC, limjang.createdAt)); } - return orders.toArray(new OrderSpecifier[orders.size()]); } From d26127d86f60dc85917c91ca335c987d040164fb Mon Sep 17 00:00:00 2001 From: PicturePark1101 Date: Wed, 9 Oct 2024 17:46:04 +0900 Subject: [PATCH 07/14] =?UTF-8?q?refactor=20:=20=EC=9E=84=EC=9E=A5=20?= =?UTF-8?q?=EC=A0=84=EC=B2=B4=20=EC=A1=B0=ED=9A=8C=20=EC=BB=A8=EB=B2=84?= =?UTF-8?q?=ED=84=B0=20=EC=A0=9C=EA=B1=B0,=20DTO=20=EC=88=98=EC=A0=95=20#2?= =?UTF-8?q?41?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../limjang/LimjangsGetResponseConverter.java | 40 ------------------- .../limjang/response/LimjangsGetResponse.java | 34 +++++++++++----- .../LimjangQueryServiceImpl.java | 7 ++-- 3 files changed, 29 insertions(+), 52 deletions(-) delete mode 100644 src/main/java/umc/th/juinjang/converter/limjang/LimjangsGetResponseConverter.java diff --git a/src/main/java/umc/th/juinjang/converter/limjang/LimjangsGetResponseConverter.java b/src/main/java/umc/th/juinjang/converter/limjang/LimjangsGetResponseConverter.java deleted file mode 100644 index 9d16566..0000000 --- a/src/main/java/umc/th/juinjang/converter/limjang/LimjangsGetResponseConverter.java +++ /dev/null @@ -1,40 +0,0 @@ -package umc.th.juinjang.converter.limjang; - -import static umc.th.juinjang.service.LimjangService.LimjangPriceBridge.makePriceListVersion2; - -import java.util.Comparator; -import java.util.List; -import java.util.Optional; -import umc.th.juinjang.model.dto.limjang.response.LimjangsGetResponse; -import umc.th.juinjang.model.dto.limjang.response.LimjangsGetResponse.LimjangsResponse; -import umc.th.juinjang.model.entity.Image; -import umc.th.juinjang.model.entity.Limjang; -import umc.th.juinjang.model.entity.LimjangPrice; - -public class LimjangsGetResponseConverter { - - public static LimjangsGetResponse.LimjangsResponse convertToLimjangsResponse(Limjang limjang, LimjangPrice limjangPrice) { - return LimjangsResponse.builder() - .limjangId(limjang.getLimjangId()) - .images(getUrlListByScrap(limjang)) - .nickname(limjang.getNickname()) - .isScraped(limjang.getScrap() != null) - .purposeCode(limjang.getPurpose().getValue()) - .priceType(limjang.getPriceType().getValue()) - .priceList(makePriceListVersion2(limjang.getPriceType(), limjang.getPurpose(), limjangPrice)) - .totalAverage(Optional.ofNullable(limjang.getReport()) - .flatMap(report -> Optional.ofNullable(report.getTotalRate()) - .map(Object::toString)) - .orElse(null)) - .address(limjang.getAddress()) - .build(); - } - - private static List getUrlListByScrap(Limjang limjang) { - return limjang.getImageList().stream() - .sorted(Comparator.comparing(Image::getCreatedAt)) - .map(Image::getImageUrl) - .limit(limjang.getScrap() == null ? 1 : 3) - .toList(); - } -} \ No newline at end of file diff --git a/src/main/java/umc/th/juinjang/model/dto/limjang/response/LimjangsGetResponse.java b/src/main/java/umc/th/juinjang/model/dto/limjang/response/LimjangsGetResponse.java index e7934a9..e629ffd 100644 --- a/src/main/java/umc/th/juinjang/model/dto/limjang/response/LimjangsGetResponse.java +++ b/src/main/java/umc/th/juinjang/model/dto/limjang/response/LimjangsGetResponse.java @@ -1,16 +1,18 @@ package umc.th.juinjang.model.dto.limjang.response; +import static umc.th.juinjang.service.LimjangService.LimjangPriceBridge.makePriceListVersion2; + +import java.util.Comparator; import java.util.List; +import java.util.Map; import lombok.Builder; -import umc.th.juinjang.converter.limjang.LimjangsGetResponseConverter; +import umc.th.juinjang.model.entity.Image; import umc.th.juinjang.model.entity.Limjang; import umc.th.juinjang.model.entity.LimjangPrice; -public record LimjangsGetResponse( - List limjangList -) { +public record LimjangsGetResponse(List limjangList) { @Builder - public record LimjangsResponse( + record LimjangsResponse( long limjangId, List images, int purposeCode, @@ -20,12 +22,26 @@ public record LimjangsResponse( List priceList, String totalAverage, String address) { - public static LimjangsResponse of(Limjang limjang, LimjangPrice limjangPrice) { - return LimjangsGetResponseConverter.convertToLimjangsResponse(limjang, limjangPrice); + static LimjangsResponse of(Limjang limjang, LimjangPrice limjangPrice, boolean isScraped) { + return LimjangsResponse.builder() + .limjangId(limjang.getLimjangId()) + .images(getUrlListByScrap(limjang, isScraped)) + .nickname(limjang.getNickname()) + .isScraped(isScraped) + .purposeCode(limjang.getPurpose().getValue()) + .priceType(limjang.getPriceType().getValue()) + .priceList(makePriceListVersion2(limjang.getPriceType(), limjang.getPurpose(), limjangPrice)) + .totalAverage(limjang.getReport() == null ? null : limjang.getReport().getTotalRate().toString()) + .address(limjang.getAddress()) + .build(); } } - public static LimjangsGetResponse of(final List limjangList) { - return new LimjangsGetResponse(limjangList.stream().map(limjang -> LimjangsResponse.of(limjang, limjang.getLimjangPrice())).toList()); + public static LimjangsGetResponse of(final List limjangList, Map mapLimjangToScrapStatus) { + return new LimjangsGetResponse(limjangList.stream().map(limjang -> LimjangsResponse.of(limjang, limjang.getLimjangPrice(), mapLimjangToScrapStatus.get(limjang.getLimjangId()))).toList()); + } + + private static List getUrlListByScrap(Limjang limjang, boolean isScraped) { + return limjang.getImageList().stream().map(Image::getImageUrl).limit(!isScraped ? 1 : 3).toList(); } } diff --git a/src/main/java/umc/th/juinjang/service/LimjangService/LimjangQueryServiceImpl.java b/src/main/java/umc/th/juinjang/service/LimjangService/LimjangQueryServiceImpl.java index 2134c33..ab5b248 100644 --- a/src/main/java/umc/th/juinjang/service/LimjangService/LimjangQueryServiceImpl.java +++ b/src/main/java/umc/th/juinjang/service/LimjangService/LimjangQueryServiceImpl.java @@ -36,14 +36,15 @@ public class LimjangQueryServiceImpl implements LimjangQueryService{ @Override @Transactional(readOnly = true) public LimjangsGetResponse getLimjangTotalList(Member member, LimjangSortOptions sort) { - return LimjangsGetResponse.of(limjangRepository.findAllByMemberAndOrderByParam(checkMemberExist(member), sort)); + checkMemberExist(member); + List limjangList = limjangRepository.findAllByMemberAndOrderByParam(member, sort); + return LimjangsGetResponse.of(limjangList, mapLimjangToScrapStatus(limjangList)); } @Override @Transactional(readOnly = true) public LimjangsMainGetResponse getLimjangsMain(final Member member) { - return LimjangsMainGetResponse.of(limjangRepository.findMainScreenContentsLimjang( - checkMemberExist(member))); + return LimjangsMainGetResponse.of(limjangRepository.findMainScreenContentsLimjang(checkMemberExist(member))); } @Override From 9a05dfc7edc50a3a8802e622f952d14ac83b354f Mon Sep 17 00:00:00 2001 From: PicturePark1101 Date: Thu, 10 Oct 2024 20:11:18 +0900 Subject: [PATCH 08/14] =?UTF-8?q?refactor=20:=20scrap=20=EC=96=91=EB=B0=A9?= =?UTF-8?q?=ED=96=A5=20=EB=A7=A4=ED=95=91=20=EC=A0=9C=EA=B1=B0=20#241?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/umc/th/juinjang/model/entity/Limjang.java | 3 --- src/main/java/umc/th/juinjang/model/entity/Scrap.java | 9 ++------- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/src/main/java/umc/th/juinjang/model/entity/Limjang.java b/src/main/java/umc/th/juinjang/model/entity/Limjang.java index f56bab9..d967f7c 100644 --- a/src/main/java/umc/th/juinjang/model/entity/Limjang.java +++ b/src/main/java/umc/th/juinjang/model/entity/Limjang.java @@ -91,9 +91,6 @@ public class Limjang extends BaseEntity { @BatchSize(size = 100) private List imageList = new ArrayList<>(); - @OneToMany(mappedBy = "limjangId", cascade = CascadeType.ALL, orphanRemoval = true) - private List scrap = new ArrayList<>(); - @Column(name = "record_count") @ColumnDefault("0") //default 0 private int recordCount; diff --git a/src/main/java/umc/th/juinjang/model/entity/Scrap.java b/src/main/java/umc/th/juinjang/model/entity/Scrap.java index 2a001b1..5aa4680 100644 --- a/src/main/java/umc/th/juinjang/model/entity/Scrap.java +++ b/src/main/java/umc/th/juinjang/model/entity/Scrap.java @@ -1,6 +1,5 @@ package umc.th.juinjang.model.entity; -import jakarta.persistence.CascadeType; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.FetchType; @@ -8,7 +7,7 @@ import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; +import jakarta.persistence.OneToOne; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Builder; @@ -29,11 +28,7 @@ public class Scrap extends BaseEntity { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long scrapId; - @ManyToOne(fetch = FetchType.LAZY) + @OneToOne(fetch = FetchType.LAZY) @JoinColumn(name = "limjang_id") private Limjang limjangId; - - public void saveLimjang(Limjang limjang){ - this.limjangId = limjang; - } } From 51928c0ea0f2f5c0e6d63e803504bc1e10f3ebd6 Mon Sep 17 00:00:00 2001 From: PicturePark1101 Date: Thu, 10 Oct 2024 20:11:28 +0900 Subject: [PATCH 09/14] =?UTF-8?q?refactor=20:=20=EC=BF=BC=EB=A6=AC?= =?UTF-8?q?=EB=AA=85=20=EB=B3=80=EA=B2=BD=20#241?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../limjang/LimjangQueryDslRepository.java | 11 ++----- .../LimjangQueryDslRepositoryImpl.java | 30 ++----------------- .../LimjangQueryServiceImpl.java | 4 +-- .../limjang/LimjangQuerydslTest.java | 8 ++--- 4 files changed, 9 insertions(+), 44 deletions(-) diff --git a/src/main/java/umc/th/juinjang/repository/limjang/LimjangQueryDslRepository.java b/src/main/java/umc/th/juinjang/repository/limjang/LimjangQueryDslRepository.java index 6ece740..aee0fef 100644 --- a/src/main/java/umc/th/juinjang/repository/limjang/LimjangQueryDslRepository.java +++ b/src/main/java/umc/th/juinjang/repository/limjang/LimjangQueryDslRepository.java @@ -1,22 +1,15 @@ package umc.th.juinjang.repository.limjang; import java.util.List; -import org.springframework.data.domain.Pageable; import umc.th.juinjang.model.dto.limjang.enums.LimjangSortOptions; import umc.th.juinjang.model.entity.Limjang; import umc.th.juinjang.model.entity.Member; public interface LimjangQueryDslRepository { - List searchLimjangs(Member member, String keyword); - - // List findTop5ByMemberIdOrderByUpdatedAtDesc(Member member); + List searchLimjangsWhereDeletedIsFalse(Member member, String keyword); List findMainScreenContentsLimjang(Member member); - Limjang findByIdWithLimjangPrice(long memberId, long limjangId); - - List findAllLimjangs(Member member); - - List findAllByMemberAndOrderByParam(Member member, LimjangSortOptions sort); + List findAllByMemberAndDeletedIsFalseOrderByParam(Member member, LimjangSortOptions sort); } diff --git a/src/main/java/umc/th/juinjang/repository/limjang/LimjangQueryDslRepositoryImpl.java b/src/main/java/umc/th/juinjang/repository/limjang/LimjangQueryDslRepositoryImpl.java index 80a3622..acb39ea 100644 --- a/src/main/java/umc/th/juinjang/repository/limjang/LimjangQueryDslRepositoryImpl.java +++ b/src/main/java/umc/th/juinjang/repository/limjang/LimjangQueryDslRepositoryImpl.java @@ -32,12 +32,12 @@ public LimjangQueryDslRepositoryImpl(EntityManager em) { } @Override - public List searchLimjangs(Member member, String keyword) { + public List searchLimjangsWhereDeletedIsFalse(Member member, String keyword) { String rKeyword = removeKeywordBlank(keyword); return queryFactory .selectFrom(limjang) .leftJoin(limjang.report, report).fetchJoin() - .leftJoin(limjang.limjangPrice, limjangPrice).fetchJoin() + .join(limjang.limjangPrice, limjangPrice).fetchJoin() .leftJoin(limjang.imageList, image).fetchJoin() .where(limjang.deleted.isFalse()) .where(limjang.memberId.eq(member), @@ -53,19 +53,7 @@ private String removeKeywordBlank(String keyword) { return keyword.replaceAll(" ", ""); } - @Override - public Limjang findByIdWithLimjangPrice(long memberId, long limjangId) { - return queryFactory - .selectFrom(limjang) - .join(limjang.limjangPrice, limjangPrice).fetchJoin() - .leftJoin(limjang.report, report).fetchJoin() - .leftJoin(limjang.scrap, scrap).fetchJoin() - .where(limjang.memberId.memberId.eq(memberId)) - .where(limjang.limjangId.eq(limjangId)) - .fetchOne(); - } - - public List findAllByMemberAndOrderByParam(Member member, LimjangSortOptions sort) { + public List findAllByMemberAndDeletedIsFalseOrderByParam(Member member, LimjangSortOptions sort) { return queryFactory .selectFrom(limjang) .join(limjang.limjangPrice, limjangPrice).fetchJoin() @@ -113,16 +101,4 @@ public List findMainScreenContentsLimjang(Member member) { .limit(5) .fetch(); } - - @Override - public List findAllLimjangs(Member member) { - return queryFactory - .selectFrom(limjang) - .leftJoin(limjang.report, report).fetchJoin() - .leftJoin(limjang.scrap, scrap).fetchJoin() - .leftJoin(limjang.limjangPrice, limjangPrice).fetchJoin() - .leftJoin(limjang.imageList, image).fetchJoin() - .where(limjang.memberId.eq(member)) - .fetch(); - } } diff --git a/src/main/java/umc/th/juinjang/service/LimjangService/LimjangQueryServiceImpl.java b/src/main/java/umc/th/juinjang/service/LimjangService/LimjangQueryServiceImpl.java index ab5b248..54b9bd2 100644 --- a/src/main/java/umc/th/juinjang/service/LimjangService/LimjangQueryServiceImpl.java +++ b/src/main/java/umc/th/juinjang/service/LimjangService/LimjangQueryServiceImpl.java @@ -37,7 +37,7 @@ public class LimjangQueryServiceImpl implements LimjangQueryService{ @Transactional(readOnly = true) public LimjangsGetResponse getLimjangTotalList(Member member, LimjangSortOptions sort) { checkMemberExist(member); - List limjangList = limjangRepository.findAllByMemberAndOrderByParam(member, sort); + List limjangList = limjangRepository.findAllByMemberAndDeletedIsFalseOrderByParam(member, sort); return LimjangsGetResponse.of(limjangList, mapLimjangToScrapStatus(limjangList)); } @@ -51,7 +51,7 @@ public LimjangsMainGetResponse getLimjangsMain(final Member member) { @Transactional(readOnly = true) public LimjangsGetByKeywordResponse getLimjangSearchList(Member member, String keyword) { checkMemberExist(member); - List limjangList = limjangRepository.searchLimjangs(member, keyword).stream().toList(); + List limjangList = limjangRepository.searchLimjangsWhereDeletedIsFalse(member, keyword); return LimjangsGetByKeywordResponse.of(limjangList, mapLimjangToScrapStatus(limjangList)); } diff --git a/src/test/java/umc/th/juinjang/repository/limjang/LimjangQuerydslTest.java b/src/test/java/umc/th/juinjang/repository/limjang/LimjangQuerydslTest.java index 5e52eba..3d344dd 100644 --- a/src/test/java/umc/th/juinjang/repository/limjang/LimjangQuerydslTest.java +++ b/src/test/java/umc/th/juinjang/repository/limjang/LimjangQuerydslTest.java @@ -11,11 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.context.annotation.Import; -import org.springframework.test.annotation.Rollback; import org.springframework.test.context.ActiveProfiles; -import org.springframework.transaction.annotation.Transactional; -import umc.th.juinjang.apiPayload.code.status.ErrorStatus; -import umc.th.juinjang.apiPayload.exception.handler.LimjangHandler; import umc.th.juinjang.config.TestConfig; import umc.th.juinjang.model.entity.Limjang; import umc.th.juinjang.model.entity.Member; @@ -58,7 +54,7 @@ void testIncludeKeyword() { // when String keyword = "인창"; - List findLimjangs = limjangRepository.searchLimjangs(member, keyword); + List findLimjangs = limjangRepository.searchLimjangsWhereDeletedIsFalse(member, keyword); // then for (int i = 0; i < findLimjangs.size(); i++) { @@ -78,7 +74,7 @@ void testNotIncludeKeyword() { // when String keyword = "인창"; - List findLimjangs = limjangRepository.searchLimjangs(member, keyword); + List findLimjangs = limjangRepository.searchLimjangsWhereDeletedIsFalse(member, keyword); // then assertThat(findLimjangs) From 94bb10f15a980f4bc1293f9e934739e5f3bb2b6d Mon Sep 17 00:00:00 2001 From: PicturePark1101 Date: Tue, 15 Oct 2024 15:07:20 +0900 Subject: [PATCH 10/14] =?UTF-8?q?feat=20:=20=EB=A9=94=EC=9D=B8=ED=99=94?= =?UTF-8?q?=EB=A9=B4=20version2=20=EC=83=9D=EC=84=B1=20#244?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/LimjangController.java | 17 +++++---- .../LimjangService/LimjangQueryService.java | 3 ++ .../LimjangQueryServiceImpl.java | 35 +++++++++++-------- 3 files changed, 33 insertions(+), 22 deletions(-) diff --git a/src/main/java/umc/th/juinjang/controller/LimjangController.java b/src/main/java/umc/th/juinjang/controller/LimjangController.java index d217601..db170a2 100644 --- a/src/main/java/umc/th/juinjang/controller/LimjangController.java +++ b/src/main/java/umc/th/juinjang/controller/LimjangController.java @@ -28,6 +28,7 @@ import umc.th.juinjang.model.dto.limjang.response.LimjangsGetByKeywordResponse; import umc.th.juinjang.model.dto.limjang.response.LimjangsGetResponse; import umc.th.juinjang.model.dto.limjang.response.LimjangsMainGetResponse; +import umc.th.juinjang.model.dto.limjang.response.LimjangsMainGetVersion2Response; import umc.th.juinjang.model.entity.Member; import umc.th.juinjang.service.LimjangService.LimjangCommandService; import umc.th.juinjang.service.LimjangService.LimjangQueryService; @@ -58,12 +59,17 @@ public ApiResponse getLimjangTotalList(@AuthenticationPrinc @CrossOrigin @Operation(summary = "임장 메인화면에서 최근 임장 조회 API", description = "가장 최근에 수정된 순으로 최대 5개까지 볼 수 있다.") @GetMapping("/main") - public ApiResponse getRecentUpdateList( - @AuthenticationPrincipal Member member - ){ + public ApiResponse getRecentUpdateList(@AuthenticationPrincipal Member member) { return ApiResponse.onSuccess((limjangQueryService.getLimjangsMain(member))); } + @CrossOrigin + @Operation(summary = "임장 메인화면에서 최근 임장 조회 API version 2", description = "가장 최근에 수정된 순으로 최대 5개까지 볼 수 있다.") + @GetMapping("/v2/main") + public ApiResponse getRecentUpdateListVersion2(@AuthenticationPrincipal Member member) { + return ApiResponse.onSuccess((limjangQueryService.getLimjangsMainVersion2(member))); + } + @CrossOrigin @Operation(summary = "임장 선택 삭제", description = "임장 게시글을 여러 개 선택해서 삭제하는 api입니다.") @DeleteMapping @@ -82,10 +88,7 @@ public ApiResponse searchLimjangs(@AuthenticationP @CrossOrigin @Operation(summary = "임장 상세보기", description = "임장 상세보기 api입니다. 임장 id를 전달해주세요.") @GetMapping("/detail/{limjangId}") - public ApiResponse getDetailLimjang( - @PathVariable(name = "limjangId") @Valid Long limjangId, - @AuthenticationPrincipal Member member - ) { + public ApiResponse getDetailLimjang(@PathVariable(name = "limjangId") @Valid Long limjangId, @AuthenticationPrincipal Member member) { return ApiResponse.onSuccess(limjangQueryService.getLimjangDetail(limjangId)); } diff --git a/src/main/java/umc/th/juinjang/service/LimjangService/LimjangQueryService.java b/src/main/java/umc/th/juinjang/service/LimjangService/LimjangQueryService.java index cace7b9..a7a00cc 100644 --- a/src/main/java/umc/th/juinjang/service/LimjangService/LimjangQueryService.java +++ b/src/main/java/umc/th/juinjang/service/LimjangService/LimjangQueryService.java @@ -7,6 +7,7 @@ import umc.th.juinjang.model.dto.limjang.response.LimjangsGetByKeywordResponse; import umc.th.juinjang.model.dto.limjang.response.LimjangsGetResponse; import umc.th.juinjang.model.dto.limjang.response.LimjangsMainGetResponse; +import umc.th.juinjang.model.dto.limjang.response.LimjangsMainGetVersion2Response; import umc.th.juinjang.model.entity.Member; public interface LimjangQueryService { @@ -18,4 +19,6 @@ public interface LimjangQueryService { LimjangsGetByKeywordResponse getLimjangSearchList(Member member, String keyword); LimjangDetailResponseDTO.DetailDto getLimjangDetail(Long limjangId); + + LimjangsMainGetVersion2Response getLimjangsMainVersion2(Member member); } diff --git a/src/main/java/umc/th/juinjang/service/LimjangService/LimjangQueryServiceImpl.java b/src/main/java/umc/th/juinjang/service/LimjangService/LimjangQueryServiceImpl.java index 54b9bd2..ed222a2 100644 --- a/src/main/java/umc/th/juinjang/service/LimjangService/LimjangQueryServiceImpl.java +++ b/src/main/java/umc/th/juinjang/service/LimjangService/LimjangQueryServiceImpl.java @@ -17,6 +17,7 @@ import umc.th.juinjang.model.dto.limjang.response.LimjangsGetByKeywordResponse; import umc.th.juinjang.model.dto.limjang.response.LimjangsGetResponse; import umc.th.juinjang.model.dto.limjang.response.LimjangsMainGetResponse; +import umc.th.juinjang.model.dto.limjang.response.LimjangsMainGetVersion2Response; import umc.th.juinjang.model.entity.Limjang; import umc.th.juinjang.model.entity.Member; import umc.th.juinjang.model.dto.limjang.enums.LimjangSortOptions; @@ -44,7 +45,7 @@ public LimjangsGetResponse getLimjangTotalList(Member member, LimjangSortOptions @Override @Transactional(readOnly = true) public LimjangsMainGetResponse getLimjangsMain(final Member member) { - return LimjangsMainGetResponse.of(limjangRepository.findMainScreenContentsLimjang(checkMemberExist(member))); + return LimjangsMainGetResponse.of(limjangRepository.findAllByMemberAndDeletedIsFalseWithReportAndLimjangPriceOrderByUpdateAtLimit5(checkMemberExist(member))); } @Override @@ -55,29 +56,33 @@ public LimjangsGetByKeywordResponse getLimjangSearchList(Member member, String k return LimjangsGetByKeywordResponse.of(limjangList, mapLimjangToScrapStatus(limjangList)); } - private Map mapLimjangToScrapStatus(List limjangList) { - Set limjangIdsInScrap = getLimjangIdsInScrap(limjangList); - return limjangList.stream().collect(Collectors.toMap( - Limjang::getLimjangId, - it -> limjangIdsInScrap.contains(it.getLimjangId()) - )); - } - - private Set getLimjangIdsInScrap(List limjangList) { - return new HashSet<>(scrapRepository.findAllByLimjangIdIn(limjangList).stream().map(it -> it.getLimjangId().getLimjangId()).toList()); - } - @Override @Transactional(readOnly = true) public DetailDto getLimjangDetail(Long limjangId) { - Limjang findLimjang = limjangRepository.findById(limjangId) .orElseThrow(() -> new LimjangHandler(ErrorStatus.LIMJANG_NOTFOUND_ERROR)); - return LimjangDetailConverter.toDetail(findLimjang, findLimjang.getLimjangPrice()); } + @Override + @Transactional(readOnly = true) + public LimjangsMainGetVersion2Response getLimjangsMainVersion2(Member member) { + return LimjangsMainGetVersion2Response.of(limjangRepository.findAllByMemberAndDeletedIsFalseWithReportAndLimjangPriceOrderByUpdateAtLimit5(checkMemberExist(member))); + } + private Member checkMemberExist(Member member) { return memberRepository.findById(member.getMemberId()).orElseThrow(() -> new MemberHandler(ErrorStatus.MEMBER_NOT_FOUND)); } + + private Map mapLimjangToScrapStatus(List limjangList) { + Set limjangIdsInScrap = getLimjangIdsInScrap(limjangList); + return limjangList.stream().collect(Collectors.toMap( + Limjang::getLimjangId, + it -> limjangIdsInScrap.contains(it.getLimjangId()) + )); + } + + private Set getLimjangIdsInScrap(List limjangList) { + return new HashSet<>(scrapRepository.findAllByLimjangIdIn(limjangList).stream().map(it -> it.getLimjangId().getLimjangId()).toList()); + } } From 0f2a7deb4617a445b03326767859b1d1a04daf92 Mon Sep 17 00:00:00 2001 From: PicturePark1101 Date: Tue, 15 Oct 2024 15:07:35 +0900 Subject: [PATCH 11/14] =?UTF-8?q?feat=20:=20=EB=A9=94=EC=9D=B8=ED=99=94?= =?UTF-8?q?=EB=A9=B4=20version2=20response=20#244?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LimjangsMainGetVersion2Response.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/main/java/umc/th/juinjang/model/dto/limjang/response/LimjangsMainGetVersion2Response.java diff --git a/src/main/java/umc/th/juinjang/model/dto/limjang/response/LimjangsMainGetVersion2Response.java b/src/main/java/umc/th/juinjang/model/dto/limjang/response/LimjangsMainGetVersion2Response.java new file mode 100644 index 0000000..2cdfcd6 --- /dev/null +++ b/src/main/java/umc/th/juinjang/model/dto/limjang/response/LimjangsMainGetVersion2Response.java @@ -0,0 +1,36 @@ +package umc.th.juinjang.model.dto.limjang.response; + +import static umc.th.juinjang.service.LimjangService.LimjangPriceBridge.getPriceToString; + +import java.util.List; +import lombok.Builder; +import umc.th.juinjang.model.entity.Limjang; + +public record LimjangsMainGetVersion2Response(List recentUpdatedList) { + @Builder + record LimjangMainVersion2Response( + long limjangId, + int priceType, + String image, + String nickname, + String price, + String totalAverage, + String address) { + + static LimjangMainVersion2Response of(Limjang limjang) { + return LimjangMainVersion2Response.builder() + .limjangId(limjang.getLimjangId()) + .priceType(limjang.getPriceType().getValue()) + .image(limjang.getDefaultImage()) + .nickname(limjang.getNickname()) + .price(getPriceToString(limjang)) + .totalAverage(limjang.getReport() == null ? null : limjang.getReport().getTotalRate().toString()) + .address(limjang.getAddress()) + .build(); + } + } + + public static LimjangsMainGetVersion2Response of(List limjangList) { + return new LimjangsMainGetVersion2Response(limjangList.stream().map(LimjangMainVersion2Response::of).toList()); + } +} From 55dbc238123f6e0cda595f595800826f72fd125c Mon Sep 17 00:00:00 2001 From: PicturePark1101 Date: Tue, 15 Oct 2024 15:07:53 +0900 Subject: [PATCH 12/14] =?UTF-8?q?refactor=20:=20=EA=B8=B0=EC=A1=B4?= =?UTF-8?q?=ED=99=94=EB=A9=B4=20=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81=20#24?= =?UTF-8?q?4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../limjang/LimjangsMainGetResponseConverter.java | 8 +------- .../model/dto/limjang/response/LimjangsGetResponse.java | 2 +- src/main/java/umc/th/juinjang/model/entity/Limjang.java | 4 ++++ .../repository/limjang/LimjangQueryDslRepository.java | 2 +- .../repository/limjang/LimjangQueryDslRepositoryImpl.java | 3 ++- .../service/LimjangService/LimjangPriceBridge.java | 6 ++++++ 6 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/main/java/umc/th/juinjang/converter/limjang/LimjangsMainGetResponseConverter.java b/src/main/java/umc/th/juinjang/converter/limjang/LimjangsMainGetResponseConverter.java index 1c09e73..d0a5aea 100644 --- a/src/main/java/umc/th/juinjang/converter/limjang/LimjangsMainGetResponseConverter.java +++ b/src/main/java/umc/th/juinjang/converter/limjang/LimjangsMainGetResponseConverter.java @@ -1,8 +1,7 @@ package umc.th.juinjang.converter.limjang; -import static umc.th.juinjang.service.LimjangService.LimjangPriceBridge.makePriceListVersion2; +import static umc.th.juinjang.service.LimjangService.LimjangPriceBridge.getPriceToString; -import java.util.List; import java.util.Optional; import umc.th.juinjang.model.dto.limjang.response.LimjangsMainGetResponse.LimjangMainResponse; import umc.th.juinjang.model.entity.Image; @@ -20,11 +19,6 @@ public static LimjangMainResponse toLimjangMainResponse(final Limjang limjang) { limjang.getAddress()); } - private static String getPriceToString(final Limjang limjang) { - List priceList = makePriceListVersion2(limjang.getPriceType(),limjang.getPurpose(), limjang.getLimjangPrice()); - return (limjang.getPriceType().getValue() == 2) ? priceList.get(1) : priceList.get(0); - } - private static String getTotalAverageOrElse(final Limjang limjang) { return Optional.ofNullable(limjang.getReport()).map(Report::getTotalRate).map(Object::toString).orElse(null); } diff --git a/src/main/java/umc/th/juinjang/model/dto/limjang/response/LimjangsGetResponse.java b/src/main/java/umc/th/juinjang/model/dto/limjang/response/LimjangsGetResponse.java index e629ffd..7e178f7 100644 --- a/src/main/java/umc/th/juinjang/model/dto/limjang/response/LimjangsGetResponse.java +++ b/src/main/java/umc/th/juinjang/model/dto/limjang/response/LimjangsGetResponse.java @@ -37,7 +37,7 @@ static LimjangsResponse of(Limjang limjang, LimjangPrice limjangPrice, boolean i } } - public static LimjangsGetResponse of(final List limjangList, Map mapLimjangToScrapStatus) { + public static LimjangsGetResponse of(List limjangList, Map mapLimjangToScrapStatus) { return new LimjangsGetResponse(limjangList.stream().map(limjang -> LimjangsResponse.of(limjang, limjang.getLimjangPrice(), mapLimjangToScrapStatus.get(limjang.getLimjangId()))).toList()); } diff --git a/src/main/java/umc/th/juinjang/model/entity/Limjang.java b/src/main/java/umc/th/juinjang/model/entity/Limjang.java index d967f7c..f0f6c8b 100644 --- a/src/main/java/umc/th/juinjang/model/entity/Limjang.java +++ b/src/main/java/umc/th/juinjang/model/entity/Limjang.java @@ -116,4 +116,8 @@ public void updateMemo(String memo){ public void saveImages(Image image){ this.imageList.add(image); } + + public String getDefaultImage() { + return this.imageList.isEmpty() ? null :this.imageList.get(0).getImageUrl(); + } } \ No newline at end of file diff --git a/src/main/java/umc/th/juinjang/repository/limjang/LimjangQueryDslRepository.java b/src/main/java/umc/th/juinjang/repository/limjang/LimjangQueryDslRepository.java index aee0fef..c5250b6 100644 --- a/src/main/java/umc/th/juinjang/repository/limjang/LimjangQueryDslRepository.java +++ b/src/main/java/umc/th/juinjang/repository/limjang/LimjangQueryDslRepository.java @@ -9,7 +9,7 @@ public interface LimjangQueryDslRepository { List searchLimjangsWhereDeletedIsFalse(Member member, String keyword); - List findMainScreenContentsLimjang(Member member); + List findAllByMemberAndDeletedIsFalseWithReportAndLimjangPriceOrderByUpdateAtLimit5(Member member); List findAllByMemberAndDeletedIsFalseOrderByParam(Member member, LimjangSortOptions sort); } diff --git a/src/main/java/umc/th/juinjang/repository/limjang/LimjangQueryDslRepositoryImpl.java b/src/main/java/umc/th/juinjang/repository/limjang/LimjangQueryDslRepositoryImpl.java index acb39ea..fcb3615 100644 --- a/src/main/java/umc/th/juinjang/repository/limjang/LimjangQueryDslRepositoryImpl.java +++ b/src/main/java/umc/th/juinjang/repository/limjang/LimjangQueryDslRepositoryImpl.java @@ -91,12 +91,13 @@ private StringExpression removeBlank(StringExpression origin) { } @Override - public List findMainScreenContentsLimjang(Member member) { + public List findAllByMemberAndDeletedIsFalseWithReportAndLimjangPriceOrderByUpdateAtLimit5(Member member) { return queryFactory .selectFrom(limjang) .leftJoin(limjang.report, report).fetchJoin() .join(limjang.limjangPrice, limjangPrice).fetchJoin() .where(limjang.memberId.eq(member)) + .where(limjang.deleted.isFalse()) .orderBy(limjang.updatedAt.desc()) .limit(5) .fetch(); diff --git a/src/main/java/umc/th/juinjang/service/LimjangService/LimjangPriceBridge.java b/src/main/java/umc/th/juinjang/service/LimjangService/LimjangPriceBridge.java index ece01fa..cf925c6 100644 --- a/src/main/java/umc/th/juinjang/service/LimjangService/LimjangPriceBridge.java +++ b/src/main/java/umc/th/juinjang/service/LimjangService/LimjangPriceBridge.java @@ -5,6 +5,7 @@ import java.util.List; import umc.th.juinjang.apiPayload.code.status.ErrorStatus; import umc.th.juinjang.apiPayload.exception.handler.LimjangHandler; +import umc.th.juinjang.model.entity.Limjang; import umc.th.juinjang.model.entity.LimjangPrice; import umc.th.juinjang.model.entity.enums.LimjangPriceType; import umc.th.juinjang.model.entity.enums.LimjangPurpose; @@ -92,4 +93,9 @@ public static void checkExpectedSize(int priceType, int priceListSize){ throw new LimjangHandler(ErrorStatus.LIMJANG_POST_PRICE_ERROR); } } + + public static String getPriceToString(Limjang limjang) { + List priceList = makePriceListVersion2(limjang.getPriceType(),limjang.getPurpose(), limjang.getLimjangPrice()); + return (limjang.getPriceType().getValue() == 2) ? priceList.get(1) : priceList.get(0); + } } \ No newline at end of file From eff9424d4a357e9aea369015969c44866aa31416 Mon Sep 17 00:00:00 2001 From: PicturePark1101 Date: Tue, 15 Oct 2024 15:08:57 +0900 Subject: [PATCH 13/14] =?UTF-8?q?refactor=20:=20=EB=B6=88=ED=95=84?= =?UTF-8?q?=EC=9A=94=ED=95=9C=20=EB=A9=94=EC=86=8C=EB=93=9C=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0=20#244?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../th/juinjang/repository/limjang/LimjangRepository.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/main/java/umc/th/juinjang/repository/limjang/LimjangRepository.java b/src/main/java/umc/th/juinjang/repository/limjang/LimjangRepository.java index 0432ece..4badc6d 100644 --- a/src/main/java/umc/th/juinjang/repository/limjang/LimjangRepository.java +++ b/src/main/java/umc/th/juinjang/repository/limjang/LimjangRepository.java @@ -21,8 +21,6 @@ public interface LimjangRepository extends JpaRepository, Limjang @Query(value = "SELECT * FROM limjang l WHERE l.member_id = :memberId", nativeQuery = true) List findLimjangByMemberIdIgnoreDeleted(@Param("memberId") Long memberId); - Optional findByLimjangIdAndMemberIdAndDeletedIsFalse(Long id, Member member); - List findAllByLimjangIdInAndMemberIdAndDeletedIsFalse(List id, Member member); @Modifying @@ -33,9 +31,6 @@ public interface LimjangRepository extends JpaRepository, Limjang @Query(value = "DELETE FROM limjang l WHERE l.deleted = true AND l.updated_at < :dateTime", nativeQuery = true) void hardDelete(@Param("dateTime") LocalDateTime dateTime); - // 가장 최근에 update된 5개 순서대로 - List findTop5ByMemberIdOrderByUpdatedAtDesc(Member member); - Optional findLimjangByLimjangIdAndMemberId(Long limjangId, Member member); @Modifying From e1796301d981a31d43138eb9535b5e14e1e3b1a4 Mon Sep 17 00:00:00 2001 From: PicturePark1101 Date: Tue, 15 Oct 2024 15:53:28 +0900 Subject: [PATCH 14/14] =?UTF-8?q?refactor=20:=20=EC=9E=84=EC=9E=A5=20?= =?UTF-8?q?=EC=83=81=EC=84=B8=EB=B3=B4=EA=B8=B0=20=EB=A6=AC=ED=8C=A9?= =?UTF-8?q?=ED=86=A0=EB=A7=81=20#244?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/LimjangController.java | 7 ++-- .../limjang/LimjangDetailConverter.java | 8 ++-- .../enums/LimjangCheckListVersionEnum.java | 6 --- .../response/LimjangDetailGetResponse.java | 41 +++++++++++++++++++ .../response/LimjangDetailResponseDTO.java | 4 +- .../umc/th/juinjang/model/entity/Limjang.java | 2 + .../entity/enums/LimjangCheckListVersion.java | 17 ++++++++ .../repository/limjang/LimjangRepository.java | 5 ++- .../LimjangService/LimjangQueryService.java | 5 +-- .../LimjangQueryServiceImpl.java | 13 +++--- .../LimjangSchedulerService.java | 2 +- 11 files changed, 82 insertions(+), 28 deletions(-) delete mode 100644 src/main/java/umc/th/juinjang/model/dto/limjang/enums/LimjangCheckListVersionEnum.java create mode 100644 src/main/java/umc/th/juinjang/model/dto/limjang/response/LimjangDetailGetResponse.java create mode 100644 src/main/java/umc/th/juinjang/model/entity/enums/LimjangCheckListVersion.java diff --git a/src/main/java/umc/th/juinjang/controller/LimjangController.java b/src/main/java/umc/th/juinjang/controller/LimjangController.java index db170a2..03e5c91 100644 --- a/src/main/java/umc/th/juinjang/controller/LimjangController.java +++ b/src/main/java/umc/th/juinjang/controller/LimjangController.java @@ -22,9 +22,8 @@ import umc.th.juinjang.model.dto.limjang.request.LimjangPatchRequest; import umc.th.juinjang.model.dto.limjang.request.LimjangPostRequest; import umc.th.juinjang.model.dto.limjang.request.LimjangsDeleteRequest; -import umc.th.juinjang.model.dto.limjang.response.LimjangDetailResponseDTO; +import umc.th.juinjang.model.dto.limjang.response.LimjangDetailGetResponse; import umc.th.juinjang.model.dto.limjang.response.LimjangPostResponse; -import umc.th.juinjang.model.dto.limjang.response.LimjangTotalListResponseDTO; import umc.th.juinjang.model.dto.limjang.response.LimjangsGetByKeywordResponse; import umc.th.juinjang.model.dto.limjang.response.LimjangsGetResponse; import umc.th.juinjang.model.dto.limjang.response.LimjangsMainGetResponse; @@ -88,8 +87,8 @@ public ApiResponse searchLimjangs(@AuthenticationP @CrossOrigin @Operation(summary = "임장 상세보기", description = "임장 상세보기 api입니다. 임장 id를 전달해주세요.") @GetMapping("/detail/{limjangId}") - public ApiResponse getDetailLimjang(@PathVariable(name = "limjangId") @Valid Long limjangId, @AuthenticationPrincipal Member member) { - return ApiResponse.onSuccess(limjangQueryService.getLimjangDetail(limjangId)); + public ApiResponse getLimjang(@PathVariable(name = "limjangId") @Valid Long id, @AuthenticationPrincipal Member member) { + return ApiResponse.onSuccess(limjangQueryService.getDetail(id, member)); } @CrossOrigin diff --git a/src/main/java/umc/th/juinjang/converter/limjang/LimjangDetailConverter.java b/src/main/java/umc/th/juinjang/converter/limjang/LimjangDetailConverter.java index 4c3b8a1..60f8ccc 100644 --- a/src/main/java/umc/th/juinjang/converter/limjang/LimjangDetailConverter.java +++ b/src/main/java/umc/th/juinjang/converter/limjang/LimjangDetailConverter.java @@ -5,7 +5,7 @@ import java.util.Comparator; import java.util.List; import umc.th.juinjang.model.dto.limjang.response.LimjangDetailResponseDTO; -import umc.th.juinjang.model.dto.limjang.enums.LimjangCheckListVersionEnum; +import umc.th.juinjang.model.entity.enums.LimjangCheckListVersion; import umc.th.juinjang.model.entity.Image; import umc.th.juinjang.model.entity.Limjang; import umc.th.juinjang.model.entity.LimjangPrice; @@ -28,14 +28,14 @@ public static LimjangDetailResponseDTO.DetailDto toDetail( LimjangPropertyType propertyType = limjang.getPropertyType(); LimjangPriceType priceType = limjang.getPriceType(); - LimjangCheckListVersionEnum checkListVersion; + LimjangCheckListVersion checkListVersion; if (purposeType == LimjangPurpose.RESIDENTIAL_PURPOSE && (propertyType == LimjangPropertyType.VILLA|| propertyType == LimjangPropertyType.OFFICE_TEL) ){ - checkListVersion = LimjangCheckListVersionEnum.NON_LIMJANG; + checkListVersion = LimjangCheckListVersion.NON_LIMJANG; } else { - checkListVersion = LimjangCheckListVersionEnum.LIMJANG; + checkListVersion = LimjangCheckListVersion.LIMJANG; } List priceList = makePriceListVersion2(priceType, purposeType,limjangPrice); diff --git a/src/main/java/umc/th/juinjang/model/dto/limjang/enums/LimjangCheckListVersionEnum.java b/src/main/java/umc/th/juinjang/model/dto/limjang/enums/LimjangCheckListVersionEnum.java deleted file mode 100644 index 698ad7a..0000000 --- a/src/main/java/umc/th/juinjang/model/dto/limjang/enums/LimjangCheckListVersionEnum.java +++ /dev/null @@ -1,6 +0,0 @@ -package umc.th.juinjang.model.dto.limjang.enums; - -public enum LimjangCheckListVersionEnum { - LIMJANG, - NON_LIMJANG -} diff --git a/src/main/java/umc/th/juinjang/model/dto/limjang/response/LimjangDetailGetResponse.java b/src/main/java/umc/th/juinjang/model/dto/limjang/response/LimjangDetailGetResponse.java new file mode 100644 index 0000000..ef11ce2 --- /dev/null +++ b/src/main/java/umc/th/juinjang/model/dto/limjang/response/LimjangDetailGetResponse.java @@ -0,0 +1,41 @@ +package umc.th.juinjang.model.dto.limjang.response; + +import static umc.th.juinjang.service.LimjangService.LimjangPriceBridge.makePriceListVersion2; + +import java.time.LocalDateTime; +import java.util.List; +import lombok.Builder; +import umc.th.juinjang.model.entity.Image; +import umc.th.juinjang.model.entity.enums.LimjangCheckListVersion; +import umc.th.juinjang.model.entity.Limjang; + +@Builder +public record LimjangDetailGetResponse( + long limjangId, + LimjangCheckListVersion checkListVersion, + List images, + int purposeCode, + String nickname, + int priceType, + List priceList, + String address, + String addressDetail, + LocalDateTime createdAt, + LocalDateTime updatedAt +) { + public static LimjangDetailGetResponse of(Limjang limjang){ + return LimjangDetailGetResponse.builder() + .limjangId(limjang.getLimjangId()) + .checkListVersion(LimjangCheckListVersion.getByLimjangType(limjang)) + .images(limjang.getImageList().stream().map(Image::getImageUrl).toList()) + .purposeCode(limjang.getPurpose().getValue()) + .nickname(limjang.getNickname()) + .priceType(limjang.getPriceType().getValue()) + .priceList(makePriceListVersion2(limjang.getPriceType(), limjang.getPurpose(), limjang.getLimjangPrice())) + .address(limjang.getAddress()) + .addressDetail(limjang.getAddressDetail()) + .createdAt(limjang.getCreatedAt()) + .updatedAt(limjang.getUpdatedAt()) + .build(); + } +} diff --git a/src/main/java/umc/th/juinjang/model/dto/limjang/response/LimjangDetailResponseDTO.java b/src/main/java/umc/th/juinjang/model/dto/limjang/response/LimjangDetailResponseDTO.java index 7863cf2..3f8fac0 100644 --- a/src/main/java/umc/th/juinjang/model/dto/limjang/response/LimjangDetailResponseDTO.java +++ b/src/main/java/umc/th/juinjang/model/dto/limjang/response/LimjangDetailResponseDTO.java @@ -6,7 +6,7 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; -import umc.th.juinjang.model.dto.limjang.enums.LimjangCheckListVersionEnum; +import umc.th.juinjang.model.entity.enums.LimjangCheckListVersion; public class LimjangDetailResponseDTO { @@ -16,7 +16,7 @@ public class LimjangDetailResponseDTO { @AllArgsConstructor public static class DetailDto { private Long limjangId; - private LimjangCheckListVersionEnum checkListVersion; + private LimjangCheckListVersion checkListVersion; private List images; private Integer purposeCode; private String nickname; diff --git a/src/main/java/umc/th/juinjang/model/entity/Limjang.java b/src/main/java/umc/th/juinjang/model/entity/Limjang.java index f0f6c8b..78f9d66 100644 --- a/src/main/java/umc/th/juinjang/model/entity/Limjang.java +++ b/src/main/java/umc/th/juinjang/model/entity/Limjang.java @@ -120,4 +120,6 @@ public void saveImages(Image image){ public String getDefaultImage() { return this.imageList.isEmpty() ? null :this.imageList.get(0).getImageUrl(); } + + } \ No newline at end of file diff --git a/src/main/java/umc/th/juinjang/model/entity/enums/LimjangCheckListVersion.java b/src/main/java/umc/th/juinjang/model/entity/enums/LimjangCheckListVersion.java new file mode 100644 index 0000000..99af9f3 --- /dev/null +++ b/src/main/java/umc/th/juinjang/model/entity/enums/LimjangCheckListVersion.java @@ -0,0 +1,17 @@ +package umc.th.juinjang.model.entity.enums; + +import umc.th.juinjang.model.entity.Limjang; + +public enum LimjangCheckListVersion { + LIMJANG, + NON_LIMJANG; + + public static LimjangCheckListVersion getByLimjangType(Limjang limjang) { + LimjangPropertyType propertyType = limjang.getPropertyType(); + + if (limjang.getPurpose() == LimjangPurpose.RESIDENTIAL_PURPOSE && (propertyType == LimjangPropertyType.VILLA || propertyType == LimjangPropertyType.OFFICE_TEL)) { + return LimjangCheckListVersion.NON_LIMJANG; + } + return LimjangCheckListVersion.LIMJANG; + } +} \ No newline at end of file diff --git a/src/main/java/umc/th/juinjang/repository/limjang/LimjangRepository.java b/src/main/java/umc/th/juinjang/repository/limjang/LimjangRepository.java index 4badc6d..8140738 100644 --- a/src/main/java/umc/th/juinjang/repository/limjang/LimjangRepository.java +++ b/src/main/java/umc/th/juinjang/repository/limjang/LimjangRepository.java @@ -17,7 +17,6 @@ @Repository public interface LimjangRepository extends JpaRepository, LimjangQueryDslRepository { - @Query(value = "SELECT * FROM limjang l WHERE l.member_id = :memberId", nativeQuery = true) List findLimjangByMemberIdIgnoreDeleted(@Param("memberId") Long memberId); @@ -50,5 +49,7 @@ public interface LimjangRepository extends JpaRepository, Limjang @Query("SELECT l FROM Limjang l join fetch l.limjangPrice WHERE l.limjangId = :id AND l.memberId = :member AND l.deleted = false") Optional findByLimjangIdAndMemberIdWithLimjangPriceAndDeletedIsFalse(@Param("id") Long id, @Param("member") Member member); -} + @Query("SELECT l FROM Limjang l join fetch l.limjangPrice left join fetch l.report WHERE l.limjangId = :id AND l.memberId = :member AND l.deleted = false") + Optional findByLimjangIdAndDeletedIsFalse(@Param("id") Long id, @Param("member") Member member); +} \ No newline at end of file diff --git a/src/main/java/umc/th/juinjang/service/LimjangService/LimjangQueryService.java b/src/main/java/umc/th/juinjang/service/LimjangService/LimjangQueryService.java index a7a00cc..3692834 100644 --- a/src/main/java/umc/th/juinjang/service/LimjangService/LimjangQueryService.java +++ b/src/main/java/umc/th/juinjang/service/LimjangService/LimjangQueryService.java @@ -1,8 +1,7 @@ package umc.th.juinjang.service.LimjangService; -import umc.th.juinjang.model.dto.limjang.response.LimjangDetailResponseDTO; +import umc.th.juinjang.model.dto.limjang.response.LimjangDetailGetResponse; -import umc.th.juinjang.model.dto.limjang.response.LimjangTotalListResponseDTO; import umc.th.juinjang.model.dto.limjang.enums.LimjangSortOptions; import umc.th.juinjang.model.dto.limjang.response.LimjangsGetByKeywordResponse; import umc.th.juinjang.model.dto.limjang.response.LimjangsGetResponse; @@ -18,7 +17,7 @@ public interface LimjangQueryService { LimjangsGetByKeywordResponse getLimjangSearchList(Member member, String keyword); - LimjangDetailResponseDTO.DetailDto getLimjangDetail(Long limjangId); + LimjangDetailGetResponse getDetail(long id, Member member); LimjangsMainGetVersion2Response getLimjangsMainVersion2(Member member); } diff --git a/src/main/java/umc/th/juinjang/service/LimjangService/LimjangQueryServiceImpl.java b/src/main/java/umc/th/juinjang/service/LimjangService/LimjangQueryServiceImpl.java index ed222a2..3582174 100644 --- a/src/main/java/umc/th/juinjang/service/LimjangService/LimjangQueryServiceImpl.java +++ b/src/main/java/umc/th/juinjang/service/LimjangService/LimjangQueryServiceImpl.java @@ -12,8 +12,7 @@ import umc.th.juinjang.apiPayload.code.status.ErrorStatus; import umc.th.juinjang.apiPayload.exception.handler.LimjangHandler; import umc.th.juinjang.apiPayload.exception.handler.MemberHandler; -import umc.th.juinjang.converter.limjang.LimjangDetailConverter; -import umc.th.juinjang.model.dto.limjang.response.LimjangDetailResponseDTO.DetailDto; +import umc.th.juinjang.model.dto.limjang.response.LimjangDetailGetResponse; import umc.th.juinjang.model.dto.limjang.response.LimjangsGetByKeywordResponse; import umc.th.juinjang.model.dto.limjang.response.LimjangsGetResponse; import umc.th.juinjang.model.dto.limjang.response.LimjangsMainGetResponse; @@ -58,10 +57,12 @@ public LimjangsGetByKeywordResponse getLimjangSearchList(Member member, String k @Override @Transactional(readOnly = true) - public DetailDto getLimjangDetail(Long limjangId) { - Limjang findLimjang = limjangRepository.findById(limjangId) - .orElseThrow(() -> new LimjangHandler(ErrorStatus.LIMJANG_NOTFOUND_ERROR)); - return LimjangDetailConverter.toDetail(findLimjang, findLimjang.getLimjangPrice()); + public LimjangDetailGetResponse getDetail(long id, Member member) { + return LimjangDetailGetResponse.of(getByIdAndMember(id, member)); + } + + private Limjang getByIdAndMember(Long id, Member member) { + return limjangRepository.findByLimjangIdAndDeletedIsFalse(id, member).orElseThrow(() -> new LimjangHandler(ErrorStatus.LIMJANG_NOTFOUND_ERROR)); } @Override diff --git a/src/main/java/umc/th/juinjang/service/LimjangService/LimjangSchedulerService.java b/src/main/java/umc/th/juinjang/service/LimjangService/LimjangSchedulerService.java index b43806e..d635d28 100644 --- a/src/main/java/umc/th/juinjang/service/LimjangService/LimjangSchedulerService.java +++ b/src/main/java/umc/th/juinjang/service/LimjangService/LimjangSchedulerService.java @@ -17,7 +17,7 @@ public class LimjangSchedulerService { private final LimjangRepository limjangRepository; @Transactional -// @Scheduled(fixedRate = 60000) // 1분 간격으로 실행 - test용 + // @Scheduled(fixedRate = 60000) // 1분 간격으로 실행 - test용 // @Scheduled(fixedRate = 7 * 24 * 60 * 60 * 1000) // 일주일 간격으로 실행 <- 나중에 출시하면 이걸로 @Scheduled(fixedRate = 31557600000L) // 일년 간격으로 실행(임시) public void cleanUpData() {