-
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.
- Loading branch information
Showing
13 changed files
with
150 additions
and
33 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
src/main/kotlin/com/soon/common/application/ItemCommandService.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,15 @@ | ||
package com.soon.common.application | ||
|
||
import com.soon.common.application.model.ItemCreateCommand | ||
import com.soon.common.domain.item.Item | ||
import com.soon.common.domain.item.ItemRepository | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class ItemCommandService( | ||
private val itemRepository: ItemRepository, | ||
) { | ||
suspend fun createItem(command: ItemCreateCommand) { | ||
itemRepository.save(Item.create(command.toCreateModel())) | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/kotlin/com/soon/common/application/model/ItemCreateCommand.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,15 @@ | ||
package com.soon.common.application.model | ||
|
||
import com.soon.common.domain.item.model.ItemCreateModel | ||
|
||
data class ItemCreateCommand( | ||
val serviceNo: Int, | ||
val title: String, | ||
val description: String, | ||
) { | ||
fun toCreateModel() = ItemCreateModel( | ||
serviceNo = serviceNo, | ||
title = title, | ||
description = description, | ||
) | ||
} |
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
7 changes: 0 additions & 7 deletions
7
src/main/kotlin/com/soon/common/application/util/MessageBroker.kt
This file was deleted.
Oops, something went wrong.
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,34 @@ | ||
package com.soon.common.domain.item | ||
|
||
import com.soon.common.domain.item.model.ItemCreateModel | ||
import jakarta.persistence.* | ||
import java.time.LocalDateTime | ||
|
||
@Entity | ||
@Table(name = "item") | ||
class Item( | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "item_no") | ||
val no: Int = 0, | ||
|
||
@Column(name = "service_no") | ||
val serviceNo: Int, | ||
|
||
@Column(name = "title") | ||
val title: String, | ||
|
||
@Column(name = "description") | ||
val description: String, | ||
) { | ||
@Column(name = "created_at") | ||
val createdAt: LocalDateTime = LocalDateTime.now() | ||
|
||
companion object { | ||
fun create(createModel: ItemCreateModel) = Item( | ||
serviceNo = createModel.serviceNo, | ||
title = createModel.title, | ||
description = createModel.description, | ||
) | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/kotlin/com/soon/common/domain/item/ItemRepository.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,5 @@ | ||
package com.soon.common.domain.item | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository | ||
|
||
interface ItemRepository : JpaRepository<Item, Int> |
7 changes: 7 additions & 0 deletions
7
src/main/kotlin/com/soon/common/domain/item/model/ItemCreateModel.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,7 @@ | ||
package com.soon.common.domain.item.model | ||
|
||
data class ItemCreateModel( | ||
val serviceNo: Int, | ||
val title: String, | ||
val description: String, | ||
) |
27 changes: 27 additions & 0 deletions
27
src/main/kotlin/com/soon/common/presentation/handler/ItemHandler.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,27 @@ | ||
package com.soon.common.presentation.handler | ||
|
||
import com.soon.common.application.ItemCommandService | ||
import com.soon.common.application.util.coroutines.ApplicationDispatchers | ||
import com.soon.common.presentation.handler.model.ItemCreateRequest | ||
import com.soon.member.presentation.extension.extractServiceCodeHeader | ||
import kotlinx.coroutines.withContext | ||
import org.springframework.stereotype.Service | ||
import org.springframework.web.reactive.function.server.ServerRequest | ||
import org.springframework.web.reactive.function.server.ServerResponse | ||
import org.springframework.web.reactive.function.server.awaitBodyOrNull | ||
import org.springframework.web.reactive.function.server.buildAndAwait | ||
|
||
@Service | ||
class ItemHandler( | ||
private val itemCommandService: ItemCommandService | ||
) { | ||
suspend fun createItem(request: ServerRequest): ServerResponse = withContext(ApplicationDispatchers.IO) { | ||
val serviceHeader = request.extractServiceCodeHeader() | ||
val command = request.awaitBodyOrNull<ItemCreateRequest>()?.toCommand(serviceHeader.no) | ||
?: throw IllegalArgumentException() | ||
|
||
itemCommandService.createItem(command) | ||
ServerResponse.noContent().buildAndAwait() | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
src/main/kotlin/com/soon/common/presentation/handler/model/ItemCreateRequest.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,14 @@ | ||
package com.soon.common.presentation.handler.model | ||
|
||
import com.soon.common.application.model.ItemCreateCommand | ||
|
||
data class ItemCreateRequest( | ||
val title: String, | ||
val description: String, | ||
) { | ||
fun toCommand(serviceNo: Int) = ItemCreateCommand( | ||
serviceNo = serviceNo, | ||
title = title, | ||
description = description, | ||
) | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/kotlin/com/soon/common/presentation/router/item/ItemInternalRouter.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,21 @@ | ||
package com.soon.common.presentation.router.item | ||
|
||
import com.soon.common.presentation.handler.ItemHandler | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.http.MediaType | ||
import org.springframework.web.reactive.function.server.RouterFunction | ||
import org.springframework.web.reactive.function.server.ServerResponse | ||
import org.springframework.web.reactive.function.server.coRouter | ||
|
||
@Configuration | ||
class ItemInternalRouter(private val itemHandler: ItemHandler) { | ||
@Bean | ||
fun itemBackOfficeRoute(): RouterFunction<ServerResponse> { | ||
return coRouter { | ||
(accept(MediaType.APPLICATION_JSON) and "/internal/common/item").nest { | ||
POST("", itemHandler::createItem) | ||
} | ||
} | ||
} | ||
} |
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
This file was deleted.
Oops, something went wrong.
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,9 @@ | ||
### 아이템 생성 | ||
POST localhost:8083/common/backoffice/item | ||
Content-Type: application/json | ||
Service-Code:eyJubyI6MSwidGl0bGUiOiJ0aXRsZSJ9 | ||
|
||
{ | ||
"title": "title", | ||
"description": "description" | ||
} |