Mapstruct
This commit is contained in:
parent
6c567ffa59
commit
09e8ed0503
@ -1,7 +1,16 @@
|
|||||||
|
val mapstructVersion: String by project
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
kotlin("kapt")
|
||||||
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation("org.springframework.boot:spring-boot-starter-webflux")
|
implementation("org.springframework.boot:spring-boot-starter-webflux")
|
||||||
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
|
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
|
||||||
|
|
||||||
implementation(project(":model"))
|
implementation(project(":model"))
|
||||||
implementation(project(":ports-incoming"))
|
implementation(project(":ports-incoming"))
|
||||||
|
|
||||||
|
implementation("org.mapstruct:mapstruct:$mapstructVersion")
|
||||||
|
kapt("org.mapstruct:mapstruct-processor:$mapstructVersion")
|
||||||
}
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
package pl.grondek.fitapp.adapter.rest
|
||||||
|
|
||||||
|
import org.mapstruct.Mapper
|
||||||
|
import pl.grondek.fitapp.model.Weight
|
||||||
|
|
||||||
|
@Mapper(componentModel = "spring")
|
||||||
|
interface RestMapper {
|
||||||
|
|
||||||
|
fun map(domain: Weight): WeightApiModel
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package pl.grondek.fitapp.adapter.rest
|
||||||
|
|
||||||
|
import java.math.BigDecimal
|
||||||
|
import java.time.LocalDateTime
|
||||||
|
|
||||||
|
data class WeightApiModel(
|
||||||
|
val weight: BigDecimal,
|
||||||
|
val date: LocalDateTime
|
||||||
|
)
|
@ -14,12 +14,14 @@ import reactor.core.publisher.Mono
|
|||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/weight")
|
@RequestMapping("/weight")
|
||||||
class WeightController(
|
class WeightController(
|
||||||
private val weightService: WeightService
|
private val weightService: WeightService,
|
||||||
|
private val mapper: RestMapper
|
||||||
) {
|
) {
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
fun listAll(): Flux<Weight>{
|
fun listAll(): Flux<WeightApiModel>{
|
||||||
return weightService.listAll()
|
return weightService.listAll()
|
||||||
|
.map(mapper::map)
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping
|
@PostMapping
|
||||||
|
@ -1,8 +1,16 @@
|
|||||||
dependencies {
|
val mapstructVersion: String by project
|
||||||
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
|
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
kotlin("kapt")
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
implementation("org.springframework.boot:spring-boot-starter-data-mongodb-reactive")
|
implementation("org.springframework.boot:spring-boot-starter-data-mongodb-reactive")
|
||||||
|
|
||||||
|
implementation("org.mapstruct:mapstruct:$mapstructVersion")
|
||||||
|
kapt("org.mapstruct:mapstruct-processor:$mapstructVersion")
|
||||||
|
|
||||||
implementation(project(":model"))
|
implementation(project(":model"))
|
||||||
implementation(project(":ports-repository"))
|
implementation(project(":ports-repository"))
|
||||||
|
|
||||||
}
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
package pl.grondek.fitapp.adapter.mongo
|
||||||
|
|
||||||
|
import org.mapstruct.Mapper
|
||||||
|
import org.mapstruct.Mapping
|
||||||
|
import org.springframework.stereotype.Component
|
||||||
|
import pl.grondek.fitapp.model.CreateWeightDTO
|
||||||
|
import pl.grondek.fitapp.model.Weight
|
||||||
|
import reactor.core.publisher.Mono
|
||||||
|
|
||||||
|
@Mapper(componentModel = "spring")
|
||||||
|
interface MongoMapper {
|
||||||
|
@Mapping(target = "id", ignore = true)
|
||||||
|
fun map(createWeightDTO: CreateWeightDTO): WeightRO
|
||||||
|
|
||||||
|
fun map(weightRO: WeightRO): Weight
|
||||||
|
}
|
@ -1,24 +0,0 @@
|
|||||||
package pl.grondek.fitapp.adapter.mongo
|
|
||||||
|
|
||||||
import org.springframework.stereotype.Component
|
|
||||||
import pl.grondek.fitapp.model.CreateWeightDTO
|
|
||||||
import pl.grondek.fitapp.model.Weight
|
|
||||||
import reactor.core.publisher.Mono
|
|
||||||
|
|
||||||
@Component
|
|
||||||
class WeightMapper {
|
|
||||||
fun map(createWeightDTO: CreateWeightDTO): WeightRO {
|
|
||||||
return WeightRO(
|
|
||||||
id = null,
|
|
||||||
weight = createWeightDTO.weight,
|
|
||||||
date = createWeightDTO.date
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun map(weightRO: WeightRO): Weight {
|
|
||||||
return Weight(
|
|
||||||
weight = weightRO.weight,
|
|
||||||
date = weightRO.date
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
@ -10,7 +10,7 @@ import reactor.core.publisher.Mono
|
|||||||
@Component
|
@Component
|
||||||
class WeightMongoRepository(
|
class WeightMongoRepository(
|
||||||
private val weightCrudRepository: WeightCrudRepository,
|
private val weightCrudRepository: WeightCrudRepository,
|
||||||
private val mapper: WeightMapper
|
private val mapper: MongoMapper
|
||||||
) : WeightRepository {
|
) : WeightRepository {
|
||||||
|
|
||||||
override fun add(createWeightDTO: CreateWeightDTO): Mono<Weight> {
|
override fun add(createWeightDTO: CreateWeightDTO): Mono<Weight> {
|
||||||
|
@ -4,6 +4,7 @@ plugins {
|
|||||||
id("org.springframework.boot") version "2.3.1.RELEASE"
|
id("org.springframework.boot") version "2.3.1.RELEASE"
|
||||||
id("io.spring.dependency-management") version "1.0.9.RELEASE"
|
id("io.spring.dependency-management") version "1.0.9.RELEASE"
|
||||||
kotlin("jvm") version "1.3.72"
|
kotlin("jvm") version "1.3.72"
|
||||||
|
kotlin("kapt") version "1.3.72"
|
||||||
kotlin("plugin.spring") version "1.3.72"
|
kotlin("plugin.spring") version "1.3.72"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,6 +33,16 @@ allprojects {
|
|||||||
dependencies{
|
dependencies{
|
||||||
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
|
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tasks.withType<KotlinCompile> {
|
||||||
|
kotlinOptions {
|
||||||
|
freeCompilerArgs = listOf(
|
||||||
|
"-Xjsr305=strict"
|
||||||
|
)
|
||||||
|
jvmTarget = "1.8"
|
||||||
|
javaParameters = true
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
@ -54,9 +65,12 @@ tasks.withType<Test> {
|
|||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.withType<KotlinCompile> {
|
//tasks.withType<KotlinCompile> {
|
||||||
kotlinOptions {
|
// kotlinOptions {
|
||||||
freeCompilerArgs = listOf("-Xjsr305=strict")
|
// freeCompilerArgs = listOf(
|
||||||
jvmTarget = "1.8"
|
// "-Xjsr305=strict",
|
||||||
}
|
// )
|
||||||
}
|
// jvmTarget = "1.8"
|
||||||
|
// javaParameters = true
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
1
gradle.properties
Normal file
1
gradle.properties
Normal file
@ -0,0 +1 @@
|
|||||||
|
mapstructVersion=1.4.0.Beta3
|
Loading…
Reference in New Issue
Block a user