Skip to content

Commit

Permalink
Implement journal modification (#29)
Browse files Browse the repository at this point in the history
Resolved: #28
  • Loading branch information
zionhann authored Aug 5, 2024
1 parent b3dc72e commit eb12046
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 3 deletions.
45 changes: 45 additions & 0 deletions api-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,51 @@ paths:
content: |
미팅 시간에 돌아가면서 진행상황을 공유했다. 각자의 역할은 존중하면서 하나의 프로덕트를 다같이 만들어간다는 느낌이 들어 기분이 좋았다.
createdDate: 24.07.17
put:
tags:
- journals
summary: 일지 수정
description: " "
operationId: updateJournal
parameters:
- name: journalId
in: path
required: true
schema:
type: string
description: 일지 ID
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/JournalRequest'
examples:
JournalUpdateRequestExample:
value:
title: 중앙해커톤 대상(수정)
content: 수정할 내용
thumbnail: https://3-namsong-st.s3.ap-northeast-2.amazonaws.com/goals/b46f73d9-fa83-4331-b37d-996897280aa6.jpeg...
responses:
"200":
description: OK
delete:
tags:
- journals
summary: 일지 삭제
description: " "
operationId: deleteJournal
parameters:
- name: journalId
in: path
required: true
schema:
type: string
description: 일지 ID
responses:
"200":
description: OK


# chat
/v1/goals/{goalId}/chats:
Expand Down
10 changes: 8 additions & 2 deletions src/main/kotlin/com/likelionhgu/stepper/journal/Journal.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,19 @@ class Journal(

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id")
val member: Member,
val member: Member? = null,

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "goal_id")
val goal: Goal
val goal: Goal? = null
) : BaseTime() {

fun update(targetJournal: Journal) {
title = targetJournal.title
content = targetJournal.content
thumbnail = targetJournal.thumbnail
}

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
val journalId = 0L
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import jakarta.validation.Valid
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.security.core.annotation.AuthenticationPrincipal
import org.springframework.web.bind.annotation.DeleteMapping
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.PutMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
Expand Down Expand Up @@ -62,4 +64,19 @@ class JournalController(
val responseBody = JournalResponseWrapper.JournalResponse.of(journal)
return ResponseEntity.ok(responseBody)
}

@PutMapping("/v1/journals/{journalId}")
fun updateJournal(
@PathVariable journalId: Long,
@Valid @RequestBody journalRequest: JournalRequest
) {
journalService.updateJournal(journalId, journalRequest)
}

@DeleteMapping("/v1/journals/{journalId}")
fun deleteJournal(
@PathVariable journalId: Long
) {
journalService.deleteJournal(journalId)
}
}
10 changes: 10 additions & 0 deletions src/main/kotlin/com/likelionhgu/stepper/journal/JournalService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,14 @@ class JournalService(
return journalRepository.findById(journalId).getOrNull()
?: throw JournalNotFoundException("Journal not found with ID: $journalId")
}

fun updateJournal(journalId: Long, journalRequest: JournalRequest) {
val sourceJournal = journalInfo(journalId)
val targetJournal = journalRequest.toEntity()
sourceJournal.update(targetJournal)
}

fun deleteJournal(journalId: Long) {
journalRepository.deleteById(journalId)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.likelionhgu.stepper.journal.request

import com.likelionhgu.stepper.journal.Journal
import jakarta.validation.constraints.NotBlank
import jakarta.validation.constraints.NotNull

Expand All @@ -13,4 +14,10 @@ data class JournalRequest(
val content: String?,

val thumbnail: String? = null
)
) {
fun toEntity() = Journal(
title = title!!,
content = content.orEmpty(),
thumbnail = thumbnail
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.likelionhgu.stepper.journal.request.JournalRequest
import io.kotest.core.spec.style.BehaviorSpec
import io.kotest.extensions.spring.SpringExtension
import io.kotest.matchers.collections.shouldHaveSize
import io.kotest.matchers.shouldBe
import io.kotest.matchers.shouldNotBe
import io.mockk.every
import io.mockk.mockk
Expand Down Expand Up @@ -72,6 +73,18 @@ class JournalServiceTest : BehaviorSpec({
journal shouldNotBe null
}
}

`when`("a member tries to update a journal entry") {
then("the journal entry should be updated") {
val target = JournalRequest("Updated Title", "Updated Content")
journalService.updateJournal(0L, target)

val result = journalService.journalInfo(0L)

result.title shouldBe "Updated Title"
result.content shouldBe "Updated Content"
}
}
}
}) {
override fun extensions() = listOf(SpringExtension)
Expand Down

0 comments on commit eb12046

Please sign in to comment.