-
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.
Merge pull request #3 from hyuksooon/feature/#1_item
Feature/#1 item
- Loading branch information
Showing
21 changed files
with
296 additions
and
62 deletions.
There are no files selected for viewing
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
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())) | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/kotlin/com/soon/common/application/ItemQueryService.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,17 @@ | ||
package com.soon.common.application | ||
|
||
import com.soon.common.application.model.ItemGetSummary | ||
import com.soon.common.domain.item.ItemRepository | ||
import org.springframework.data.repository.findByIdOrNull | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class ItemQueryService( | ||
private val itemRepository: ItemRepository, | ||
) { | ||
fun getItem(itemNo: Int): ItemGetSummary { | ||
return itemRepository.findByIdOrNull(itemNo)?.let { | ||
ItemGetSummary.of(it) | ||
} ?: throw IllegalArgumentException() | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
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,17 @@ | ||
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, | ||
val thumbnail: String, | ||
) { | ||
fun toCreateModel() = ItemCreateModel( | ||
serviceNo = serviceNo, | ||
title = title, | ||
description = description, | ||
thumbnail = thumbnail, | ||
) | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/kotlin/com/soon/common/application/model/ItemGetSummary.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.application.model | ||
|
||
import com.soon.common.domain.item.Item | ||
|
||
data class ItemGetSummary( | ||
val itemNo: Int, | ||
val serviceNo: Int, | ||
val title: String, | ||
val description: String, | ||
val thumbnail: String, | ||
) { | ||
companion object { | ||
fun of(item: Item) = ItemGetSummary( | ||
itemNo = item.no, | ||
serviceNo = item.serviceNo, | ||
title = item.title, | ||
description = item.description, | ||
thumbnail = item.thumbnail, | ||
) | ||
} | ||
} |
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
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,38 @@ | ||
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 = "thumbnail") | ||
val thumbnail: 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, | ||
thumbnail = createModel.thumbnail, | ||
) | ||
} | ||
} |
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> |
8 changes: 8 additions & 0 deletions
8
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,8 @@ | ||
package com.soon.common.domain.item.model | ||
|
||
data class ItemCreateModel( | ||
val serviceNo: Int, | ||
val title: String, | ||
val description: String, | ||
val thumbnail: String, | ||
) |
14 changes: 7 additions & 7 deletions
14
src/main/kotlin/com/soon/common/presentation/extension/MemberHeader.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 |
---|---|---|
@@ -1,14 +1,14 @@ | ||
package com.soon.member.presentation.extension | ||
package com.soon.common.presentation.extension | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty | ||
|
||
|
||
data class MemberHeader | ||
( | ||
@JsonProperty("no") | ||
val no: Int, | ||
@JsonProperty("name") | ||
val name: String, | ||
@JsonProperty("account") | ||
val account: String, | ||
@JsonProperty("no") | ||
val no: Int, | ||
@JsonProperty("name") | ||
val name: String, | ||
@JsonProperty("account") | ||
val account: String, | ||
) |
27 changes: 16 additions & 11 deletions
27
src/main/kotlin/com/soon/common/presentation/extension/RequestExtension.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 |
---|---|---|
@@ -1,19 +1,24 @@ | ||
package com.soon.member.presentation.extension | ||
package com.soon.common.presentation.extension | ||
|
||
import com.soon.common.domain.extension.decodeBase64ToDto | ||
import com.soon.common.presentation.extension.ServiceHeader | ||
import org.springframework.web.reactive.function.server.ServerRequest | ||
import org.springframework.web.reactive.function.server.queryParamOrNull | ||
|
||
fun ServerRequest.extractMemberCodeHeader() :MemberHeader{ | ||
fun ServerRequest.extractMemberCodeHeader(): MemberHeader { | ||
return headers().header("Member-Code").firstOrNull() | ||
?.let{ | ||
it.decodeBase64ToDto<MemberHeader>() | ||
}?:throw IllegalArgumentException() | ||
?.let { | ||
it.decodeBase64ToDto<MemberHeader>() | ||
} ?: throw IllegalArgumentException() | ||
} | ||
|
||
fun ServerRequest.extractServiceCodeHeader() :ServiceHeader{ | ||
fun ServerRequest.extractServiceCodeHeader(): ServiceHeader { | ||
return headers().header("Service-Code").firstOrNull() | ||
?.let{ | ||
it.decodeBase64ToDto<ServiceHeader>() | ||
}?:throw IllegalArgumentException() | ||
} | ||
?.let { | ||
it.decodeBase64ToDto<ServiceHeader>() | ||
} ?: throw IllegalArgumentException() | ||
} | ||
|
||
fun ServerRequest.intQueryParam(parameter: String): Int { | ||
return queryParamOrNull(parameter)?.toIntOrNull() | ||
?: throw IllegalArgumentException("Invalid or missing 'itemNo' query parameter") | ||
} |
33 changes: 33 additions & 0 deletions
33
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,33 @@ | ||
package com.soon.common.presentation.handler | ||
|
||
import com.soon.common.application.ItemCommandService | ||
import com.soon.common.application.ItemQueryService | ||
import com.soon.common.application.util.coroutines.ApplicationDispatchers | ||
import com.soon.common.presentation.extension.extractServiceCodeHeader | ||
import com.soon.common.presentation.extension.intQueryParam | ||
import com.soon.common.presentation.handler.model.ItemCreateRequest | ||
import com.soon.common.presentation.handler.model.ItemGetResponse | ||
import kotlinx.coroutines.withContext | ||
import org.springframework.stereotype.Service | ||
import org.springframework.web.reactive.function.server.* | ||
|
||
@Service | ||
class ItemHandler( | ||
private val itemCommandService: ItemCommandService, | ||
private val itemQueryService: ItemQueryService, | ||
) { | ||
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() | ||
} | ||
|
||
suspend fun getItem(request: ServerRequest): ServerResponse = withContext(ApplicationDispatchers.IO) { | ||
val itemNo = request.intQueryParam("itemNo") | ||
val summary = itemQueryService.getItem(itemNo) | ||
ServerResponse.ok().bodyValueAndAwait(ItemGetResponse.of(summary)) | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
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,20 @@ | ||
package com.soon.common.presentation.handler.model | ||
|
||
import com.soon.common.application.model.ItemCreateCommand | ||
import jakarta.validation.constraints.NotBlank | ||
|
||
data class ItemCreateRequest( | ||
@field:NotBlank | ||
val title: String, | ||
@field:NotBlank | ||
val description: String, | ||
@field:NotBlank | ||
val thumbnail: String, | ||
) { | ||
fun toCommand(serviceNo: Int) = ItemCreateCommand( | ||
serviceNo = serviceNo, | ||
title = title, | ||
description = description, | ||
thumbnail = thumbnail, | ||
) | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/kotlin/com/soon/common/presentation/handler/model/ItemGetResponse.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.handler.model | ||
|
||
import com.soon.common.application.model.ItemGetSummary | ||
|
||
data class ItemGetResponse( | ||
val itemNo: Int, | ||
val serviceNo: Int, | ||
val title: String, | ||
val description: String, | ||
val thumbnail: String, | ||
) { | ||
companion object { | ||
fun of(summary: ItemGetSummary) = ItemGetResponse( | ||
itemNo = summary.itemNo, | ||
serviceNo = summary.serviceNo, | ||
title = summary.title, | ||
description = summary.description, | ||
thumbnail = summary.thumbnail, | ||
) | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
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,22 @@ | ||
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 itemInternalRoute(): RouterFunction<ServerResponse> { | ||
return coRouter { | ||
(accept(MediaType.APPLICATION_JSON) and "/internal/common/item").nest { | ||
POST("", itemHandler::createItem) | ||
GET("", itemHandler::getItem) | ||
} | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/kotlin/com/soon/common/presentation/router/item/ItemRouter.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 ItemRouter(private val itemHandler: ItemHandler) { | ||
@Bean | ||
fun itemRoute(): RouterFunction<ServerResponse> { | ||
return coRouter { | ||
(accept(MediaType.APPLICATION_JSON) and "/common/item").nest { | ||
GET("", itemHandler::getItem) | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.