From 3770d520a1f39d756889bb965b662a045262dab6 Mon Sep 17 00:00:00 2001 From: seeunjang Date: Tue, 21 May 2024 14:52:08 +0900 Subject: [PATCH 1/2] =?UTF-8?q?refactor=20:=20=EB=A7=88=EA=B0=90=EC=88=9C?= =?UTF-8?q?=20=EC=A0=95=EB=A0=AC=20=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= =?UTF-8?q?(#128)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/JobDescriptionReader.kt | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/jobDescription/service/JobDescriptionReader.kt b/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/jobDescription/service/JobDescriptionReader.kt index 4dca0a18..b9367de9 100644 --- a/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/jobDescription/service/JobDescriptionReader.kt +++ b/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/jobDescription/service/JobDescriptionReader.kt @@ -5,6 +5,8 @@ import com.bamyanggang.domainmodule.domain.jobDescription.aggregate.JobDescripti import com.bamyanggang.domainmodule.domain.jobDescription.enums.SortType import com.bamyanggang.domainmodule.domain.jobDescription.enums.WriteStatus import com.bamyanggang.domainmodule.domain.jobDescription.repository.JobDescriptionRepository +import java.time.LocalDateTime +import java.time.temporal.ChronoUnit import java.util.* class JobDescriptionReader( @@ -13,11 +15,24 @@ class JobDescriptionReader( fun readJobDescriptionByUserIdAndSortType(userId: UUID, page: Int, size: Int, sortType: SortType?, writeStatus: WriteStatus?): PageDomain { return when(sortType) { SortType.CREATED -> jobDescriptionRepository.findAllByUserIdAndSortByCreatedAt(userId, page, size, writeStatus) - SortType.ENDED -> jobDescriptionRepository.findAllByUserIdAndSortByEndedAt(userId, page, size, writeStatus) + SortType.ENDED -> sortWithEndedAt(jobDescriptionRepository.findAllByUserId(userId, page, size, writeStatus)) else -> jobDescriptionRepository.findAllByUserId(userId, page, size, writeStatus) } } + private fun sortWithEndedAt (pageDomain: PageDomain): PageDomain { + val now = LocalDateTime.now() + val futureList = pageDomain.content.filter { it.endedAt.isAfter(now) } + val pastList = pageDomain.content.filter { it.endedAt.isBefore(now) } + + val sortedFutureList = futureList.sortedWith(compareBy { kotlin.math.abs(ChronoUnit.DAYS.between(it.endedAt, now)) }) + val sortedPastList = pastList.sortedWith(compareByDescending { it.endedAt }) + + val sortedList = sortedFutureList + sortedPastList + + return PageDomain(sortedList, pageDomain.pageNumber, pageDomain.pageSize, pageDomain.totalPage, pageDomain.hasNext) + } + fun readJobDescriptionById(jobDescriptionId: UUID): JobDescription { return jobDescriptionRepository.findById(jobDescriptionId) } From 524f01f76106069b6a4f4c7f86674309c66d700a Mon Sep 17 00:00:00 2001 From: seeunjang Date: Tue, 21 May 2024 14:52:21 +0900 Subject: [PATCH 2/2] =?UTF-8?q?refactor=20:=20=EB=AF=B8=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=A0=9C=EA=B1=B0(#128)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/JobDescriptionRepository.kt | 2 -- .../jobDescription/JobDescriptionRepositoryImpl.java | 11 +---------- .../jpa/repository/JobDescriptionJpaRepository.java | 3 --- 3 files changed, 1 insertion(+), 15 deletions(-) diff --git a/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/jobDescription/repository/JobDescriptionRepository.kt b/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/jobDescription/repository/JobDescriptionRepository.kt index 90207975..35eb05c6 100644 --- a/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/jobDescription/repository/JobDescriptionRepository.kt +++ b/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/jobDescription/repository/JobDescriptionRepository.kt @@ -13,8 +13,6 @@ interface JobDescriptionRepository { fun findAllByUserIdAndSortByCreatedAt(userId: UUID, page: Int, size: Int, writeStatus: WriteStatus?): PageDomain - fun findAllByUserIdAndSortByEndedAt(userId: UUID, page: Int, size: Int, writeStatus: WriteStatus?): PageDomain - fun findAllByUserId(userId: UUID, page: Int, size: Int, writeStatus: WriteStatus?): PageDomain fun deleteById(jobDescriptionId: UUID) diff --git a/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/jobDescription/JobDescriptionRepositoryImpl.java b/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/jobDescription/JobDescriptionRepositoryImpl.java index dae3c613..de6776df 100644 --- a/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/jobDescription/JobDescriptionRepositoryImpl.java +++ b/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/jobDescription/JobDescriptionRepositoryImpl.java @@ -29,6 +29,7 @@ public void save(JobDescription jobDescription) { jobDescriptionJpaRepository.save(jobDescriptionJpaEntity); } + @Override public JobDescription findById(UUID jobDescriptionId) { return jobDescriptionJpaRepository.findById(jobDescriptionId) .map(jobDescriptionMapper::toDomainEntity) @@ -53,16 +54,6 @@ public PageDomain findAllByUserId(UUID userId, int page, int siz ,jobDescriptionSlice.getTotalPages(), jobDescriptionSlice.hasNext()); } - @Override - public PageDomain findAllByUserIdAndSortByEndedAt(UUID userId, int page, int size, WriteStatus writeStatus) { - Pageable pageable = PageRequest.of(page, size); - LocalDateTime now = LocalDateTime.now(); - Page jobDescriptionJpaEntities = jobDescriptionJpaRepository.findAllByUserIdAndWriteStatusAndTime(userId, writeStatus, now, pageable); - Page jobDescriptionSlice = jobDescriptionJpaEntities.map(jobDescriptionMapper::toDomainEntity); - return new PageDomain<>(jobDescriptionSlice.getContent(), jobDescriptionSlice.getNumber(), jobDescriptionSlice.getSize() - ,jobDescriptionSlice.getTotalPages(), jobDescriptionSlice.hasNext()); - } - @Override public void deleteById(UUID jobDescriptionId) { jobDescriptionJpaRepository.deleteById(jobDescriptionId); diff --git a/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/jobDescription/jpa/repository/JobDescriptionJpaRepository.java b/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/jobDescription/jpa/repository/JobDescriptionJpaRepository.java index 338e237c..55cc7fc7 100644 --- a/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/jobDescription/jpa/repository/JobDescriptionJpaRepository.java +++ b/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/jobDescription/jpa/repository/JobDescriptionJpaRepository.java @@ -16,9 +16,6 @@ public interface JobDescriptionJpaRepository extends JpaRepository findAllByUserIdAndWriteStatus(@Param("userId") UUID userId, @Param("writeStatus") WriteStatus writeStatus, @Param("date") Pageable pageable); - @Query("SELECT j FROM JobDescriptionJpaEntity j WHERE j.userId = :userId AND (:writeStatus is null or j.writeStatus = :writeStatus) AND j.endedAt > :date ORDER BY j.endedAt ASC") - Page findAllByUserIdAndWriteStatusAndTime(@Param("userId") UUID userId, @Param("writeStatus") WriteStatus writeStatus, - @Param("date") LocalDateTime now, Pageable pageable); @Modifying @Query("UPDATE JobDescriptionJpaEntity j SET j.writeStatus = 'CLOSED' WHERE j.endedAt < CURRENT_TIMESTAMP") void changeWriteStatus();