Skip to content

Commit

Permalink
create tag api의 PathVariable에 memberId를 추가한다
Browse files Browse the repository at this point in the history
  • Loading branch information
anjeongkyun committed Nov 6, 2023
1 parent d3770c2 commit df0b046
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ class TagController(
private val createTagsCommandExecutor: CreateTagsCommandExecutor,
private val getTagsQueryProcessor: GetTagsQueryProcessor
) {
@PostMapping("/tags")
@PostMapping("/members/{memberId}/tags")
fun createTags(
@PathVariable("memberId") memberId: Long,
@RequestBody command: CreateTagsCommand
) {
try {
createTagsCommandExecutor.execute(
memberId = memberId,
command = command
)
} catch (e: InvalidCommandException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ package org.tagwonder.commands

data class CreateTagsCommand(
val titles: List<String>,
val memberId: Long
)
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ import org.tagwonder.usecases.utils.hasDuplicate
class CreateTagsCommandExecutor(
private val tagRepository: ITagRepository
) {
fun execute(command: CreateTagsCommand) {
fun execute(memberId: Long, command: CreateTagsCommand) {
validCommand(command)
existsTitleInTag(command)
existsTitleInTag(memberId, command.titles)
tagRepository.creates(
command.titles.map {
Tag(
title = it,
memberId = command.memberId
memberId = memberId
)
}
)
}

private fun existsTitleInTag(command: CreateTagsCommand) {
command.titles.forEach {
tagRepository.find(command.memberId, it)?.let {
private fun existsTitleInTag(memberId: Long, titles: List<String>) {
titles.forEach {
tagRepository.find(memberId, it)?.let {
throw InvalidRequestException("title already exists")
}
}
Expand Down

0 comments on commit df0b046

Please sign in to comment.