-
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.
feat: implement CreateDiaryService and usecase
- Loading branch information
1 parent
3971b8b
commit 0ca1285
Showing
3 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
src/main/kotlin/me/daegyeo/maru/diary/application/port/in/CreateDiaryUseCase.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,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 | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/kotlin/me/daegyeo/maru/diary/application/port/in/command/CreateDiaryCommand.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,8 @@ | ||
package me.daegyeo.maru.diary.application.port.`in`.command | ||
|
||
import java.util.UUID | ||
|
||
data class CreateDiaryCommand( | ||
val content: String, | ||
val userId: UUID, | ||
) |
36 changes: 36 additions & 0 deletions
36
src/main/kotlin/me/daegyeo/maru/diary/application/service/CreateDiaryService.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,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 | ||
} | ||
} | ||
} |