Skip to content

Commit

Permalink
feat: implement CreateDiaryService and usecase
Browse files Browse the repository at this point in the history
  • Loading branch information
SkyLightQP committed Jan 1, 2025
1 parent 3971b8b commit 0ca1285
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package me.daegyeo.maru.diary.application.port.`in`

import me.daegyeo.maru.diary.application.domain.Diary
import me.daegyeo.maru.diary.application.port.`in`.command.CreateDiaryCommand

fun interface CreateDiaryUseCase {
fun createDiary(input: CreateDiaryCommand): Diary
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package me.daegyeo.maru.diary.application.port.`in`.command

import java.util.UUID

data class CreateDiaryCommand(
val content: String,
val userId: UUID,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package me.daegyeo.maru.diary.application.service

import me.daegyeo.maru.diary.application.domain.Diary
import me.daegyeo.maru.diary.application.port.`in`.CreateDiaryUseCase
import me.daegyeo.maru.diary.application.port.`in`.EncryptDiaryUseCase
import me.daegyeo.maru.diary.application.port.`in`.command.CreateDiaryCommand
import me.daegyeo.maru.diary.application.port.out.CreateDiaryPort
import me.daegyeo.maru.diary.application.port.out.dto.CreateDiaryDto
import me.daegyeo.maru.user.application.port.`in`.GetUserUseCase
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
class CreateDiaryService(
private val getUserUseCase: GetUserUseCase,
private val createDiaryPort: CreateDiaryPort,
private val encryptDiaryUseCase: EncryptDiaryUseCase,
) :
CreateDiaryUseCase {
@Transactional
override fun createDiary(input: CreateDiaryCommand): Diary {
val user = getUserUseCase.getUser(input.userId)
val encryptedContent = encryptDiaryUseCase.encryptDiary(input.content)
val diary =
createDiaryPort.createDiary(
CreateDiaryDto(
userId = user.userId,
content = encryptedContent,
),
)
return diary.let {
it.content = ""
it
}
}
}

0 comments on commit 0ca1285

Please sign in to comment.