Skip to content

Commit

Permalink
Merge branch 'develop' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
gurdl0525 committed Nov 12, 2023
2 parents 4a72e6c + 99f2f2d commit 425f340
Show file tree
Hide file tree
Showing 21 changed files with 230 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.*

Expand All @@ -17,6 +18,7 @@ class AuthController(
) {

@PostMapping("/google")
@ResponseStatus(HttpStatus.CREATED)
fun oauthSignIn(
@RequestParam(name = "token", required = true)
token: String
Expand All @@ -29,6 +31,7 @@ class AuthController(
): TokenResponse = authService.reissue(token)

@PostMapping("/apple")
@ResponseStatus(HttpStatus.CREATED)
fun oauthSignInWithApple(
@RequestParam(name = "token", required = true)
token: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -47,8 +53,6 @@ class GoogleAuthServiceImpl(
)
)

googleAuth.revokeToken(token)

return tokenResponse
}
}
15 changes: 15 additions & 0 deletions src/main/kotlin/com/example/onui/domain/diary/entity/Diary.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -54,6 +56,9 @@ Diary(
var isPosted: Boolean = isPosted
protected set

@OneToMany(mappedBy = "timeline", cascade = [CascadeType.REMOVE])
var commentList: MutableList<Comment> = arrayListOf()

fun toResponse() = DiaryResponse(
this.id!!,
this.mood,
Expand All @@ -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
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ interface DiaryRepository : JpaRepository<Diary, UUID?> {
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?
}
47 changes: 47 additions & 0 deletions src/main/kotlin/com/example/onui/domain/timeline/entity/Comment.kt
Original file line number Diff line number Diff line change
@@ -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
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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)
}
Original file line number Diff line number Diff line change
@@ -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.*
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.example.onui.domain.timeline.presentation.dto.response

data class CommentListResponse(
val commentList: MutableList<CommentResponse>?
)
Original file line number Diff line number Diff line change
@@ -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
)
Original file line number Diff line number Diff line change
@@ -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<String>,
val tagList: MutableList<String>,
val image: String?,
val dayOfWeek: DayOfWeek,
val createdAt: LocalDateTime,
val isUpdated: Boolean
)
val writer: String,
val commentCount: Int
)
Original file line number Diff line number Diff line change
@@ -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<Comment, UUID?> {

fun findAllByTimelineOrderByCreatedAtAsc(timeline: Diary): MutableList<Comment>
}
Original file line number Diff line number Diff line change
@@ -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<DiaryDetailResponse>
fun findPageByDate(pageable: Pageable, date: LocalDate): Page<TimelineResponse>
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -14,7 +14,7 @@ class QTimelineRepositoryImpl(
private val query: JPAQueryFactory
) : QTimelineRepository {

override fun findPageByDate(pageable: Pageable, date: LocalDate): Page<DiaryDetailResponse> {
override fun findPageByDate(pageable: Pageable, date: LocalDate): Page<TimelineResponse> {
val query = query.selectFrom(diary).where(
diary.isPosted.eq(true).and(
diary.day.eq(date.dayOfMonth).and(
Expand All @@ -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())
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.example.onui.domain.timeline.service

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): TimelineResponse

fun searchByDate(idx: Int, size: Int, date: LocalDate): Page<TimelineResponse>

fun comment(timelineId: UUID, comment: String): CommentResponse

fun getComment(timelineId: UUID): CommentListResponse
}
Loading

0 comments on commit 425f340

Please sign in to comment.