Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include thumbnail url in response #24

Merged
merged 2 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions api-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ paths:
title: 진행상황 공유
content: |
미팅 시간에 돌아가면서 진행상황을 공유했다. 각자의 역할은 존중하면서 하나의 프로덕트를 다같이 만들어간다는 느낌이 들어 기분이 좋았다.
thumbnail: https://3-namsong-st.s3.ap-northeast-2.amazonaws.com/goals/b46f73d9-fa83-4331-b37d-996897280aa6.jpeg...
responses:
"201":
description: Created
Expand Down Expand Up @@ -216,10 +217,11 @@ paths:
- journalId: 1
title: 진행상황 공유
createdDate: 24.07.17
# thumbnail: https://3-namsong-st.s3.ap-northeast-2.amazonaws.com/goals/b46f73d9-fa83-4331-b37d-996897280aa6.jpeg...
thumbnail: https://3-namsong-st.s3.ap-northeast-2.amazonaws.com/goals/b46f73d9-fa83-4331-b37d-996897280aa6.jpeg...
- journalId: 2
title: 아이디어 디벨롭
createdDate: 24.07.16
thumbnail: https://3-namsong-st.s3.ap-northeast-2.amazonaws.com/goals/b46f73d9-fa83-4331-b37d-996897280aa6.jpeg...
/v1/journals/{journalId}:
get:
tags:
Expand Down Expand Up @@ -366,9 +368,9 @@ components:
GoalResponse:
type: object
properties:
goaldId:
goalId:
type: number
descriptiom: 목표 ID
description: 목표 ID
title:
type: string
description: 목표 이름
Expand Down Expand Up @@ -403,6 +405,9 @@ components:
content:
type: string
description: 일지내용
thumbnail:
type: string
description: 썸네일 이미지 URL
JournalResponse:
type: object
properties:
Expand All @@ -415,9 +420,9 @@ components:
createdDate:
type: string
description: 작성일자
# thumbnail:
# type: string
# description: 썸네일 이미지
thumbnail:
type: string
description: 썸네일 이미지 URL
JournalDetailResponse:
type: object
properties:
Expand All @@ -436,7 +441,7 @@ components:
CsrfToken:
type: object
properties:
prameterName:
parameterName:
type: string
description: csrf 파라미터 키값
token:
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/com/likelionhgu/stepper/goal/Goal.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Goal(
@Column
var endDate: LocalDate? = null,

@Column
@Column(length = 512)
var thumbnail: String? = null,

@ManyToOne(fetch = FetchType.LAZY)
Expand Down
3 changes: 3 additions & 0 deletions src/main/kotlin/com/likelionhgu/stepper/journal/Journal.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ class Journal(
@Column(length = 2048)
var content: String,

@Column(length = 512)
var thumbnail: String? = null,

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id")
val member: Member,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class JournalService(
val journal = Journal(
title = request.title!!,
content = request.content.orEmpty(),
thumbnail = request.thumbnail,
member = member,
goal = goal
).let(journalRepository::save)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ data class JournalRequest(
val title: String?,

@field:NotNull(message = "content cannot be null")
val content: String?
val content: String?,

val thumbnail: String? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,45 @@ import com.fasterxml.jackson.annotation.JsonFormat
import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL
import com.likelionhgu.stepper.goal.Goal
import com.likelionhgu.stepper.goal.response.GoalResponseWrapper
import com.likelionhgu.stepper.goal.response.GoalResponseWrapper.GoalResponse
import com.likelionhgu.stepper.journal.Journal
import java.time.LocalDate

@JsonInclude(NON_NULL)
data class JournalResponseWrapper(
val goal: GoalResponseWrapper.GoalResponse,
val journals: List<JournalResponse>
) {
data class JournalResponseWrapper(val goal: GoalResponse, val journals: List<JournalResponse>) {

data class JournalResponse(
val journalId: Long,
val title: String,
val content: String?,

@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yy.MM.dd", timezone = "Asia/Seoul")
val createdDate: LocalDate
val createdDate: LocalDate,

val content: String?,
val thumbnail: String?
) {
companion object {
fun of(journal: Journal): JournalResponse = JournalResponse(
journalId = journal.journalId,
title = journal.title,
content = journal.content,
createdDate = journal.createdDate.toLocalDate()
createdDate = journal.createdDate.toLocalDate(),
thumbnail = journal.thumbnail
)
}
}

companion object {
fun of(goal: Goal, journals: List<Journal>): JournalResponseWrapper {
return JournalResponseWrapper(
goal = GoalResponseWrapper.GoalResponse.of(goal),
goal = GoalResponse.of(goal),
journals = journals.map {
JournalResponse(
journalId = it.journalId,
title = it.title,
content = null,
createdDate = it.createdDate.toLocalDate()
createdDate = it.createdDate.toLocalDate(),
thumbnail = it.thumbnail
)
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ class JournalControllerTest(
Journal(
"title1",
"content",
mockk(),
mockk()
member = mockk(),
goal = mockk()
),
Journal(
"title2",
"content",
mockk(),
mockk()
member = mockk(),
goal = mockk()
)
)

Expand All @@ -91,7 +91,12 @@ class JournalControllerTest(
}

given("a journal entry ID which exists") {
every { journalService.journalInfo(any()) } returns Journal("title", "content", mockk(), mockk())
every { journalService.journalInfo(any()) } returns Journal(
"title",
"content",
member = mockk(),
goal = mockk()
)

`when`("a member tries to read a journal entry") {
then("the request should be successful") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class JournalRepositoryTest(
val goal = goalRepository.save(Goal(title = "title", member = member))

given("multiple journal entries") {
val j1 = journalRepository.save(Journal("title1", "content", member, goal))
val j2 = journalRepository.save(Journal("title2", "content", member, goal))
val j1 = journalRepository.save(Journal("title1", "content", member = member, goal = goal))
val j2 = journalRepository.save(Journal("title2", "content", member = member, goal = goal))

`when`("the member requests to see the journal entries with default order") {
then("the journal entries should be returned ordered by created date in descending order") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ class JournalServiceTest : BehaviorSpec({
val journalService = JournalService(journalRepository)

given("A member who has created a goal") {
every { journalRepository.save(any<Journal>()) } returns Journal("title", "content", mockk(), mockk())
every { journalRepository.save(any<Journal>()) } returns Journal(
"title",
"content",
member = mockk(),
goal = mockk()
)
val request = JournalRequest("title", "content")

`when`("the member writes the journal entry") {
Expand All @@ -32,14 +37,14 @@ class JournalServiceTest : BehaviorSpec({
Journal(
"title1",
"content",
mockk(),
mockk()
member = mockk(),
goal = mockk()
),
Journal(
"title2",
"content",
mockk(),
mockk()
member = mockk(),
goal = mockk()
)
)

Expand All @@ -53,7 +58,12 @@ class JournalServiceTest : BehaviorSpec({
}

given("a journal entry ID") {
every { journalRepository.findById(any()).getOrNull() } returns Journal("title", "content", mockk(), mockk())
every { journalRepository.findById(any()).getOrNull() } returns Journal(
"title",
"content",
member = mockk(),
goal = mockk()
)

`when`("a member tries to read a journal entry") {
then("the journal entry should be returned") {
Expand Down
Loading