✨ 공지사항 등록
This commit is contained in:
@@ -5,16 +5,16 @@ data class Notice(
|
|||||||
val content: String,
|
val content: String,
|
||||||
) {
|
) {
|
||||||
data class Summary(
|
data class Summary(
|
||||||
val id: String,
|
val id: String? = null,
|
||||||
val title: String,
|
val title: String,
|
||||||
val createdAt: String,
|
val createdAt: String? = null,
|
||||||
)
|
)
|
||||||
|
|
||||||
data class Detail(
|
data class Detail(
|
||||||
val id: String,
|
val id: String? = null,
|
||||||
val title: String,
|
val title: String,
|
||||||
val content: String,
|
val content: String,
|
||||||
val createdAt: String,
|
val createdAt: String? = null,
|
||||||
)
|
)
|
||||||
|
|
||||||
fun detail(): Detail {
|
fun detail(): Detail {
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package me.jiniworld.demohx.application.notice.port.input
|
||||||
|
|
||||||
|
data class RegisterNoticeCommand(
|
||||||
|
val title: String,
|
||||||
|
val content: String,
|
||||||
|
)
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package me.jiniworld.demohx.application.notice.port.input
|
||||||
|
|
||||||
|
interface RegisterNoticeUseCase {
|
||||||
|
suspend fun registerNotice(command: RegisterNoticeCommand)
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package me.jiniworld.demohx.application.notice.port.output
|
||||||
|
|
||||||
|
import me.jiniworld.demohx.application.notice.domain.Notice
|
||||||
|
|
||||||
|
interface SaveNoticePort {
|
||||||
|
suspend fun saveNotice(notice: Notice)
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package me.jiniworld.demohx.application.notice.service
|
||||||
|
|
||||||
|
import me.jiniworld.demohx.annotation.UseCase
|
||||||
|
import me.jiniworld.demohx.application.notice.domain.Notice
|
||||||
|
import me.jiniworld.demohx.application.notice.port.input.RegisterNoticeCommand
|
||||||
|
import me.jiniworld.demohx.application.notice.port.input.RegisterNoticeUseCase
|
||||||
|
import me.jiniworld.demohx.application.notice.port.output.SaveNoticePort
|
||||||
|
import org.springframework.transaction.annotation.Transactional
|
||||||
|
|
||||||
|
@Transactional(readOnly = true)
|
||||||
|
@UseCase
|
||||||
|
internal class RegisterNoticeService(
|
||||||
|
private val saveNoticePort: SaveNoticePort,
|
||||||
|
): RegisterNoticeUseCase {
|
||||||
|
|
||||||
|
override suspend fun registerNotice(command: RegisterNoticeCommand) {
|
||||||
|
saveNoticePort.saveNotice(Notice(Notice.Summary(title = command.title), content = command.content))
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -9,4 +9,7 @@ internal object NoticeMapper {
|
|||||||
Notice(summary = Notice.Summary(id = doc.id, title = doc.title,
|
Notice(summary = Notice.Summary(id = doc.id, title = doc.title,
|
||||||
createdAt = DateTimeUtils.toString(doc.createdAt)), content = doc.content)
|
createdAt = DateTimeUtils.toString(doc.createdAt)), content = doc.content)
|
||||||
|
|
||||||
|
fun mapToDocument(notice: Notice) =
|
||||||
|
NoticeDocument(title = notice.summary.title, content = notice.content)
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -5,12 +5,13 @@ import kotlinx.coroutines.flow.map
|
|||||||
import me.jiniworld.demohx.annotation.PersistenceAdapter
|
import me.jiniworld.demohx.annotation.PersistenceAdapter
|
||||||
import me.jiniworld.demohx.application.notice.domain.Notice
|
import me.jiniworld.demohx.application.notice.domain.Notice
|
||||||
import me.jiniworld.demohx.application.notice.port.output.LoadNoticePort
|
import me.jiniworld.demohx.application.notice.port.output.LoadNoticePort
|
||||||
|
import me.jiniworld.demohx.application.notice.port.output.SaveNoticePort
|
||||||
import org.springframework.data.domain.Pageable
|
import org.springframework.data.domain.Pageable
|
||||||
|
|
||||||
@PersistenceAdapter
|
@PersistenceAdapter
|
||||||
internal class NoticePersistenceAdapter(
|
internal class NoticePersistenceAdapter(
|
||||||
private val noticeRepository: NoticeRepository,
|
private val noticeRepository: NoticeRepository,
|
||||||
) : LoadNoticePort {
|
) : LoadNoticePort, SaveNoticePort {
|
||||||
override fun loadNotices(pageable: Pageable): Flow<Notice> {
|
override fun loadNotices(pageable: Pageable): Flow<Notice> {
|
||||||
return noticeRepository.findAllBy(pageable).map { NoticeMapper.mapToNotice(it) }
|
return noticeRepository.findAllBy(pageable).map { NoticeMapper.mapToNotice(it) }
|
||||||
}
|
}
|
||||||
@@ -18,4 +19,8 @@ internal class NoticePersistenceAdapter(
|
|||||||
override suspend fun loadNotice(id: String): Notice? {
|
override suspend fun loadNotice(id: String): Notice? {
|
||||||
return noticeRepository.findById(id)?.let { NoticeMapper.mapToNotice(it) }
|
return noticeRepository.findById(id)?.let { NoticeMapper.mapToNotice(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun saveNotice(notice: Notice) {
|
||||||
|
noticeRepository.save(NoticeMapper.mapToDocument(notice))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package me.jiniworld.demohx.web.notice
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.Operation
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag
|
||||||
|
import me.jiniworld.demohx.annotation.WebAdapter
|
||||||
|
import me.jiniworld.demohx.application.notice.port.input.RegisterNoticeCommand
|
||||||
|
import me.jiniworld.demohx.application.notice.port.input.RegisterNoticeUseCase
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping
|
||||||
|
import org.springframework.web.bind.annotation.RestController
|
||||||
|
|
||||||
|
@WebAdapter
|
||||||
|
@Tag(name = "setting-system", description = "설정-시스템(공지사항, FAQ, 이용약관, 메타정보 등)")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/v1/notices")
|
||||||
|
internal class RegisterNoticeController(
|
||||||
|
private val registerNoticeUseCase: RegisterNoticeUseCase,
|
||||||
|
) {
|
||||||
|
|
||||||
|
@Operation(summary = "공지사항 등록")
|
||||||
|
@PostMapping("")
|
||||||
|
suspend fun getNotices(
|
||||||
|
@RequestBody command: RegisterNoticeCommand,
|
||||||
|
) = registerNoticeUseCase.registerNotice(command)
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user