Commencement de la vérification de la position des étapes
This commit is contained in:
parent
211fdb1895
commit
c313888f30
|
@ -5,6 +5,7 @@ import dev.fyloz.colorrecipesexplorer.model.*
|
|||
import dev.fyloz.colorrecipesexplorer.model.validation.or
|
||||
import dev.fyloz.colorrecipesexplorer.repository.RecipeRepository
|
||||
import dev.fyloz.colorrecipesexplorer.service.files.FileService
|
||||
import dev.fyloz.colorrecipesexplorer.service.utils.setAll
|
||||
import org.springframework.context.annotation.Lazy
|
||||
import org.springframework.stereotype.Service
|
||||
import org.springframework.web.multipart.MultipartFile
|
||||
|
@ -73,22 +74,22 @@ class RecipeServiceImpl(
|
|||
remark = remark or persistedRecipe.remark,
|
||||
company = persistedRecipe.company,
|
||||
mixes = persistedRecipe.mixes,
|
||||
groupsInformation = updateGroupsInformationSteps(persistedRecipe, entity.steps)
|
||||
groupsInformation = updateGroupsInformation(persistedRecipe, entity)
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
private fun updateGroupsInformationSteps(recipe: Recipe, steps: Set<RecipeStepsDto>?): Set<RecipeGroupInformation> {
|
||||
if (steps == null) return recipe.groupsInformation
|
||||
private fun updateGroupsInformation(recipe: Recipe, updateDto: RecipeUpdateDto): Set<RecipeGroupInformation> {
|
||||
val steps = updateDto.steps ?: return recipe.groupsInformation
|
||||
|
||||
val updatedGroupsInformation = mutableSetOf<RecipeGroupInformation>()
|
||||
steps.forEach {
|
||||
with(recipe.groupInformationForGroup(it.groupId)) {
|
||||
updatedGroupsInformation.add(
|
||||
// Set steps for the existing RecipeGroupInformation or create a new one
|
||||
this?.apply {
|
||||
if (this.steps != null) {
|
||||
this.steps!!.clear()
|
||||
this.steps!!.addAll(it.steps)
|
||||
this.steps!!.setAll(it.steps)
|
||||
} else {
|
||||
this.steps = it.steps.toMutableSet()
|
||||
}
|
||||
|
|
|
@ -4,9 +4,27 @@ import dev.fyloz.colorrecipesexplorer.model.RecipeStep
|
|||
import dev.fyloz.colorrecipesexplorer.repository.RecipeStepRepository
|
||||
import org.springframework.stereotype.Service
|
||||
|
||||
interface RecipeStepService : ModelService<RecipeStep, RecipeStepRepository>
|
||||
interface RecipeStepService : ModelService<RecipeStep, RecipeStepRepository> {
|
||||
|
||||
/**
|
||||
* Validates if the given [steps] obey the following criteria:
|
||||
*
|
||||
* * The position of the steps is greater or equals to 1
|
||||
* * Each position is unique in the collection
|
||||
* * There is no gap between positions
|
||||
*/
|
||||
fun validateStepsCollection(steps: Collection<RecipeStep>): Boolean
|
||||
}
|
||||
|
||||
@Service
|
||||
class RecipeStepServiceImpl(recipeStepRepository: RecipeStepRepository) :
|
||||
AbstractModelService<RecipeStep, RecipeStepRepository>(recipeStepRepository),
|
||||
RecipeStepService
|
||||
RecipeStepService {
|
||||
// override fun validateStepsCollection(steps: Collection<RecipeStep>): Boolean {
|
||||
// val sortedSteps = steps.sortedBy { it.position }
|
||||
//
|
||||
// fun validateStepPosition(step: RecipeStep) =
|
||||
// step.position >= 1
|
||||
//
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -16,3 +16,9 @@ inline fun <T, R, reified E : Throwable> Iterable<T>.mapMayThrow(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Clears and fills the given [MutableCollection] with the given [elements]. */
|
||||
fun <T> MutableCollection<T>.setAll(elements: Collection<T>) {
|
||||
this.clear()
|
||||
this.addAll(elements)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue