Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ plugins {
kotlin("jvm") version "1.6.10"
kotlin("plugin.spring") version "1.6.10"
kotlin("plugin.jpa") version "1.6.10"
kotlin("kapt") version "1.5.10"
}

group = "com.ssu.commerce"
Expand Down Expand Up @@ -43,6 +44,9 @@ dependencies {
annotationProcessor("org.springframework.boot:spring-boot-configuration-processor")
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.springframework.security:spring-security-test")

implementation("org.mapstruct:mapstruct:1.5.2.Final")
kapt("org.mapstruct:mapstruct-processor:1.5.2.Final")
}

tasks.withType<KotlinCompile> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package com.ssu.commerce.delivery

import com.ssu.commerce.core.configs.EnableSsuCommerceCore
import com.ssu.commerce.vault.config.EnableSsuCommerceVault
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication

@EnableSsuCommerceVault
@EnableSsuCommerceCore
@SpringBootApplication
class DeliveryApplication

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.ssu.commerce.delivery.configs

import com.ssu.commerce.core.configs.EnableSsuCommerceCore
import org.springframework.context.annotation.Configuration

@EnableSsuCommerceCore
@Configuration
class CoreConfiguration
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.ssu.commerce.delivery.configs

import com.ssu.commerce.vault.config.EnableSsuCommerceVault
import org.springframework.context.annotation.Configuration

@EnableSsuCommerceVault
@Configuration
class VaultConfiguration
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.ssu.commerce.delivery.controller

import com.ssu.commerce.core.response.PageResponse
import com.ssu.commerce.delivery.controller.model.DeliveryCreateModel
import com.ssu.commerce.delivery.controller.model.DeliveryResponseModel
import com.ssu.commerce.delivery.converter.DeliveryConverter
import com.ssu.commerce.delivery.service.DeliveryService
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.media.Content
import io.swagger.v3.oas.annotations.media.Schema
import io.swagger.v3.oas.annotations.tags.Tag
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
import javax.validation.Valid

