From 77b8efa5aa8edfd6ecf8531c54a9920833df0041 Mon Sep 17 00:00:00 2001 From: gurdl7011 Date: Mon, 13 Nov 2023 08:45:44 +0900 Subject: [PATCH 01/20] =?UTF-8?q?=F0=9F=93=9D=20::=20response=20status?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/onui/domain/auth/presentation/AuthController.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/kotlin/com/example/onui/domain/auth/presentation/AuthController.kt b/src/main/kotlin/com/example/onui/domain/auth/presentation/AuthController.kt index f6e2613..2a44a41 100644 --- a/src/main/kotlin/com/example/onui/domain/auth/presentation/AuthController.kt +++ b/src/main/kotlin/com/example/onui/domain/auth/presentation/AuthController.kt @@ -4,6 +4,7 @@ import com.example.onui.domain.auth.presentation.dto.response.TokenResponse import com.example.onui.domain.auth.service.AppleAuthService import com.example.onui.domain.auth.service.AuthService import com.example.onui.domain.auth.service.GoogleAuthService +import org.springframework.http.HttpStatus import org.springframework.validation.annotation.Validated import org.springframework.web.bind.annotation.* @@ -17,6 +18,7 @@ class AuthController( ) { @PostMapping("/google") + @ResponseStatus(HttpStatus.CREATED) fun oauthSignIn( @RequestParam(name = "token", required = true) token: String @@ -29,6 +31,7 @@ class AuthController( ): TokenResponse = authService.reissue(token) @PostMapping("/apple") + @ResponseStatus(HttpStatus.CREATED) fun oauthSignInWithApple( @RequestParam(name = "token", required = true) token: String From 770b915230824b639158273aefae28a82c019efa Mon Sep 17 00:00:00 2001 From: gurdl7011 Date: Mon, 13 Nov 2023 08:46:17 +0900 Subject: [PATCH 02/20] =?UTF-8?q?=F0=9F=90=9B=20::=20google=20token=20?= =?UTF-8?q?=EA=B6=8C=ED=95=9C=20=EC=98=A4=EB=A5=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../onui/domain/auth/service/GoogleAuthServiceImpl.kt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/com/example/onui/domain/auth/service/GoogleAuthServiceImpl.kt b/src/main/kotlin/com/example/onui/domain/auth/service/GoogleAuthServiceImpl.kt index d5e2992..f932f96 100644 --- a/src/main/kotlin/com/example/onui/domain/auth/service/GoogleAuthServiceImpl.kt +++ b/src/main/kotlin/com/example/onui/domain/auth/service/GoogleAuthServiceImpl.kt @@ -4,6 +4,7 @@ import com.example.onui.domain.auth.presentation.dto.response.TokenResponse import com.example.onui.domain.auth.repository.RefreshTokenRepository import com.example.onui.domain.user.entity.User import com.example.onui.domain.user.repository.UserRepository +import com.example.onui.global.config.error.exception.InvalidTokenException import com.example.onui.global.config.jwt.TokenProvider import com.example.onui.infra.feign.google.GoogleAuthClient import com.example.onui.infra.feign.google.GoogleInfoClient @@ -31,12 +32,17 @@ class GoogleAuthServiceImpl( logger.info { token } - val response = googleInfo.googleInfo(ALT, token) + val response = try { + googleInfo.googleInfo(ALT, token) + } catch (e: Exception) { + throw InvalidTokenException + } refreshTokenRepository.findBySub(response.sub)?.let { refreshTokenRepository.delete(it) } + googleAuth.revokeToken(token) val tokenResponse = tokenProvider.receiveToken(response.sub) userRepository.findBySub(response.sub) @@ -47,8 +53,6 @@ class GoogleAuthServiceImpl( ) ) - googleAuth.revokeToken(token) - return tokenResponse } } \ No newline at end of file From d561a07e191275fe1aa054b09adacb95e2bf4174 Mon Sep 17 00:00:00 2001 From: gurdl7011 Date: Mon, 13 Nov 2023 08:47:14 +0900 Subject: [PATCH 03/20] =?UTF-8?q?=E2=AD=90=EF=B8=8F=20::=20Comment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/onui/domain/diary/entity/Diary.kt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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 f2ee99a..dd425da 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 @@ -2,6 +2,8 @@ import com.example.onui.domain.diary.presentation.response.DiaryDetailResponse import com.example.onui.domain.diary.presentation.response.DiaryResponse +import com.example.onui.domain.timeline.entity.Comment +import com.example.onui.domain.timeline.presentation.dto.response.TimelineResponse import com.example.onui.domain.user.entity.User import com.example.onui.global.common.entity.BaseTimeEntity import java.time.LocalDateTime @@ -54,6 +56,9 @@ Diary( var isPosted: Boolean = isPosted protected set + @OneToMany(mappedBy = "timeline", cascade = [CascadeType.REMOVE]) + var commentList: MutableList = arrayListOf() + fun toResponse() = DiaryResponse( this.id!!, this.mood, @@ -68,4 +73,14 @@ Diary( this.createdAt.toLocalDate(), this.image ) + + fun toTimelineResponse() = TimelineResponse( + this.id!!, + this.content, + this.mood, + this.tagList, + this.image, + this.user.name, + this.commentList.size + ) } \ No newline at end of file From 551e840b40e66565238964fe27e14961cea0950c Mon Sep 17 00:00:00 2001 From: gurdl7011 Date: Mon, 13 Nov 2023 08:47:36 +0900 Subject: [PATCH 04/20] =?UTF-8?q?=E2=AD=90=EF=B8=8F=20::=20Comment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../onui/domain/timeline/entity/Comment.kt | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/main/kotlin/com/example/onui/domain/timeline/entity/Comment.kt diff --git a/src/main/kotlin/com/example/onui/domain/timeline/entity/Comment.kt b/src/main/kotlin/com/example/onui/domain/timeline/entity/Comment.kt new file mode 100644 index 0000000..b7c0de7 --- /dev/null +++ b/src/main/kotlin/com/example/onui/domain/timeline/entity/Comment.kt @@ -0,0 +1,47 @@ +package com.example.onui.domain.timeline.entity + +import com.example.onui.domain.diary.entity.Diary +import com.example.onui.domain.timeline.presentation.dto.response.CommentResponse +import com.example.onui.domain.user.entity.User +import java.time.LocalDateTime +import java.util.* +import javax.persistence.* + +@Entity(name = "comment") +class Comment( + content: String, + user: User, + timeline: Diary, + id: UUID? = null +) { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(columnDefinition = "BINARY(16)") + var id: UUID? = id + protected set + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "user_id", nullable = false) + var user: User = user + protected set + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "timeline_id", nullable = false) + var timeline: Diary = timeline + protected set + + @Column(name = "content", columnDefinition = "VARCHAR(50)", nullable = false) + var content: String = content + protected set + + @Column(name = "created_at", nullable = false) + var createdAt: LocalDateTime = LocalDateTime.now() + protected set + + fun toResponse() = CommentResponse( + this.id!!, + this.timeline.id!!, + this.user.id!!, + this.content + ) +} \ No newline at end of file From 27ffd16f421d0f795d056ce852f8ab75f6ee1932 Mon Sep 17 00:00:00 2001 From: gurdl7011 Date: Mon, 13 Nov 2023 08:48:10 +0900 Subject: [PATCH 05/20] =?UTF-8?q?=E2=AD=90=EF=B8=8F=20::=20findByIdAndIsPo?= =?UTF-8?q?sted?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/onui/domain/diary/repository/DiaryRepository.kt | 2 ++ 1 file changed, 2 insertions(+) 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 45bedc4..66d2dcb 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 @@ -14,4 +14,6 @@ interface DiaryRepository : JpaRepository { fun findByUserAndYearAndMonthAndDay(user: User, year: Int, month: Int, day: Int): Diary? fun existsByIdAndIsPosted(id: UUID, isPosted: Boolean): Boolean + + fun findByIdAndIsPosted(id: UUID, isPosted: Boolean): Diary? } \ No newline at end of file From d7e60e9bd9a48006245c94e6cbdb7f2fa8f9b451 Mon Sep 17 00:00:00 2001 From: gurdl7011 Date: Mon, 13 Nov 2023 08:48:41 +0900 Subject: [PATCH 06/20] =?UTF-8?q?=E2=AD=90=EF=B8=8F=20::=20TimelineNotFoun?= =?UTF-8?q?dException?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/timeline/exception/TimelineNotFoundException.kt | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 src/main/kotlin/com/example/onui/domain/timeline/exception/TimelineNotFoundException.kt diff --git a/src/main/kotlin/com/example/onui/domain/timeline/exception/TimelineNotFoundException.kt b/src/main/kotlin/com/example/onui/domain/timeline/exception/TimelineNotFoundException.kt new file mode 100644 index 0000000..b5808f2 --- /dev/null +++ b/src/main/kotlin/com/example/onui/domain/timeline/exception/TimelineNotFoundException.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 TimelineNotFoundException : BusinessException(ErrorCode.TIMELINE_NOT_FOUND) From 2112e62023e688a8724a24db143f68ad3d0b635d Mon Sep 17 00:00:00 2001 From: gurdl7011 Date: Mon, 13 Nov 2023 08:49:00 +0900 Subject: [PATCH 07/20] =?UTF-8?q?=E2=AD=90=EF=B8=8F=20::=20createComment,?= =?UTF-8?q?=20getComment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/CommentController.kt | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/main/kotlin/com/example/onui/domain/timeline/presentation/CommentController.kt diff --git a/src/main/kotlin/com/example/onui/domain/timeline/presentation/CommentController.kt b/src/main/kotlin/com/example/onui/domain/timeline/presentation/CommentController.kt new file mode 100644 index 0000000..925a65b --- /dev/null +++ b/src/main/kotlin/com/example/onui/domain/timeline/presentation/CommentController.kt @@ -0,0 +1,32 @@ +package com.example.onui.domain.timeline.presentation + +import com.example.onui.domain.timeline.presentation.dto.request.CommentRequest +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.util.* +import javax.validation.Valid + +@Validated +@RestController +@RequestMapping("/comment") +class CommentController( + private val timelineService: TimeLineService +) { + + @PostMapping + @ResponseStatus(HttpStatus.CREATED) + fun createComment( + @RequestParam("timeline_id", required = true) + timelineId: UUID, + @RequestBody @Valid + req: CommentRequest + ) = timelineService.comment(timelineId, req.comment) + + @GetMapping + fun getComment( + @RequestParam("timeline_id", required = true) + timelineId: UUID + ) = timelineService.getComment(timelineId) +} \ No newline at end of file From 7c1719803ec0b8ff84a28dd38bf5f802339bbbec Mon Sep 17 00:00:00 2001 From: gurdl7011 Date: Mon, 13 Nov 2023 08:49:34 +0900 Subject: [PATCH 08/20] =?UTF-8?q?=E2=AD=90=EF=B8=8F=20::=20createComment,?= =?UTF-8?q?=20getComment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../timeline/service/TimeLineService.kt | 12 +++-- .../timeline/service/TimelineServiceImpl.kt | 53 +++++++++++++------ 2 files changed, 46 insertions(+), 19 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 8556d52..45b469b 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,19 @@ package com.example.onui.domain.timeline.service -import com.example.onui.domain.diary.presentation.response.DiaryDetailResponse +import com.example.onui.domain.timeline.presentation.dto.response.CommentListResponse +import com.example.onui.domain.timeline.presentation.dto.response.CommentResponse +import com.example.onui.domain.timeline.presentation.dto.response.TimelineResponse import org.springframework.data.domain.Page import java.time.LocalDate import java.util.* interface TimeLineService { - fun post(id: UUID): DiaryDetailResponse + fun post(id: UUID): TimelineResponse - fun searchByDate(idx: Int, size: Int, date: LocalDate): Page + fun searchByDate(idx: Int, size: Int, date: LocalDate): Page + + fun comment(timelineId: UUID, comment: String): CommentResponse + + fun getComment(timelineId: UUID): CommentListResponse } 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 7211091..b35864a 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 @@ -2,9 +2,14 @@ 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.Comment import com.example.onui.domain.timeline.exception.AlreadyPostedTimeLineException +import com.example.onui.domain.timeline.exception.TimelineNotFoundException +import com.example.onui.domain.timeline.presentation.dto.response.CommentListResponse +import com.example.onui.domain.timeline.presentation.dto.response.CommentResponse +import com.example.onui.domain.timeline.presentation.dto.response.TimelineResponse +import com.example.onui.domain.timeline.repository.CommentRepository 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 @@ -21,15 +26,15 @@ import java.util.* class TimelineServiceImpl( private val userFacade: UserFacade, private val qTimelineRepository: QTimelineRepository, - private val diaryRepository: DiaryRepository + private val diaryRepository: DiaryRepository, + private val commentRepository: CommentRepository ) : TimeLineService { @Transactional - override fun post(id: UUID): DiaryDetailResponse { + override fun post(id: UUID): TimelineResponse { val user = userFacade.getCurrentUser() - val diary = diaryRepository.findByIdOrNull(id) - ?: throw DiaryNotFoundException + val diary = diaryRepository.findByIdOrNull(id) ?: throw DiaryNotFoundException if (diary.user != user) throw PermissionDeniedException @@ -37,20 +42,36 @@ class TimelineServiceImpl( return diaryRepository.save( Diary( - diary.user, - diary.content, - diary.mood, - diary.tagList, - diary.createdAt, - diary.image, - diary.id, - true + diary.user, diary.content, diary.mood, diary.tagList, diary.createdAt, diary.image, diary.id, true ) - ).toDetailResponse() + ).toTimelineResponse() } - override fun searchByDate(idx: Int, size: Int, date: LocalDate) = qTimelineRepository - .findPageByDate( + override fun searchByDate(idx: Int, size: Int, date: LocalDate) = qTimelineRepository.findPageByDate( PageRequest.of(idx, size, Sort.by("diary.createdAt").descending()), date ) + + @Transactional + override fun comment(timelineId: UUID, comment: String): CommentResponse { + + val timeline = diaryRepository.findByIdAndIsPosted(timelineId, true) ?: throw TimelineNotFoundException + + return commentRepository.save( + Comment( + comment, userFacade.getCurrentUser(), timeline + ) + ).toResponse() + } + + override fun getComment(timelineId: UUID): CommentListResponse { + + val timeline = diaryRepository.findByIdAndIsPosted(timelineId, true) ?: throw TimelineNotFoundException + + val commentList = + commentRepository.findAllByTimelineOrderByCreatedAtAsc(timeline).map { it.toResponse() }.toMutableList() + + return CommentListResponse(if (commentList.isEmpty()) null else commentList) + } + + } \ No newline at end of file From cbb4ba0c125af6ee71bbf1dd9e383da607adc087 Mon Sep 17 00:00:00 2001 From: gurdl7011 Date: Mon, 13 Nov 2023 08:50:40 +0900 Subject: [PATCH 09/20] =?UTF-8?q?=F0=9F=93=9D=20::=20rename?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...stedTimeLineException.kt => AlreadyPostedTimelineException.kt} | 0 .../timeline/service/{TimeLineService.kt => TimelineService.kt} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename src/main/kotlin/com/example/onui/domain/timeline/exception/{AlreadyPostedTimeLineException.kt => AlreadyPostedTimelineException.kt} (100%) rename src/main/kotlin/com/example/onui/domain/timeline/service/{TimeLineService.kt => TimelineService.kt} (100%) diff --git a/src/main/kotlin/com/example/onui/domain/timeline/exception/AlreadyPostedTimeLineException.kt b/src/main/kotlin/com/example/onui/domain/timeline/exception/AlreadyPostedTimelineException.kt similarity index 100% rename from src/main/kotlin/com/example/onui/domain/timeline/exception/AlreadyPostedTimeLineException.kt rename to src/main/kotlin/com/example/onui/domain/timeline/exception/AlreadyPostedTimelineException.kt 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 similarity index 100% rename from src/main/kotlin/com/example/onui/domain/timeline/service/TimeLineService.kt rename to src/main/kotlin/com/example/onui/domain/timeline/service/TimelineService.kt From b1ec81a4ab6cc87886abac62ebe11548af4af007 Mon Sep 17 00:00:00 2001 From: gurdl7011 Date: Mon, 13 Nov 2023 08:50:56 +0900 Subject: [PATCH 10/20] =?UTF-8?q?=E2=AD=90=EF=B8=8F=20::=20TimelineRespons?= =?UTF-8?q?e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../onui/domain/timeline/repository/QTimelineRepository.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 index 452a3b3..a6e45b0 100644 --- a/src/main/kotlin/com/example/onui/domain/timeline/repository/QTimelineRepository.kt +++ b/src/main/kotlin/com/example/onui/domain/timeline/repository/QTimelineRepository.kt @@ -1,11 +1,11 @@ package com.example.onui.domain.timeline.repository -import com.example.onui.domain.diary.presentation.response.DiaryDetailResponse +import com.example.onui.domain.timeline.presentation.dto.response.TimelineResponse 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 + fun findPageByDate(pageable: Pageable, date: LocalDate): Page } From 83246e9d384b94e2a061794fb912c601efcf592b Mon Sep 17 00:00:00 2001 From: gurdl7011 Date: Mon, 13 Nov 2023 08:51:33 +0900 Subject: [PATCH 11/20] =?UTF-8?q?=E2=AD=90=EF=B8=8F=20::=20TimelineRespons?= =?UTF-8?q?e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/timeline/repository/QTimelineRepositoryImpl.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 index e9214bc..6682381 100644 --- a/src/main/kotlin/com/example/onui/domain/timeline/repository/QTimelineRepositoryImpl.kt +++ b/src/main/kotlin/com/example/onui/domain/timeline/repository/QTimelineRepositoryImpl.kt @@ -1,7 +1,7 @@ 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.example.onui.domain.timeline.presentation.dto.response.TimelineResponse import com.querydsl.jpa.impl.JPAQueryFactory import org.springframework.data.domain.Page import org.springframework.data.domain.PageImpl @@ -14,7 +14,7 @@ class QTimelineRepositoryImpl( private val query: JPAQueryFactory ) : QTimelineRepository { - override fun findPageByDate(pageable: Pageable, date: LocalDate): Page { + 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( @@ -25,7 +25,7 @@ class QTimelineRepositoryImpl( ) ).orderBy(diary.createdAt.desc()).offset(pageable.offset).limit(pageable.pageSize.toLong()) - val iterable = query.fetch().map { it.toDetailResponse() } + val iterable = query.fetch().map { it.toTimelineResponse() } return PageImpl(iterable, pageable, iterable.size.toLong()) } From f271e08022f8cfbd1d72b111048f7cab20b220f0 Mon Sep 17 00:00:00 2001 From: gurdl7011 Date: Mon, 13 Nov 2023 08:51:46 +0900 Subject: [PATCH 12/20] =?UTF-8?q?=E2=AD=90=EF=B8=8F=20::=20TimelineRespons?= =?UTF-8?q?e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/dto/response/TimelineResponse.kt | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/com/example/onui/domain/timeline/presentation/dto/response/TimelineResponse.kt b/src/main/kotlin/com/example/onui/domain/timeline/presentation/dto/response/TimelineResponse.kt index 21a61be..0f93e6c 100644 --- a/src/main/kotlin/com/example/onui/domain/timeline/presentation/dto/response/TimelineResponse.kt +++ b/src/main/kotlin/com/example/onui/domain/timeline/presentation/dto/response/TimelineResponse.kt @@ -1,17 +1,14 @@ package com.example.onui.domain.timeline.presentation.dto.response import com.example.onui.domain.diary.entity.Mood -import java.time.DayOfWeek -import java.time.LocalDateTime import java.util.* data class TimelineResponse( val id: UUID, val content: String?, val mood: Mood, - val tag: MutableList, + val tagList: MutableList, val image: String?, - val dayOfWeek: DayOfWeek, - val createdAt: LocalDateTime, - val isUpdated: Boolean -) \ No newline at end of file + val writer: String, + val commentCount: Int +) From eeedd3b77d9b1b579b44a4bc49a9e62087ce09be Mon Sep 17 00:00:00 2001 From: gurdl7011 Date: Mon, 13 Nov 2023 08:57:04 +0900 Subject: [PATCH 13/20] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20::=20code=20style?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/timeline/presentation/TimelineController.kt | 8 +++----- 1 file changed, 3 insertions(+), 5 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 33ab5e8..2613ea0 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,7 +1,7 @@ package com.example.onui.domain.timeline.presentation import com.example.onui.domain.timeline.exception.InvalidDateFormatException -import com.example.onui.domain.timeline.service.TimeLineService +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.* @@ -13,14 +13,12 @@ import java.util.* @RestController @RequestMapping("/tl") class TimelineController( - private val timelineService: TimeLineService + private val timelineService: TimelineService ) { @PostMapping @ResponseStatus(HttpStatus.CREATED) - fun createTimeline( - @RequestParam("id", required = true) id: UUID - ) = timelineService.post(id) + fun createTimeline(@RequestParam("id", required = true) id: UUID) = timelineService.post(id) @GetMapping fun getByDate( From 5e63549af3eb515527774cbd61fac97918909b60 Mon Sep 17 00:00:00 2001 From: gurdl7011 Date: Mon, 13 Nov 2023 08:57:36 +0900 Subject: [PATCH 14/20] =?UTF-8?q?=F0=9F=93=9D=20::=20rename?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/AlreadyPostedTimelineException.kt | 2 +- .../domain/timeline/presentation/CommentController.kt | 4 ++-- .../onui/domain/timeline/service/TimelineService.kt | 2 +- .../domain/timeline/service/TimelineServiceImpl.kt | 10 +++++----- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/kotlin/com/example/onui/domain/timeline/exception/AlreadyPostedTimelineException.kt b/src/main/kotlin/com/example/onui/domain/timeline/exception/AlreadyPostedTimelineException.kt index bc3b5b7..331feb7 100644 --- a/src/main/kotlin/com/example/onui/domain/timeline/exception/AlreadyPostedTimelineException.kt +++ b/src/main/kotlin/com/example/onui/domain/timeline/exception/AlreadyPostedTimelineException.kt @@ -3,4 +3,4 @@ import com.example.onui.global.config.error.data.ErrorCode import com.example.onui.global.config.error.exception.BusinessException -object AlreadyPostedTimeLineException : BusinessException(ErrorCode.ALREADY_POSTED_TIMELINE) +object AlreadyPostedTimelineException : BusinessException(ErrorCode.ALREADY_POSTED_TIMELINE) diff --git a/src/main/kotlin/com/example/onui/domain/timeline/presentation/CommentController.kt b/src/main/kotlin/com/example/onui/domain/timeline/presentation/CommentController.kt index 925a65b..57973e9 100644 --- a/src/main/kotlin/com/example/onui/domain/timeline/presentation/CommentController.kt +++ b/src/main/kotlin/com/example/onui/domain/timeline/presentation/CommentController.kt @@ -1,7 +1,7 @@ package com.example.onui.domain.timeline.presentation import com.example.onui.domain.timeline.presentation.dto.request.CommentRequest -import com.example.onui.domain.timeline.service.TimeLineService +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.* @@ -12,7 +12,7 @@ import javax.validation.Valid @RestController @RequestMapping("/comment") class CommentController( - private val timelineService: TimeLineService + private val timelineService: TimelineService ) { @PostMapping 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 45b469b..a8537f5 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 @@ -7,7 +7,7 @@ import org.springframework.data.domain.Page import java.time.LocalDate import java.util.* -interface TimeLineService { +interface TimelineService { fun post(id: UUID): TimelineResponse 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 b35864a..def6f7b 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 @@ -4,7 +4,7 @@ import com.example.onui.domain.diary.entity.Diary import com.example.onui.domain.diary.exception.DiaryNotFoundException import com.example.onui.domain.diary.repository.DiaryRepository import com.example.onui.domain.timeline.entity.Comment -import com.example.onui.domain.timeline.exception.AlreadyPostedTimeLineException +import com.example.onui.domain.timeline.exception.AlreadyPostedTimelineException import com.example.onui.domain.timeline.exception.TimelineNotFoundException import com.example.onui.domain.timeline.presentation.dto.response.CommentListResponse import com.example.onui.domain.timeline.presentation.dto.response.CommentResponse @@ -28,7 +28,7 @@ class TimelineServiceImpl( private val qTimelineRepository: QTimelineRepository, private val diaryRepository: DiaryRepository, private val commentRepository: CommentRepository -) : TimeLineService { +) : TimelineService { @Transactional override fun post(id: UUID): TimelineResponse { @@ -38,7 +38,7 @@ class TimelineServiceImpl( if (diary.user != user) throw PermissionDeniedException - if (diaryRepository.existsByIdAndIsPosted(id, true)) throw AlreadyPostedTimeLineException + if (diaryRepository.existsByIdAndIsPosted(id, true)) throw AlreadyPostedTimelineException return diaryRepository.save( Diary( @@ -48,8 +48,8 @@ class TimelineServiceImpl( } override fun searchByDate(idx: Int, size: Int, date: LocalDate) = qTimelineRepository.findPageByDate( - PageRequest.of(idx, size, Sort.by("diary.createdAt").descending()), date - ) + PageRequest.of(idx, size, Sort.by("diary.createdAt").descending()), date + ) @Transactional override fun comment(timelineId: UUID, comment: String): CommentResponse { From 576c71ce510fa71d7f97cb2e9348f5955166373f Mon Sep 17 00:00:00 2001 From: gurdl7011 Date: Mon, 13 Nov 2023 08:58:06 +0900 Subject: [PATCH 15/20] =?UTF-8?q?=E2=AD=90=EF=B8=8F=20::=20comment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/com/example/onui/domain/user/entity/User.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/kotlin/com/example/onui/domain/user/entity/User.kt b/src/main/kotlin/com/example/onui/domain/user/entity/User.kt index 1c5db18..c977d46 100644 --- a/src/main/kotlin/com/example/onui/domain/user/entity/User.kt +++ b/src/main/kotlin/com/example/onui/domain/user/entity/User.kt @@ -1,6 +1,7 @@ package com.example.onui.domain.user.entity import com.example.onui.domain.diary.entity.Diary +import com.example.onui.domain.timeline.entity.Comment import com.example.onui.domain.user.presentation.dto.response.UserProfileResponse import org.hibernate.annotations.DynamicUpdate import java.util.* @@ -31,6 +32,9 @@ class User( @OneToMany(mappedBy = "user", cascade = [CascadeType.REMOVE]) var diaryList: MutableList = arrayListOf() + @OneToMany(mappedBy = "user", cascade = [CascadeType.REMOVE]) + var commentList: MutableList = arrayListOf() + fun toResponse() = UserProfileResponse( this.sub, this.name From 7f9a9ae176e1fdeba441974e67c130aa2da0b866 Mon Sep 17 00:00:00 2001 From: gurdl7011 Date: Mon, 13 Nov 2023 08:58:20 +0900 Subject: [PATCH 16/20] =?UTF-8?q?=E2=AD=90=EF=B8=8F=20::=20TIMELINE=5FNOT?= =?UTF-8?q?=5FFOUND?= 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 82a7c50..b4100ad 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 @@ -23,6 +23,7 @@ enum class ErrorCode( // 404 DIARY_NOT_FOUND(HttpStatus.NOT_FOUND, "감정 기록을 찾을 수 없습니다."), + TIMELINE_NOT_FOUND(HttpStatus.NOT_FOUND, "타임라인을 찾을 수 없습니다."), // 500 INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "서버 내부 에러") From c589a38862698026d3d02566abdd1c5ec5d3f270 Mon Sep 17 00:00:00 2001 From: gurdl7011 Date: Mon, 13 Nov 2023 08:58:36 +0900 Subject: [PATCH 17/20] =?UTF-8?q?=E2=AD=90=EF=B8=8F=20::=20findAllByTimeli?= =?UTF-8?q?neOrderByCreatedAtAsc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/timeline/repository/CommentRepository.kt | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/main/kotlin/com/example/onui/domain/timeline/repository/CommentRepository.kt diff --git a/src/main/kotlin/com/example/onui/domain/timeline/repository/CommentRepository.kt b/src/main/kotlin/com/example/onui/domain/timeline/repository/CommentRepository.kt new file mode 100644 index 0000000..adafc20 --- /dev/null +++ b/src/main/kotlin/com/example/onui/domain/timeline/repository/CommentRepository.kt @@ -0,0 +1,13 @@ +package com.example.onui.domain.timeline.repository + +import com.example.onui.domain.diary.entity.Diary +import com.example.onui.domain.timeline.entity.Comment +import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.stereotype.Repository +import java.util.* + +@Repository +interface CommentRepository : JpaRepository { + + fun findAllByTimelineOrderByCreatedAtAsc(timeline: Diary): MutableList +} \ No newline at end of file From da99ade71f8406b6e6a91064da7d890477385444 Mon Sep 17 00:00:00 2001 From: gurdl7011 Date: Mon, 13 Nov 2023 08:58:47 +0900 Subject: [PATCH 18/20] =?UTF-8?q?=E2=AD=90=EF=B8=8F=20::=20CommentResponse?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/dto/response/CommentResponse.kt | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 src/main/kotlin/com/example/onui/domain/timeline/presentation/dto/response/CommentResponse.kt diff --git a/src/main/kotlin/com/example/onui/domain/timeline/presentation/dto/response/CommentResponse.kt b/src/main/kotlin/com/example/onui/domain/timeline/presentation/dto/response/CommentResponse.kt new file mode 100644 index 0000000..210d128 --- /dev/null +++ b/src/main/kotlin/com/example/onui/domain/timeline/presentation/dto/response/CommentResponse.kt @@ -0,0 +1,10 @@ +package com.example.onui.domain.timeline.presentation.dto.response + +import java.util.* + +data class CommentResponse( + val id: UUID, + val timeline: UUID, + val user: UUID, + val content: String +) From 232138de989f80550d5b87fa2c2e9cfdfd75218b Mon Sep 17 00:00:00 2001 From: gurdl7011 Date: Mon, 13 Nov 2023 08:59:01 +0900 Subject: [PATCH 19/20] =?UTF-8?q?=E2=AD=90=EF=B8=8F=20::=20CommentListResp?= =?UTF-8?q?onse?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/dto/response/CommentListResponse.kt | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 src/main/kotlin/com/example/onui/domain/timeline/presentation/dto/response/CommentListResponse.kt diff --git a/src/main/kotlin/com/example/onui/domain/timeline/presentation/dto/response/CommentListResponse.kt b/src/main/kotlin/com/example/onui/domain/timeline/presentation/dto/response/CommentListResponse.kt new file mode 100644 index 0000000..06725fe --- /dev/null +++ b/src/main/kotlin/com/example/onui/domain/timeline/presentation/dto/response/CommentListResponse.kt @@ -0,0 +1,5 @@ +package com.example.onui.domain.timeline.presentation.dto.response + +data class CommentListResponse( + val commentList: MutableList? +) From 5fd8cbf85af4d3023fb62692021d28448f0a3838 Mon Sep 17 00:00:00 2001 From: gurdl7011 Date: Mon, 13 Nov 2023 08:59:27 +0900 Subject: [PATCH 20/20] =?UTF-8?q?=E2=AD=90=EF=B8=8F=20::=20CommentRequest?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/dto/request/CommentRequest.kt | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/main/kotlin/com/example/onui/domain/timeline/presentation/dto/request/CommentRequest.kt diff --git a/src/main/kotlin/com/example/onui/domain/timeline/presentation/dto/request/CommentRequest.kt b/src/main/kotlin/com/example/onui/domain/timeline/presentation/dto/request/CommentRequest.kt new file mode 100644 index 0000000..c5ccbf7 --- /dev/null +++ b/src/main/kotlin/com/example/onui/domain/timeline/presentation/dto/request/CommentRequest.kt @@ -0,0 +1,11 @@ +package com.example.onui.domain.timeline.presentation.dto.request + +import javax.validation.constraints.NotBlank +import javax.validation.constraints.Size + +data class CommentRequest( + + @field:NotBlank(message = "comment는 null일 수 없습니다.") + @field:Size(max = 50, message = "댓글은 최대 50자 입니다.") + val comment: String +)