-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
230 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/main/kotlin/com/example/onui/domain/timeline/entity/Comment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/main/kotlin/com/example/onui/domain/timeline/exception/TimelineNotFoundException.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
32 changes: 32 additions & 0 deletions
32
src/main/kotlin/com/example/onui/domain/timeline/presentation/CommentController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/main/kotlin/com/example/onui/domain/timeline/presentation/dto/request/CommentRequest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
5 changes: 5 additions & 0 deletions
5
.../kotlin/com/example/onui/domain/timeline/presentation/dto/response/CommentListResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>? | ||
) |
10 changes: 10 additions & 0 deletions
10
...main/kotlin/com/example/onui/domain/timeline/presentation/dto/response/CommentResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
11 changes: 4 additions & 7 deletions
11
...ain/kotlin/com/example/onui/domain/timeline/presentation/dto/response/TimelineResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
13 changes: 13 additions & 0 deletions
13
src/main/kotlin/com/example/onui/domain/timeline/repository/CommentRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
} |
4 changes: 2 additions & 2 deletions
4
src/main/kotlin/com/example/onui/domain/timeline/repository/QTimelineRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 0 additions & 13 deletions
13
src/main/kotlin/com/example/onui/domain/timeline/service/TimeLineService.kt
This file was deleted.
Oops, something went wrong.
19 changes: 19 additions & 0 deletions
19
src/main/kotlin/com/example/onui/domain/timeline/service/TimelineService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.