Ajout des endpoints GET et DELETE pour les mélanges
This commit is contained in:
parent
41110237f5
commit
8fce20f978
|
@ -4,8 +4,10 @@ import dev.fyloz.trial.colorrecipesexplorer.model.*
|
|||
import dev.fyloz.trial.colorrecipesexplorer.service.MixService
|
||||
import dev.fyloz.trial.colorrecipesexplorer.service.RecipeService
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.web.bind.annotation.*
|
||||
import java.net.URI
|
||||
import org.springframework.web.bind.annotation.PutMapping
|
||||
import org.springframework.web.bind.annotation.RequestBody
|
||||
import org.springframework.web.bind.annotation.RequestMapping
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
import javax.validation.Valid
|
||||
|
||||
|
||||
|
@ -28,20 +30,5 @@ class RecipeController(recipeService: RecipeService) :
|
|||
|
||||
@RestController
|
||||
@RequestMapping(MIX_CONTROLLER_PATH)
|
||||
class MixController(val mixService: MixService) {
|
||||
@PostMapping
|
||||
fun save(@Valid @RequestBody entity: MixSaveDto): ResponseEntity<Mix> {
|
||||
val saved = mixService.save(entity)
|
||||
return ResponseEntity
|
||||
.created(URI("$MIX_CONTROLLER_PATH/${saved.id}"))
|
||||
.body(saved)
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
fun update(@Valid @RequestBody entity: MixUpdateDto): ResponseEntity<Void> {
|
||||
mixService.update(entity)
|
||||
return ResponseEntity
|
||||
.noContent()
|
||||
.build()
|
||||
}
|
||||
}
|
||||
class MixController(val mixService: MixService) :
|
||||
AbstractModelRestApiController<Mix, MixSaveDto, MixUpdateDto, MixService>(mixService, MIX_CONTROLLER_PATH)
|
||||
|
|
|
@ -5,7 +5,7 @@ import dev.fyloz.trial.colorrecipesexplorer.model.Mix
|
|||
import dev.fyloz.trial.colorrecipesexplorer.model.MixMaterial
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.mixMaterial
|
||||
import dev.fyloz.trial.colorrecipesexplorer.repository.MixMaterialRepository
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.context.annotation.Lazy
|
||||
import org.springframework.stereotype.Service
|
||||
|
||||
interface MixMaterialService : ModelService<MixMaterial, MixMaterialRepository> {
|
||||
|
@ -20,13 +20,13 @@ interface MixMaterialService : ModelService<MixMaterial, MixMaterialRepository>
|
|||
}
|
||||
|
||||
@Service
|
||||
class MixMaterialServiceImpl(mixMaterialRepository: MixMaterialRepository) :
|
||||
AbstractModelService<MixMaterial, MixMaterialRepository>(mixMaterialRepository), MixMaterialService {
|
||||
@Autowired
|
||||
lateinit var materialService: MaterialService
|
||||
|
||||
class MixMaterialServiceImpl(
|
||||
mixMaterialRepository: MixMaterialRepository,
|
||||
@Lazy val materialService: MaterialService
|
||||
) : AbstractModelService<MixMaterial, MixMaterialRepository>(mixMaterialRepository), MixMaterialService {
|
||||
override fun existsByMaterial(material: Material): Boolean = repository.existsByMaterial(material)
|
||||
override fun createFromMap(mix: Mix, map: Map<Long, Float>): Collection<MixMaterial> = map.map { createFromPair(mix, it.toPair()) }
|
||||
override fun createFromMap(mix: Mix, map: Map<Long, Float>): Collection<MixMaterial> =
|
||||
map.map { createFromPair(mix, it.toPair()) }
|
||||
|
||||
override fun createFromPair(mix: Mix, pair: Pair<Long, Float>): MixMaterial {
|
||||
val material = materialService.getById(pair.first)
|
||||
|
|
|
@ -21,7 +21,7 @@ interface MixService : ExternalModelService<Mix, MixSaveDto, MixUpdateDto, MixRe
|
|||
class MixServiceImpl(
|
||||
mixRepository: MixRepository,
|
||||
@Lazy val recipeService: RecipeService,
|
||||
val materialTypeService: MaterialTypeService,
|
||||
@Lazy val materialTypeService: MaterialTypeService,
|
||||
val mixMaterialService: MixMaterialService,
|
||||
val mixTypeService: MixTypeService
|
||||
) : AbstractModelService<Mix, MixRepository>(mixRepository),
|
||||
|
|
|
@ -21,7 +21,7 @@ interface MixTypeService : NamedModelService<MixType, MixTypeRepository> {
|
|||
@Service
|
||||
class MixTypeServiceImpl(
|
||||
mixTypeRepository: MixTypeRepository,
|
||||
val materialService: MaterialService,
|
||||
@Lazy val materialService: MaterialService,
|
||||
@Lazy val mixService: MixService
|
||||
) :
|
||||
AbstractNamedModelService<MixType, MixTypeRepository>(mixTypeRepository), MixTypeService {
|
||||
|
|
|
@ -15,7 +15,8 @@ import kotlin.test.assertTrue
|
|||
|
||||
class MixMaterialServiceTest : AbstractModelServiceTest<MixMaterial, MixMaterialService, MixMaterialRepository>() {
|
||||
override val repository: MixMaterialRepository = mock()
|
||||
override val service: MixMaterialService = spy(MixMaterialServiceImpl(repository))
|
||||
private val materialService: MaterialService = mock()
|
||||
override val service: MixMaterialService = spy(MixMaterialServiceImpl(repository, materialService))
|
||||
|
||||
private val material: Material = material(id = 0L)
|
||||
override val entity: MixMaterial = mixMaterial(id = 0L, material = material)
|
||||
|
|
Loading…
Reference in New Issue