-
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 #77 from TeamMiso/feat/recyclables-create
๐ :: ์ฌํ์ฉํ ๋ฐฉ๋ฒ ๊ธ ์์ฑํ๊ธฐ API ๊ตฌํ
- Loading branch information
Showing
29 changed files
with
276 additions
and
24 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
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
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
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
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
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
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
26 changes: 26 additions & 0 deletions
26
src/main/kotlin/andreas311/miso/domain/recyclables/adapter/input/RecyclablesAdapter.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,26 @@ | ||
package andreas311.miso.domain.recyclables.adapter.input | ||
|
||
import andreas311.miso.common.annotation.RequestController | ||
import andreas311.miso.domain.recyclables.adapter.input.data.CreateRecyclablesRequest | ||
import andreas311.miso.domain.recyclables.adapter.input.mapper.RecyclablesDataMapper | ||
import andreas311.miso.domain.recyclables.application.port.input.CreateRecyclablesUseCase | ||
import org.springframework.http.HttpStatus | ||
import org.springframework.http.ResponseEntity | ||
import org.springframework.web.bind.annotation.PostMapping | ||
import org.springframework.web.bind.annotation.RequestPart | ||
import org.springframework.web.multipart.MultipartFile | ||
import javax.validation.Valid | ||
|
||
@RequestController("/recyclables") | ||
class RecyclablesAdapter( | ||
private val recyclablesDataMapper: RecyclablesDataMapper, | ||
private val createRecyclablesUseCase: CreateRecyclablesUseCase | ||
) { | ||
@PostMapping | ||
fun execute( | ||
@RequestPart(value = "file") multipartFile: MultipartFile?, | ||
@RequestPart(value = "recyclables") @Valid createRecyclablesRequest: CreateRecyclablesRequest | ||
): ResponseEntity<Void> = | ||
createRecyclablesUseCase.execute(recyclablesDataMapper toDto createRecyclablesRequest, multipartFile) | ||
.let { ResponseEntity.status(HttpStatus.CREATED).build() } | ||
} |
21 changes: 21 additions & 0 deletions
21
.../kotlin/andreas311/miso/domain/recyclables/adapter/input/data/CreateRecyclablesRequest.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 andreas311.miso.domain.recyclables.adapter.input.data | ||
|
||
import andreas311.miso.domain.recyclables.domain.RecyclablesType | ||
import javax.validation.constraints.NotNull | ||
|
||
data class CreateRecyclablesRequest( | ||
@field:NotNull | ||
val title: String, | ||
@field:NotNull | ||
val subTitle: String, | ||
@field:NotNull | ||
val recycleMethod: String, | ||
@field:NotNull | ||
val recycleTip: String, | ||
@field:NotNull | ||
val recycleCaution: String, | ||
@field:NotNull | ||
val recyclablesType: RecyclablesType, | ||
@field:NotNull | ||
val recycleMark: String | ||
) |
19 changes: 19 additions & 0 deletions
19
...n/kotlin/andreas311/miso/domain/recyclables/adapter/input/mapper/RecyclablesDataMapper.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,19 @@ | ||
package andreas311.miso.domain.recyclables.adapter.input.mapper | ||
|
||
import andreas311.miso.domain.recyclables.adapter.input.data.CreateRecyclablesRequest | ||
import andreas311.miso.domain.recyclables.application.port.input.dto.CreateRecyclablesDto | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class RecyclablesDataMapper { | ||
infix fun toDto(createRecyclablesRequest: CreateRecyclablesRequest): CreateRecyclablesDto = | ||
CreateRecyclablesDto( | ||
title = createRecyclablesRequest.title, | ||
subTitle = createRecyclablesRequest.subTitle, | ||
recycleMethod = createRecyclablesRequest.recycleMethod, | ||
recycleTip = createRecyclablesRequest.recycleTip, | ||
recycleCaution = createRecyclablesRequest.recycleCaution, | ||
recyclablesType = createRecyclablesRequest.recyclablesType, | ||
recycleMark = createRecyclablesRequest.recycleMark | ||
) | ||
} |
18 changes: 18 additions & 0 deletions
18
...iso/domain/recyclables/adapter/output/persistence/CommandRecyclablesPersistenceAdapter.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,18 @@ | ||
package andreas311.miso.domain.recyclables.adapter.output.persistence | ||
|
||
import andreas311.miso.domain.recyclables.adapter.output.persistence.mapper.RecyclablesMapper | ||
import andreas311.miso.domain.recyclables.adapter.output.persistence.repository.RecyclablesRepository | ||
import andreas311.miso.domain.recyclables.application.port.output.CommandRecyclablesPort | ||
import andreas311.miso.domain.recyclables.domain.Recyclables | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class CommandRecyclablesPersistenceAdapter( | ||
private val recyclablesMapper: RecyclablesMapper, | ||
private val recyclablesRepository: RecyclablesRepository | ||
) : CommandRecyclablesPort { | ||
override fun saveRecyclables(recyclables: Recyclables): Recyclables { | ||
val recyclablesEntity = recyclablesRepository.save(recyclablesMapper toEntity recyclables) | ||
return recyclablesMapper.toDomain(recyclablesEntity)!! | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...andreas311/miso/domain/recyclables/adapter/output/persistence/entity/RecyclablesEntity.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,38 @@ | ||
package andreas311.miso.domain.recyclables.adapter.output.persistence.entity | ||
|
||
import andreas311.miso.domain.recyclables.domain.RecyclablesType | ||
import javax.persistence.* | ||
|
||
@Entity | ||
@Table(name = "recyclables") | ||
data class RecyclablesEntity( | ||
@Id | ||
@Column(name = "recyclables_id") | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
val id: Long, | ||
|
||
@Column(name = "title", nullable = false) | ||
val title: String, | ||
|
||
@Column(name = "sub_title", nullable = false) | ||
val subTitle: String, | ||
|
||
@Column(name = "recycle_method", nullable = false, length = 5000) | ||
val recycleMethod: String, | ||
|
||
@Column(name = "recycle_tip", nullable = false, length = 5000) | ||
val recycleTip: String, | ||
|
||
@Column(name = "recycle_caution", nullable = false, length = 5000) | ||
val recycleCaution: String, | ||
|
||
@Column(name = "imageUrl", nullable = true) | ||
val imageUrl: String?, | ||
|
||
@Enumerated(EnumType.STRING) | ||
@Column(name = "recyclables_type", nullable = false) | ||
val recyclablesType: RecyclablesType, | ||
|
||
@Column(name = "recycle_mark", nullable = false) | ||
val recycleMark: String | ||
) |
36 changes: 36 additions & 0 deletions
36
...andreas311/miso/domain/recyclables/adapter/output/persistence/mapper/RecyclablesMapper.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 andreas311.miso.domain.recyclables.adapter.output.persistence.mapper | ||
|
||
import andreas311.miso.domain.recyclables.adapter.output.persistence.entity.RecyclablesEntity | ||
import andreas311.miso.domain.recyclables.domain.Recyclables | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class RecyclablesMapper { | ||
infix fun toEntity(domain: Recyclables): RecyclablesEntity = | ||
RecyclablesEntity( | ||
id = domain.id, | ||
title = domain.title, | ||
subTitle = domain.subTitle, | ||
recycleMethod = domain.recycleMethod, | ||
recycleTip = domain.recycleTip, | ||
recycleCaution = domain.recycleCaution, | ||
imageUrl = domain.imageUrl, | ||
recyclablesType = domain.recyclablesType, | ||
recycleMark = domain.recycleMark | ||
) | ||
|
||
infix fun toDomain(entity: RecyclablesEntity?): Recyclables? = | ||
entity?.let { | ||
Recyclables( | ||
id = entity.id, | ||
title = entity.title, | ||
subTitle = entity.subTitle, | ||
recycleMethod = entity.recycleMethod, | ||
recycleTip = entity.recycleTip, | ||
recycleCaution = entity.recycleCaution, | ||
imageUrl = entity.imageUrl, | ||
recyclablesType = entity.recyclablesType, | ||
recycleMark = entity.recycleMark | ||
) | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...11/miso/domain/recyclables/adapter/output/persistence/repository/RecyclablesRepository.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 andreas311.miso.domain.recyclables.adapter.output.persistence.repository | ||
|
||
import andreas311.miso.domain.recyclables.adapter.output.persistence.entity.RecyclablesEntity | ||
import org.springframework.data.repository.CrudRepository | ||
|
||
interface RecyclablesRepository : CrudRepository<RecyclablesEntity, Long> { | ||
} |
8 changes: 8 additions & 0 deletions
8
...lin/andreas311/miso/domain/recyclables/application/port/input/CreateRecyclablesUseCase.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 andreas311.miso.domain.recyclables.application.port.input | ||
|
||
import andreas311.miso.domain.recyclables.application.port.input.dto.CreateRecyclablesDto | ||
import org.springframework.web.multipart.MultipartFile | ||
|
||
interface CreateRecyclablesUseCase { | ||
fun execute(createRecyclablesDto: CreateRecyclablesDto, multipartFile: MultipartFile?) | ||
} |
13 changes: 13 additions & 0 deletions
13
...lin/andreas311/miso/domain/recyclables/application/port/input/dto/CreateRecyclablesDto.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,13 @@ | ||
package andreas311.miso.domain.recyclables.application.port.input.dto | ||
|
||
import andreas311.miso.domain.recyclables.domain.RecyclablesType | ||
|
||
data class CreateRecyclablesDto( | ||
val title: String, | ||
val subTitle: String, | ||
val recycleMethod: String, | ||
val recycleTip: String, | ||
val recycleCaution: String, | ||
val recyclablesType: RecyclablesType, | ||
val recycleMark: String | ||
) |
7 changes: 7 additions & 0 deletions
7
...tlin/andreas311/miso/domain/recyclables/application/port/output/CommandRecyclablesPort.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 andreas311.miso.domain.recyclables.application.port.output | ||
|
||
import andreas311.miso.domain.recyclables.domain.Recyclables | ||
|
||
interface CommandRecyclablesPort { | ||
fun saveRecyclables(recyclables: Recyclables): Recyclables | ||
} |
Oops, something went wrong.