Hexagon + some implementation
This commit is contained in:
parent
090dc3ba92
commit
6c567ffa59
7
adapter-incoming-rest/build.gradle.kts
Normal file
7
adapter-incoming-rest/build.gradle.kts
Normal file
@ -0,0 +1,7 @@
|
||||
dependencies {
|
||||
implementation("org.springframework.boot:spring-boot-starter-webflux")
|
||||
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
|
||||
|
||||
implementation(project(":model"))
|
||||
implementation(project(":ports-incoming"))
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package pl.grondek.fitapp.adapter.rest
|
||||
|
||||
import org.springframework.web.bind.annotation.GetMapping
|
||||
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.RestController
|
||||
import pl.grondek.fitapp.model.CreateWeightDTO
|
||||
import pl.grondek.fitapp.model.Weight
|
||||
import pl.grondek.fitapp.port.incoming.WeightService
|
||||
import reactor.core.publisher.Flux
|
||||
import reactor.core.publisher.Mono
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/weight")
|
||||
class WeightController(
|
||||
private val weightService: WeightService
|
||||
) {
|
||||
|
||||
@GetMapping
|
||||
fun listAll(): Flux<Weight>{
|
||||
return weightService.listAll()
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
fun save(@RequestBody createWeightDTO: CreateWeightDTO): Mono<Weight> {
|
||||
return weightService.add(createWeightDTO)
|
||||
}
|
||||
}
|
8
adapter-repository-mongodb/build.gradle.kts
Normal file
8
adapter-repository-mongodb/build.gradle.kts
Normal file
@ -0,0 +1,8 @@
|
||||
dependencies {
|
||||
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
|
||||
|
||||
implementation("org.springframework.boot:spring-boot-starter-data-mongodb-reactive")
|
||||
|
||||
implementation(project(":model"))
|
||||
implementation(project(":ports-repository"))
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
package pl.grondek.fitapp.adapter.mongo
|
||||
|
||||
import org.springframework.data.repository.reactive.ReactiveCrudRepository
|
||||
|
||||
interface WeightCrudRepository : ReactiveCrudRepository<WeightRO, Int> {
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
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
|
||||
)
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package pl.grondek.fitapp.adapter.mongo
|
||||
|
||||
import org.springframework.stereotype.Component
|
||||
import pl.grondek.fitapp.model.CreateWeightDTO
|
||||
import pl.grondek.fitapp.model.Weight
|
||||
import pl.grondek.fitapp.repository.WeightRepository
|
||||
import reactor.core.publisher.Flux
|
||||
import reactor.core.publisher.Mono
|
||||
|
||||
@Component
|
||||
class WeightMongoRepository(
|
||||
private val weightCrudRepository: WeightCrudRepository,
|
||||
private val mapper: WeightMapper
|
||||
) : WeightRepository {
|
||||
|
||||
override fun add(createWeightDTO: CreateWeightDTO): Mono<Weight> {
|
||||
val entity = mapper.map(createWeightDTO)
|
||||
val savedMono = weightCrudRepository.save(entity)
|
||||
return savedMono.map(mapper::map)
|
||||
}
|
||||
|
||||
override fun listAll(): Flux<Weight> {
|
||||
return weightCrudRepository.findAll()
|
||||
.map(mapper::map)
|
||||
}
|
||||
|
||||
override fun getLatest(): Mono<Weight> {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun getPrevious(): Mono<Weight> {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package pl.grondek.fitapp.adapter.mongo
|
||||
|
||||
import org.springframework.data.annotation.Id
|
||||
import java.math.BigDecimal
|
||||
import java.time.LocalDateTime
|
||||
|
||||
data class WeightRO(
|
||||
@field:Id
|
||||
val id: String?,
|
||||
|
||||
val weight: BigDecimal,
|
||||
|
||||
val date: LocalDateTime
|
||||
)
|
@ -11,17 +11,38 @@ group = "pl.grondek"
|
||||
version = "0.0.1-SNAPSHOT"
|
||||
java.sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
allprojects {
|
||||
apply{
|
||||
plugin("io.spring.dependency-management")
|
||||
}
|
||||
apply{
|
||||
plugin("org.jetbrains.kotlin.jvm")
|
||||
}
|
||||
repositories {
|
||||
mavenCentral()
|
||||
mavenLocal()
|
||||
}
|
||||
|
||||
dependencyManagement {
|
||||
imports {
|
||||
mavenBom("org.springframework.boot:spring-boot-dependencies:2.3.1.RELEASE")
|
||||
}
|
||||
}
|
||||
|
||||
dependencies{
|
||||
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("org.springframework.boot:spring-boot-starter-data-mongodb-reactive")
|
||||
implementation("org.springframework.boot:spring-boot-starter-webflux")
|
||||
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
|
||||
implementation("io.projectreactor.kotlin:reactor-kotlin-extensions")
|
||||
implementation(project(":model"))
|
||||
implementation(project(":core"))
|
||||
implementation(project(":ports-repository"))
|
||||
implementation(project(":adapter-repository-mongodb"))
|
||||
implementation(project(":adapter-incoming-rest"))
|
||||
|
||||
implementation("org.springframework.boot:spring-boot-starter")
|
||||
implementation("org.jetbrains.kotlin:kotlin-reflect")
|
||||
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactor")
|
||||
testImplementation("org.springframework.boot:spring-boot-starter-test") {
|
||||
exclude(group = "org.junit.vintage", module = "junit-vintage-engine")
|
||||
|
7
core/build.gradle.kts
Normal file
7
core/build.gradle.kts
Normal file
@ -0,0 +1,7 @@
|
||||
dependencies {
|
||||
implementation(project(":ports-incoming"))
|
||||
implementation(project(":model"))
|
||||
implementation(project(":ports-repository"))
|
||||
|
||||
api ("org.springframework:spring-context")
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package pl.grondek.fitapp.core
|
||||
|
||||
import org.springframework.stereotype.Service
|
||||
import pl.grondek.fitapp.model.CreateWeightDTO
|
||||
import pl.grondek.fitapp.model.Weight
|
||||
import pl.grondek.fitapp.port.incoming.WeightService
|
||||
import pl.grondek.fitapp.repository.WeightRepository
|
||||
import reactor.core.publisher.Flux
|
||||
import reactor.core.publisher.Mono
|
||||
|
||||
@Service
|
||||
class WeightsServiceImpl(
|
||||
private val weightRepository: WeightRepository
|
||||
):WeightService {
|
||||
override fun add(createWeightDTO: CreateWeightDTO): Mono<Weight> {
|
||||
return weightRepository.add(createWeightDTO)
|
||||
}
|
||||
|
||||
override fun listAll(): Flux<Weight> {
|
||||
return weightRepository.listAll()
|
||||
}
|
||||
}
|
0
model/build.gradle.kts
Normal file
0
model/build.gradle.kts
Normal file
@ -0,0 +1,9 @@
|
||||
package pl.grondek.fitapp.model
|
||||
|
||||
import java.math.BigDecimal
|
||||
import java.time.LocalDateTime
|
||||
|
||||
data class CreateWeightDTO(
|
||||
val weight: BigDecimal,
|
||||
val date: LocalDateTime
|
||||
)
|
9
model/src/main/kotlin/pl/grondek/fitapp/model/Weight.kt
Normal file
9
model/src/main/kotlin/pl/grondek/fitapp/model/Weight.kt
Normal file
@ -0,0 +1,9 @@
|
||||
package pl.grondek.fitapp.model
|
||||
|
||||
import java.math.BigDecimal
|
||||
import java.time.LocalDateTime
|
||||
|
||||
data class Weight (
|
||||
val weight: BigDecimal,
|
||||
val date: LocalDateTime
|
||||
)
|
5
ports-incoming/build.gradle.kts
Normal file
5
ports-incoming/build.gradle.kts
Normal file
@ -0,0 +1,5 @@
|
||||
dependencies {
|
||||
api("io.projectreactor:reactor-core")
|
||||
|
||||
implementation(project(":model"))
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package pl.grondek.fitapp.port.incoming
|
||||
|
||||
import pl.grondek.fitapp.model.CreateWeightDTO
|
||||
import pl.grondek.fitapp.model.Weight
|
||||
import reactor.core.publisher.Flux
|
||||
import reactor.core.publisher.Mono
|
||||
|
||||
interface WeightService {
|
||||
fun add(createWeightDTO: CreateWeightDTO): Mono<Weight>
|
||||
|
||||
fun listAll(): Flux<Weight>
|
||||
|
||||
}
|
5
ports-repository/build.gradle.kts
Normal file
5
ports-repository/build.gradle.kts
Normal file
@ -0,0 +1,5 @@
|
||||
dependencies {
|
||||
api("io.projectreactor:reactor-core")
|
||||
|
||||
implementation(project(":model"))
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package pl.grondek.fitapp.repository
|
||||
|
||||
import pl.grondek.fitapp.model.CreateWeightDTO
|
||||
import pl.grondek.fitapp.model.Weight
|
||||
import reactor.core.publisher.Flux
|
||||
import reactor.core.publisher.Mono
|
||||
|
||||
interface WeightRepository {
|
||||
|
||||
fun add(createWeightDTO: CreateWeightDTO): Mono<Weight>
|
||||
|
||||
fun listAll(): Flux<Weight>
|
||||
|
||||
fun getLatest(): Mono<Weight>
|
||||
|
||||
fun getPrevious(): Mono<Weight>
|
||||
}
|
@ -1 +1,8 @@
|
||||
rootProject.name = "fitapp"
|
||||
|
||||
include("model")
|
||||
include("core")
|
||||
include("ports-repository")
|
||||
include("ports-incoming")
|
||||
include("adapter-repository-mongodb")
|
||||
include("adapter-incoming-rest")
|
Loading…
Reference in New Issue
Block a user