@RestController
@RequestMapping("/deliveries")
@Tag(name = "배송 관련 API")
class DeliveryController(
private val deliveryService: DeliveryService,
private val deliveryConverter: DeliveryConverter
) {

@GetMapping
@Operation(summary = "배송 리스트 조회")
fun getList(@RequestParam page: Int, @RequestParam size: Int): PageResponse<DeliveryResponseModel> {
val result = deliveryService.getList(page, size)
return PageResponse(result.map(deliveryConverter::convert))
}

@GetMapping("/{deliveryId}")
@Operation(summary = "배송 상세 조회")
fun get(@PathVariable deliveryId: Long): DeliveryResponseModel {
val result = deliveryService.get(deliveryId)
return deliveryConverter.convert(result)
}

@PostMapping
@Operation(
summary = "배송 생성",
requestBody = io.swagger.v3.oas.annotations.parameters.RequestBody(
description = "배달 생성 객체",
required = true,
content = [Content(schema = Schema(implementation = DeliveryCreateModel::class))]
)
)
fun create(
@RequestBody @Valid
deliveryCreate: DeliveryCreateModel
) {
deliveryService.create(deliveryCreate)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.ssu.commerce.delivery.controller.model

import com.ssu.commerce.delivery.domain.enums.DeliveryFeeType
import com.ssu.commerce.delivery.domain.enums.DeliveryType
import java.math.BigDecimal
import java.time.LocalDateTime
import javax.validation.constraints.FutureOrPresent
import javax.validation.constraints.NotBlank
import javax.validation.constraints.NotNull
import javax.validation.constraints.Pattern

data class DeliveryCreateModel(
val transactionId: Long,
val orderBookId: Long,
val deliveryFeeType: DeliveryFeeType,
val baseFee: BigDecimal,
@NotNull
val sellerAccountId: Long,
@NotNull
val lenderAccountId: Long,
@NotBlank
val addressBase: String,
@NotBlank
val addressDetail: String,
val message: String? = null,
@Pattern(regexp = "\\d{5}")
@NotBlank
val zipcode: String,
@Pattern(regexp = "\\d{3}-\\d{4}-\\d{4}")
@NotBlank
val phoneNumber1: String,
@Pattern(regexp = "\\d{3}-\\d{4}-\\d{4}")
val phoneNumber2: String? = null,
var deliveryType: DeliveryType,
@FutureOrPresent
val deliveryStartedAt: LocalDateTime,
@FutureOrPresent
val deliveryArrivedAt: LocalDateTime
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.ssu.commerce.delivery.controller.model

import com.fasterxml.jackson.annotation.JsonFormat
import com.ssu.commerce.delivery.domain.enums.DeliveryFeeType
import com.ssu.commerce.delivery.domain.enums.DeliveryStatus
import com.ssu.commerce.delivery.domain.enums.DeliveryType
import com.ssu.commerce.delivery.utils.DateTimeUtils
import io.swagger.v3.oas.annotations.media.Schema
import java.math.BigDecimal
import java.time.LocalDateTime

@Schema(description = "배송 응답 모델")
data class DeliveryResponseModel(
@Schema(description = "배송 등록번호", defaultValue = "1")
val id: Long,
@Schema(description = "거래 등록 번호", example = "1")
val transactionId: Long,
@Schema(description = "주문한 책 번호", example = "1")
val orderBookId: Long,
@Schema(description = "배송비 유형", example = "FREE")
val deliveryFeeType: DeliveryFeeType,
@Schema(description = "배송비", example = "1000")
val baseFee: BigDecimal,
@Schema(description = "판매자 등록번호", example = "1")
val sellerAccountId: Long,
@Schema(description = "대여자 등록번호", example = "1")
val lenderAccountId: Long,
@Schema(description = "대여자 기본주소", example = "서울특별시 동작구 상도로 369")
val addressBase: String,
@Schema(description = "대여자 상세주소", example = "정보과학관 301호")
val addressDetail: String,
@Schema(description = "남기고 싶은 메세지", example = "도착 시 연락주세요")
val message: String? = null,
@Schema(description = "우편번호", example = "06978")
val zipcode: String,
@Schema(description = "대여자 연락 번호1", example = "010-1234-1234")
val phoneNumber1: String,
@Schema(description = "대여자 연락 번호2", example = "010-1234-1234")
val phoneNumber2: String? = null,
@Schema(description = "배송 유형", example = "DELIVERY")
var deliveryType: DeliveryType,
@Schema(description = "배송 상태", example = "DS00")
var deliveryStatus: DeliveryStatus,
@Schema(description = "배송 시작 일시", example = "2022-07-01 17:00:00")
val deliveryStartedAt: LocalDateTime,
@Schema(description = "배송 도착 일시", example = "2022-07-01 17:00:00")
val deliveryArrivedAt: LocalDateTime,
@Schema(description = "생성자", example = "TREE")
val createdWho: String,
@JsonFormat(pattern = DateTimeUtils.PATTERN)
@Schema(description = "생성일시", example = "2022-07-01 17:00:00")
val createdAt: LocalDateTime,
@Schema(description = "변경자", example = "TREE")
val updatedWho: String,
@JsonFormat(pattern = DateTimeUtils.PATTERN)
@Schema(description = "변경일시", example = "2022-07-01 17:00:00")
val updatedAt: LocalDateTime
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.ssu.commerce.delivery.converter

import com.ssu.commerce.delivery.controller.model.DeliveryCreateModel
import com.ssu.commerce.delivery.controller.model.DeliveryResponseModel
import com.ssu.commerce.delivery.domain.DeliveryInfoEntity
import com.ssu.commerce.delivery.vo.Delivery
import org.mapstruct.Mapper
import org.mapstruct.Mapping
import org.mapstruct.Mappings

@Mapper(componentModel = "spring")
interface DeliveryConverter {

@Mappings(
Mapping(target = "addressBase", source = "lenderAddress.addressBase"),
Mapping(target = "addressDetail", source = "lenderAddress.addressDetail"),
Mapping(target = "message", source = "lenderAddress.message"),
Mapping(target = "zipcode", source = "lenderAddress.zipcode"),
Mapping(target = "phoneNumber1", source = "lenderAddress.phoneNumber1"),
Mapping(target = "phoneNumber2", source = "lenderAddress.phoneNumber2"),
Mapping(target = "deliveryFeeType", source = "deliveryFee.deliveryFeeType"),
Mapping(target = "baseFee", source = "deliveryFee.baseFee"),
Mapping(target = "deliveryStatus", source = "status")
)
fun convert(deliveryInfoEntity: DeliveryInfoEntity): Delivery

@Mappings
fun convert(deliveryCreate: DeliveryCreateModel): Delivery

fun convert(delivery: Delivery): DeliveryResponseModel
}
20 changes: 20 additions & 0 deletions src/main/kotlin/com/ssu/commerce/delivery/domain/AddressInfo.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.ssu.commerce.delivery.domain

import javax.persistence.Column
import javax.persistence.Embeddable

@Embeddable
data class AddressInfo(
@Column(length = 255, nullable = false)
val addressBase: String,
@Column(length = 255, nullable = false)
val addressDetail: String,
@Column(length = 255)
val message: String? = null,
@Column(length = 10, nullable = false)
val zipcode: String,
@Column(length = 15, nullable = false)
val phoneNumber1: String,
@Column(length = 15)
val phoneNumber2: String? = null
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.ssu.commerce.delivery.domain

import com.ssu.commerce.delivery.domain.enums.DeliveryFeeType
import java.math.BigDecimal
import javax.persistence.Column
import javax.persistence.Embeddable
import javax.persistence.EnumType
import javax.persistence.Enumerated

@Embeddable
data class DeliveryFeeInfo(
@Column(length = 4, nullable = false)
@Enumerated(EnumType.STRING)
val deliveryFeeType: DeliveryFeeType,
@Column(nullable = false)
val baseFee: BigDecimal
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.ssu.commerce.delivery.domain

import com.ssu.commerce.core.jpa.BaseEntity
import com.ssu.commerce.delivery.domain.enums.DeliveryStatus
import com.ssu.commerce.delivery.domain.enums.DeliveryType
import java.time.LocalDateTime
import javax.persistence.Column
import javax.persistence.Embedded
import javax.persistence.Entity
import javax.persistence.EnumType
import javax.persistence.Enumerated
import javax.persistence.GeneratedValue
import javax.persistence.GenerationType
import javax.persistence.Id
import javax.persistence.Table

@Entity
@Table(name = "delivery_info")
data class DeliveryInfoEntity(
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(updatable = false)
val id: Long? = null,
@Column(nullable = false, updatable = false)
val transactionId: Long,
@Column(nullable = false, updatable = false)
val orderBookId: Long,
@Embedded
val deliveryFee: DeliveryFeeInfo,
@Column(nullable = false, updatable = false)
val sellerAccountId: Long,
@Column(nullable = false, updatable = false)
val lenderAccountId: Long,
@Embedded
var lenderAddress: AddressInfo,
@Column(nullable = false, updatable = false)
@Enumerated(EnumType.STRING)
var deliveryType: DeliveryType,
@Column(nullable = false, updatable = false)
@Enumerated(EnumType.STRING)
var status: DeliveryStatus,
@Column(nullable = false, updatable = false)
val deliveryStartedAt: LocalDateTime,
@Column(nullable = false, updatable = false)
val deliveryArrivedAt: LocalDateTime
) : BaseEntity()
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.ssu.commerce.delivery.domain

import com.ssu.commerce.core.exception.SsuCommerceException
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.repository.findByIdOrNull
import org.springframework.http.HttpStatus
import org.springframework.stereotype.Repository

@Repository
interface DeliveryInfoRepository : JpaRepository<DeliveryInfoEntity, Long> {
override fun getById(id: Long): DeliveryInfoEntity = findByIdOrNull(id)
?: throw SsuCommerceException(HttpStatus.BAD_REQUEST, "delivery-01", "존재 하지 않는 아이디입니다.")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.ssu.commerce.delivery.domain.enums

enum class DeliveryFeeType(val description: String) {
FREE("무료"), PAID("유료")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.ssu.commerce.delivery.domain.enums

enum class DeliveryStatus(val description: String) {
DS00("배송 요청"),
DS01("배송 준비"),
DS02("배송 중"),
DS03("배송 완료"),

DS04("반송 요청"),
DS05("반송 준비"),
DS06("반송 중"),
DS07("반송 완료"),

DS10("배송 취소"),
DS11("반송 취소")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.ssu.commerce.delivery.domain.enums

enum class DeliveryType(val description: String) {
DELIVERY("택배배송"), DIRECT("직배송");
}
Loading