From 6c789631a5fa83c0a2158c5538aa9dd6a8473f43 Mon Sep 17 00:00:00 2001 From: gurdl7011 Date: Sun, 12 Nov 2023 00:33:42 +0900 Subject: [PATCH 01/15] =?UTF-8?q?=F0=9F=94=A5=20::=20timeLine?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/onui/domain/diary/entity/Diary.kt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/com/example/onui/domain/diary/entity/Diary.kt b/src/main/kotlin/com/example/onui/domain/diary/entity/Diary.kt index a7c40d9..f2ee99a 100644 --- a/src/main/kotlin/com/example/onui/domain/diary/entity/Diary.kt +++ b/src/main/kotlin/com/example/onui/domain/diary/entity/Diary.kt @@ -14,10 +14,11 @@ Diary( user: User, content: String?, mood: Mood, - tag: MutableList, + tagList: MutableList, createdAt: LocalDateTime, image: String? = null, - id: UUID? = null + id: UUID? = null, + isPosted: Boolean = false ) : BaseTimeEntity(createdAt) { @Id @@ -42,13 +43,17 @@ Diary( @ElementCollection(fetch = FetchType.EAGER) @CollectionTable(name = "diary_tag", joinColumns = [JoinColumn(name = "diary_id", referencedColumnName = "id")]) - var tag: MutableList = tag + var tagList: MutableList = tagList protected set @Column(name = "image", nullable = true) var image: String? = image protected set + @Column(name = "is_posted", nullable = false, columnDefinition = "BIT") + var isPosted: Boolean = isPosted + protected set + fun toResponse() = DiaryResponse( this.id!!, this.mood, @@ -59,7 +64,7 @@ Diary( this.id!!, this.content, this.mood, - this.tag, + this.tagList, this.createdAt.toLocalDate(), this.image ) From b75159767d927559d97cbb0e9fc02fa17c29c686 Mon Sep 17 00:00:00 2001 From: gurdl7011 Date: Sun, 12 Nov 2023 00:34:29 +0900 Subject: [PATCH 02/15] =?UTF-8?q?=F0=9F=94=A5=20::=20timeLine?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/onui/domain/diary/repository/DiaryRepository.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/com/example/onui/domain/diary/repository/DiaryRepository.kt b/src/main/kotlin/com/example/onui/domain/diary/repository/DiaryRepository.kt index 453adf6..45bedc4 100644 --- a/src/main/kotlin/com/example/onui/domain/diary/repository/DiaryRepository.kt +++ b/src/main/kotlin/com/example/onui/domain/diary/repository/DiaryRepository.kt @@ -9,7 +9,9 @@ import java.util.* @Repository interface DiaryRepository : JpaRepository { - fun findAllByUserAndYearAndMonth(user: User, year: Int, month: Int): MutableList? + fun findAllByUserAndYearAndMonthOrderByCreatedAtAsc(user: User, year: Int, month: Int): MutableList? fun findByUserAndYearAndMonthAndDay(user: User, year: Int, month: Int, day: Int): Diary? + + fun existsByIdAndIsPosted(id: UUID, isPosted: Boolean): Boolean } \ No newline at end of file From 33a8ae4ae28c072b9d4f9aa6281479000469d148 Mon Sep 17 00:00:00 2001 From: gurdl7011 Date: Sun, 12 Nov 2023 00:37:33 +0900 Subject: [PATCH 03/15] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20::=20code=20refactor?= =?UTF-8?q?ing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../diary/repository/QDiaryRepositoryImpl.kt | 30 ++++++------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/src/main/kotlin/com/example/onui/domain/diary/repository/QDiaryRepositoryImpl.kt b/src/main/kotlin/com/example/onui/domain/diary/repository/QDiaryRepositoryImpl.kt index c8e1782..95f5903 100644 --- a/src/main/kotlin/com/example/onui/domain/diary/repository/QDiaryRepositoryImpl.kt +++ b/src/main/kotlin/com/example/onui/domain/diary/repository/QDiaryRepositoryImpl.kt @@ -1,8 +1,6 @@ package com.example.onui.domain.diary.repository -import com.example.onui.domain.diary.entity.Diary import com.example.onui.domain.diary.entity.QDiary.diary -import com.example.onui.domain.diary.presentation.response.DiaryResponse import com.example.onui.domain.user.entity.User import com.querydsl.jpa.impl.JPAQueryFactory import org.springframework.stereotype.Repository @@ -17,24 +15,14 @@ class QDiaryRepositoryImpl( private val queryFactory: JPAQueryFactory ) : QDiaryRepository { - override fun findThreeDayAgoByUser(user: User): Diary? { + override fun findThreeDayAgoByUser(user: User) = queryFactory.selectFrom(diary) + .orderBy(diary.createdAt.desc()) + .where(diary.user.eq(user).and(diary.createdAt.after(LocalDateTime.now().minusDays(3)))) + .limit(1) + .fetchOne() - val ago = LocalDateTime.now().minusDays(3) - - return queryFactory.selectFrom(diary) - .orderBy(diary.createdAt.desc()) - .where(diary.user.eq(user).and(diary.createdAt.after(ago))) - .limit(1) - .fetchOne() - } - - override fun findSevenDayAgoByUser(user: User): MutableList { - - val ago = LocalDateTime.now().minusDays(7) - - return queryFactory.selectFrom(diary) - .orderBy(diary.createdAt.desc()) - .where(diary.user.eq(user).and(diary.createdAt.after(ago))) - .fetch().map { it.toResponse() }.toMutableList() - } + override fun findSevenDayAgoByUser(user: User) = queryFactory.selectFrom(diary) + .orderBy(diary.createdAt.desc()) + .where(diary.user.eq(user).and(diary.createdAt.after(LocalDateTime.now().minusDays(7)))) + .fetch().map { it.toResponse() }.toMutableList() } \ No newline at end of file From a7960f0c61264071a5f697fd968b3867a649da68 Mon Sep 17 00:00:00 2001 From: gurdl7011 Date: Sun, 12 Nov 2023 00:37:48 +0900 Subject: [PATCH 04/15] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20::?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/diary/service/DiaryServiceImpl.kt | 60 +++++-------------- 1 file changed, 14 insertions(+), 46 deletions(-) diff --git a/src/main/kotlin/com/example/onui/domain/diary/service/DiaryServiceImpl.kt b/src/main/kotlin/com/example/onui/domain/diary/service/DiaryServiceImpl.kt index 74f857c..8ff83b6 100644 --- a/src/main/kotlin/com/example/onui/domain/diary/service/DiaryServiceImpl.kt +++ b/src/main/kotlin/com/example/onui/domain/diary/service/DiaryServiceImpl.kt @@ -8,8 +8,6 @@ import com.example.onui.domain.diary.presentation.response.DiaryDetailResponse import com.example.onui.domain.diary.presentation.response.DiaryListResponse import com.example.onui.domain.diary.repository.DiaryRepository import com.example.onui.domain.diary.repository.QDiaryRepository -import com.example.onui.domain.timeline.entity.Timeline -import com.example.onui.domain.timeline.repository.TimelineRepository import com.example.onui.global.common.facade.UserFacade import com.example.onui.global.config.error.exception.PermissionDeniedException import org.springframework.data.repository.findByIdOrNull @@ -23,7 +21,6 @@ import java.util.* class DiaryServiceImpl( private val diaryRepository: DiaryRepository, private val userFacade: UserFacade, - private val timelineRepository: TimelineRepository, private val qDiaryRepository: QDiaryRepository ) : DiaryService { @@ -33,36 +30,28 @@ class DiaryServiceImpl( val user = userFacade.getCurrentUser() val now = LocalDateTime.now() - val diary = Diary( - user, - req.content, - req.mood!!, - req.tagList!!, - now, - req.image, - diaryRepository.findByUserAndYearAndMonthAndDay( - user, - now.year, - now.monthValue, - now.dayOfMonth - )?.id - ) + val diary = + diaryRepository.findByUserAndYearAndMonthAndDay(user, now.year, now.monthValue, now.dayOfMonth)?.let { + Diary( + user, req.content, req.mood!!, req.tagList!!, it.createdAt, req.image, it.id, it.isPosted + ) + } ?: Diary( + user, req.content, req.mood!!, req.tagList!!, now, req.image + ) diaryRepository.save(diary) - user.diaryList.add(diary) return diary.toDetailResponse() } override fun getDiaryByMonth(year: Int, month: Int) = DiaryListResponse( - diaryRepository.findAllByUserAndYearAndMonth(userFacade.getCurrentUser(), year, month)?.map { + diaryRepository.findAllByUserAndYearAndMonthOrderByCreatedAtAsc(userFacade.getCurrentUser(), year, month)?.map { it.toResponse() }?.toMutableList() ) override fun getDetailById(id: UUID): DiaryDetailResponse { - val diary = diaryRepository.findByIdOrNull(id) - ?: throw DiaryNotFoundException + val diary = diaryRepository.findByIdOrNull(id) ?: throw DiaryNotFoundException if (diary.user != userFacade.getCurrentUser()) throw PermissionDeniedException @@ -73,36 +62,15 @@ class DiaryServiceImpl( override fun update(req: UpdateDiaryRequest): DiaryDetailResponse { val user = userFacade.getCurrentUser() - var diary = diaryRepository.findByIdOrNull(req.id) - ?: throw DiaryNotFoundException + val diary = diaryRepository.findByIdOrNull(req.id) ?: throw DiaryNotFoundException if (diary.user != user) throw PermissionDeniedException - diary = diaryRepository.save( + return diaryRepository.save( Diary( - diary.user, - req.content, - req.mood!!, - req.tagList!!, - diary.createdAt, - req.image, - diary.id + diary.user, req.content, req.mood!!, req.tagList!!, diary.createdAt, req.image, diary.id ) - ) - - timelineRepository.findByIdOrNull(diary.id) - ?.run { - timelineRepository.save( - Timeline( - diary, - diary.createdAt, - id, - true, - ) - ) - } - - return diary.toDetailResponse() + ).toDetailResponse() } override fun getSevenDaysAgo(): DiaryListResponse { From 1d14479686fb7e52440166e017a1c7e2452e26b2 Mon Sep 17 00:00:00 2001 From: gurdl7011 Date: Sun, 12 Nov 2023 00:38:02 +0900 Subject: [PATCH 05/15] =?UTF-8?q?=F0=9F=94=A5=20::=20timeLine?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../onui/domain/timeline/entity/Timeline.kt | 47 ------------------- 1 file changed, 47 deletions(-) delete mode 100644 src/main/kotlin/com/example/onui/domain/timeline/entity/Timeline.kt diff --git a/src/main/kotlin/com/example/onui/domain/timeline/entity/Timeline.kt b/src/main/kotlin/com/example/onui/domain/timeline/entity/Timeline.kt deleted file mode 100644 index 54358d9..0000000 --- a/src/main/kotlin/com/example/onui/domain/timeline/entity/Timeline.kt +++ /dev/null @@ -1,47 +0,0 @@ -package com.example.onui.domain.timeline.entity - -import com.example.onui.domain.diary.entity.Diary -import com.example.onui.domain.timeline.presentation.dto.response.TimelineResponse -import java.time.DayOfWeek -import java.time.LocalDateTime -import java.util.* -import javax.persistence.* - -@Entity(name = "timeline") -class Timeline( - diary: Diary, - createdAt: LocalDateTime, - id: UUID? = null, - isUpdated: Boolean = false -) { - - @Id - @Column(name = "id") - var id: UUID? = id - protected set - - @OneToOne(fetch = FetchType.LAZY) - @MapsId - @JoinColumn(name = "id", columnDefinition = "BINARY(16)") - var diary: Diary = diary - protected set - - @Enumerated(EnumType.STRING) - @Column(name = "day_of_week", nullable = false) - var dayOfWeek: DayOfWeek = createdAt.dayOfWeek - - @Column(name = "is_updated", nullable = false, columnDefinition = "BIT") - var isUpdated: Boolean = isUpdated - protected set - - fun toResponse() = TimelineResponse( - this.id!!, - this.diary.content, - this.diary.mood, - this.diary.tag, - this.diary.image, - this.dayOfWeek, - this.diary.createdAt, - this.isUpdated - ) -} \ No newline at end of file From c959753b56c07c0419f64a4606af11747fd50172 Mon Sep 17 00:00:00 2001 From: gurdl7011 Date: Sun, 12 Nov 2023 00:38:30 +0900 Subject: [PATCH 06/15] =?UTF-8?q?=F0=9F=94=A5=20::=20timeLine?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../timeline/repository/TimelineRepository.kt | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 src/main/kotlin/com/example/onui/domain/timeline/repository/TimelineRepository.kt diff --git a/src/main/kotlin/com/example/onui/domain/timeline/repository/TimelineRepository.kt b/src/main/kotlin/com/example/onui/domain/timeline/repository/TimelineRepository.kt deleted file mode 100644 index e04e936..0000000 --- a/src/main/kotlin/com/example/onui/domain/timeline/repository/TimelineRepository.kt +++ /dev/null @@ -1,13 +0,0 @@ -package com.example.onui.domain.timeline.repository - -import com.example.onui.domain.timeline.entity.Timeline -import org.springframework.data.domain.Page -import org.springframework.data.domain.Pageable -import org.springframework.data.jpa.repository.JpaRepository -import java.time.DayOfWeek -import java.util.* - -interface TimelineRepository: JpaRepository { - - fun findAllByDayOfWeek(dayOfWeek: DayOfWeek, pageable: Pageable): Page -} \ No newline at end of file From bf3a2c405d67a332e629cc6969e9b2650d88cd60 Mon Sep 17 00:00:00 2001 From: gurdl7011 Date: Sun, 12 Nov 2023 00:39:07 +0900 Subject: [PATCH 07/15] =?UTF-8?q?=F0=9F=94=A5=20::=20=EC=A3=BC=EC=84=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../onui/global/config/redis/RedisConfig.kt | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/main/kotlin/com/example/onui/global/config/redis/RedisConfig.kt b/src/main/kotlin/com/example/onui/global/config/redis/RedisConfig.kt index b34a0ad..2b1980e 100644 --- a/src/main/kotlin/com/example/onui/global/config/redis/RedisConfig.kt +++ b/src/main/kotlin/com/example/onui/global/config/redis/RedisConfig.kt @@ -16,18 +16,4 @@ class RedisConfig( @Bean fun redisConnectionFactory(): RedisConnectionFactory = LettuceConnectionFactory(property.host, property.port) - -// @Bean -// fun redisTemplate(): RedisTemplate { -// -// val template: RedisTemplate = RedisTemplate() -// -// template.let { -// it.keySerializer = StringRedisSerializer() -// it.valueSerializer = StringRedisSerializer() -// it.setConnectionFactory(redisConnectionFactory()) -// } -// -// return template -// } } \ No newline at end of file From 4adada95864c07bea557518681861c13a83a305f Mon Sep 17 00:00:00 2001 From: gurdl7011 Date: Sun, 12 Nov 2023 00:39:27 +0900 Subject: [PATCH 08/15] =?UTF-8?q?=E2=AD=90=EF=B8=8F=20::=20InvalidDateForm?= =?UTF-8?q?atException?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/timeline/exception/InvalidDateFormatException.kt | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 src/main/kotlin/com/example/onui/domain/timeline/exception/InvalidDateFormatException.kt diff --git a/src/main/kotlin/com/example/onui/domain/timeline/exception/InvalidDateFormatException.kt b/src/main/kotlin/com/example/onui/domain/timeline/exception/InvalidDateFormatException.kt new file mode 100644 index 0000000..c89d652 --- /dev/null +++ b/src/main/kotlin/com/example/onui/domain/timeline/exception/InvalidDateFormatException.kt @@ -0,0 +1,6 @@ +package com.example.onui.domain.timeline.exception + +import com.example.onui.global.config.error.data.ErrorCode +import com.example.onui.global.config.error.exception.BusinessException + +object InvalidDateFormatException : BusinessException(ErrorCode.INVALID_DATE_FORMAT) From 18d9c7b3e5f6cd2dcdb0b4829ab196cb446f9ce5 Mon Sep 17 00:00:00 2001 From: gurdl7011 Date: Sun, 12 Nov 2023 00:39:52 +0900 Subject: [PATCH 09/15] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20::=20format?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/onui/global/common/entity/BaseTimeEntity.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/com/example/onui/global/common/entity/BaseTimeEntity.kt b/src/main/kotlin/com/example/onui/global/common/entity/BaseTimeEntity.kt index fa608ed..5f1d1e5 100644 --- a/src/main/kotlin/com/example/onui/global/common/entity/BaseTimeEntity.kt +++ b/src/main/kotlin/com/example/onui/global/common/entity/BaseTimeEntity.kt @@ -18,12 +18,14 @@ abstract class BaseTimeEntity( var year: Int = createdAt.year protected set - @Min(1) @Max(12) + @Min(1) + @Max(12) @Column(name = "month", nullable = false) var month: Int = createdAt.monthValue protected set - @Min(1) @Max(31) + @Min(1) + @Max(31) @Column(name = "day", nullable = false) var day: Int = createdAt.dayOfMonth protected set From 8daac68f91429f3b1c2e724620c478e8189a0cc2 Mon Sep 17 00:00:00 2001 From: gurdl7011 Date: Sun, 12 Nov 2023 00:40:26 +0900 Subject: [PATCH 10/15] =?UTF-8?q?=E2=AD=90=EF=B8=8F=20::=20InvalidDateForm?= =?UTF-8?q?atException?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/onui/global/config/error/data/ErrorCode.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/kotlin/com/example/onui/global/config/error/data/ErrorCode.kt b/src/main/kotlin/com/example/onui/global/config/error/data/ErrorCode.kt index 7d0081f..82a7c50 100644 --- a/src/main/kotlin/com/example/onui/global/config/error/data/ErrorCode.kt +++ b/src/main/kotlin/com/example/onui/global/config/error/data/ErrorCode.kt @@ -12,6 +12,7 @@ enum class ErrorCode( ALREADY_WROTE_DIARY(HttpStatus.BAD_REQUEST, "이미 감정을 기록하셨습니다."), ALREADY_POSTED_TIMELINE(HttpStatus.BAD_REQUEST, "이미 타임라인을 업로드하셨습니다."), INVALID_FILE_EXTENSION(HttpStatus.BAD_REQUEST, "지원하지 않는 파일 확장자입니다."), + INVALID_DATE_FORMAT(HttpStatus.BAD_REQUEST, "date가 올비르지 않습니다."), // 401 INVALID_TOKEN(HttpStatus.UNAUTHORIZED, "유효하지 않은 토큰입니다."), From 6ce38998e32b6afaa37770a43a86eb87ebf898a3 Mon Sep 17 00:00:00 2001 From: gurdl7011 Date: Sun, 12 Nov 2023 00:40:42 +0900 Subject: [PATCH 11/15] =?UTF-8?q?=F0=9F=94=A5=20::=20timeLine?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../timeline/service/TimelineServiceImpl.kt | 43 +++++++++++-------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/src/main/kotlin/com/example/onui/domain/timeline/service/TimelineServiceImpl.kt b/src/main/kotlin/com/example/onui/domain/timeline/service/TimelineServiceImpl.kt index 5bb1589..7211091 100644 --- a/src/main/kotlin/com/example/onui/domain/timeline/service/TimelineServiceImpl.kt +++ b/src/main/kotlin/com/example/onui/domain/timeline/service/TimelineServiceImpl.kt @@ -1,11 +1,11 @@ package com.example.onui.domain.timeline.service +import com.example.onui.domain.diary.entity.Diary import com.example.onui.domain.diary.exception.DiaryNotFoundException +import com.example.onui.domain.diary.presentation.response.DiaryDetailResponse import com.example.onui.domain.diary.repository.DiaryRepository -import com.example.onui.domain.timeline.entity.Timeline import com.example.onui.domain.timeline.exception.AlreadyPostedTimeLineException -import com.example.onui.domain.timeline.presentation.dto.response.TimelineResponse -import com.example.onui.domain.timeline.repository.TimelineRepository +import com.example.onui.domain.timeline.repository.QTimelineRepository import com.example.onui.global.common.facade.UserFacade import com.example.onui.global.config.error.exception.PermissionDeniedException import org.springframework.data.domain.PageRequest @@ -13,19 +13,19 @@ import org.springframework.data.domain.Sort import org.springframework.data.repository.findByIdOrNull import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional -import java.time.DayOfWeek +import java.time.LocalDate import java.util.* @Service @Transactional(readOnly = true) class TimelineServiceImpl( private val userFacade: UserFacade, - private val timelineRepository: TimelineRepository, + private val qTimelineRepository: QTimelineRepository, private val diaryRepository: DiaryRepository -): TimeLineService { +) : TimeLineService { @Transactional - override fun post(id: UUID): TimelineResponse { + override fun post(id: UUID): DiaryDetailResponse { val user = userFacade.getCurrentUser() val diary = diaryRepository.findByIdOrNull(id) @@ -33,17 +33,24 @@ class TimelineServiceImpl( if (diary.user != user) throw PermissionDeniedException - if (timelineRepository.existsById(id)) throw AlreadyPostedTimeLineException - - return timelineRepository.save(Timeline( - diary, - diary.createdAt - )).toResponse() + if (diaryRepository.existsByIdAndIsPosted(id, true)) throw AlreadyPostedTimeLineException + + return diaryRepository.save( + Diary( + diary.user, + diary.content, + diary.mood, + diary.tagList, + diary.createdAt, + diary.image, + diary.id, + true + ) + ).toDetailResponse() } - override fun searchByDayOfWeek(idx: Int, size: Int, dayOfWeek: DayOfWeek) = timelineRepository - .findAllByDayOfWeek( - dayOfWeek, - PageRequest.of(idx, size, Sort.by("diary.createdAt").descending()) - ).map { it.toResponse() } + override fun searchByDate(idx: Int, size: Int, date: LocalDate) = qTimelineRepository + .findPageByDate( + PageRequest.of(idx, size, Sort.by("diary.createdAt").descending()), date + ) } \ No newline at end of file From 86c61bbd8042d5dddd28a283dcfd7aa6fe8cbf60 Mon Sep 17 00:00:00 2001 From: gurdl7011 Date: Sun, 12 Nov 2023 00:40:52 +0900 Subject: [PATCH 12/15] =?UTF-8?q?=F0=9F=94=A5=20::=20timeLine?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../onui/domain/timeline/service/TimeLineService.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/com/example/onui/domain/timeline/service/TimeLineService.kt b/src/main/kotlin/com/example/onui/domain/timeline/service/TimeLineService.kt index 6085e2f..8556d52 100644 --- a/src/main/kotlin/com/example/onui/domain/timeline/service/TimeLineService.kt +++ b/src/main/kotlin/com/example/onui/domain/timeline/service/TimeLineService.kt @@ -1,13 +1,13 @@ package com.example.onui.domain.timeline.service -import com.example.onui.domain.timeline.presentation.dto.response.TimelineResponse +import com.example.onui.domain.diary.presentation.response.DiaryDetailResponse import org.springframework.data.domain.Page -import java.time.DayOfWeek +import java.time.LocalDate import java.util.* interface TimeLineService { - fun post(id: UUID): TimelineResponse + fun post(id: UUID): DiaryDetailResponse - fun searchByDayOfWeek(idx: Int, size: Int, dayOfWeek: DayOfWeek): Page + fun searchByDate(idx: Int, size: Int, date: LocalDate): Page } From 31411980ad83bf9c0ea79868438b37d782c8b5bc Mon Sep 17 00:00:00 2001 From: gurdl7011 Date: Sun, 12 Nov 2023 00:41:30 +0900 Subject: [PATCH 13/15] =?UTF-8?q?=F0=9F=93=9D=20::=20day=5Fof=5Fweek=20->?= =?UTF-8?q?=20date?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/TimelineController.kt | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/main/kotlin/com/example/onui/domain/timeline/presentation/TimelineController.kt b/src/main/kotlin/com/example/onui/domain/timeline/presentation/TimelineController.kt index f4ea84d..33ab5e8 100644 --- a/src/main/kotlin/com/example/onui/domain/timeline/presentation/TimelineController.kt +++ b/src/main/kotlin/com/example/onui/domain/timeline/presentation/TimelineController.kt @@ -1,11 +1,13 @@ package com.example.onui.domain.timeline.presentation +import com.example.onui.domain.timeline.exception.InvalidDateFormatException import com.example.onui.domain.timeline.service.TimeLineService import org.springframework.http.HttpStatus import org.springframework.validation.annotation.Validated import org.springframework.web.bind.annotation.* -import java.time.DayOfWeek -import java.util.UUID +import java.time.LocalDate +import java.time.format.DateTimeParseException +import java.util.* @Validated @RestController @@ -17,17 +19,17 @@ class TimelineController( @PostMapping @ResponseStatus(HttpStatus.CREATED) fun createTimeline( - @RequestParam("id", required = true) - id: UUID + @RequestParam("id", required = true) id: UUID ) = timelineService.post(id) @GetMapping - fun getByDayOfWeek( - @RequestParam("idx", required = true) - idx: Int = 0, - @RequestParam("size", required = true) - size: Int = 5, - @RequestParam("day_of_week", required = true) - dayOfWeek: DayOfWeek - ) = timelineService.searchByDayOfWeek(idx, size, dayOfWeek) + fun getByDate( + @RequestParam("idx", required = true) idx: Int = 0, + @RequestParam("size", required = true) size: Int = 5, + @RequestParam("date", required = true) date: String + ) = try { + timelineService.searchByDate(idx, size, LocalDate.parse(date)) + } catch (e: DateTimeParseException) { + throw InvalidDateFormatException + } } \ No newline at end of file From 10d0a0525aeb419b49390f5d499b8a908978b9fb Mon Sep 17 00:00:00 2001 From: gurdl7011 Date: Sun, 12 Nov 2023 00:41:48 +0900 Subject: [PATCH 14/15] =?UTF-8?q?=E2=AD=90=EF=B8=8F=20::=20findPageByDate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/timeline/repository/QTimelineRepository.kt | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/main/kotlin/com/example/onui/domain/timeline/repository/QTimelineRepository.kt diff --git a/src/main/kotlin/com/example/onui/domain/timeline/repository/QTimelineRepository.kt b/src/main/kotlin/com/example/onui/domain/timeline/repository/QTimelineRepository.kt new file mode 100644 index 0000000..452a3b3 --- /dev/null +++ b/src/main/kotlin/com/example/onui/domain/timeline/repository/QTimelineRepository.kt @@ -0,0 +1,11 @@ +package com.example.onui.domain.timeline.repository + +import com.example.onui.domain.diary.presentation.response.DiaryDetailResponse +import org.springframework.data.domain.Page +import org.springframework.data.domain.Pageable +import java.time.LocalDate + +interface QTimelineRepository { + + fun findPageByDate(pageable: Pageable, date: LocalDate): Page +} From e994f44e041b83ba124028a33b25ef8d8bde1d44 Mon Sep 17 00:00:00 2001 From: gurdl7011 Date: Sun, 12 Nov 2023 00:41:53 +0900 Subject: [PATCH 15/15] =?UTF-8?q?=E2=AD=90=EF=B8=8F=20::=20findPageByDate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/QTimelineRepositoryImpl.kt | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/main/kotlin/com/example/onui/domain/timeline/repository/QTimelineRepositoryImpl.kt diff --git a/src/main/kotlin/com/example/onui/domain/timeline/repository/QTimelineRepositoryImpl.kt b/src/main/kotlin/com/example/onui/domain/timeline/repository/QTimelineRepositoryImpl.kt new file mode 100644 index 0000000..e9214bc --- /dev/null +++ b/src/main/kotlin/com/example/onui/domain/timeline/repository/QTimelineRepositoryImpl.kt @@ -0,0 +1,32 @@ +package com.example.onui.domain.timeline.repository + +import com.example.onui.domain.diary.entity.QDiary.diary +import com.example.onui.domain.diary.presentation.response.DiaryDetailResponse +import com.querydsl.jpa.impl.JPAQueryFactory +import org.springframework.data.domain.Page +import org.springframework.data.domain.PageImpl +import org.springframework.data.domain.Pageable +import org.springframework.stereotype.Service +import java.time.LocalDate + +@Service +class QTimelineRepositoryImpl( + private val query: JPAQueryFactory +) : QTimelineRepository { + + override fun findPageByDate(pageable: Pageable, date: LocalDate): Page { + val query = query.selectFrom(diary).where( + diary.isPosted.eq(true).and( + diary.day.eq(date.dayOfMonth).and( + diary.month.eq(date.monthValue).and( + diary.year.eq(date.year) + ) + ) + ) + ).orderBy(diary.createdAt.desc()).offset(pageable.offset).limit(pageable.pageSize.toLong()) + + val iterable = query.fetch().map { it.toDetailResponse() } + + return PageImpl(iterable, pageable, iterable.size.toLong()) + } +} \ No newline at end of file