From 3cdc8f442542e3211605160456b68e1a89fbb1a8 Mon Sep 17 00:00:00 2001 From: FyloZ Date: Wed, 10 Mar 2021 17:01:52 -0500 Subject: [PATCH] Ajout de la couleur et du lustre d'une recette. --- .../model/dto/RecipeEditorFormDto.java | 4 +- .../colorrecipesexplorer/model/Recipe.kt | 61 ++++++++++++++++--- .../service/RecipeService.kt | 12 ++-- 3 files changed, 64 insertions(+), 13 deletions(-) diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/model/dto/RecipeEditorFormDto.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/model/dto/RecipeEditorFormDto.java index 74a05e5..90e617d 100644 --- a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/model/dto/RecipeEditorFormDto.java +++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/model/dto/RecipeEditorFormDto.java @@ -29,11 +29,11 @@ public class RecipeEditorFormDto { private List step; public Recipe getRecipe() { - return new Recipe(id, name, company, description, sample, approbationDate, remark, note); + return new Recipe(id, name, company, description, "ffffff", (byte) 0, sample, approbationDate, remark, note); } public Recipe update(Recipe original) { - return new Recipe(original.getId(), name, company, description, sample, approbationDate, remark, note); + return new Recipe(original.getId(), name, company, description, "ffffff", (byte) 0, sample, approbationDate, remark, note); } } diff --git a/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/model/Recipe.kt b/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/model/Recipe.kt index 3180f4e..e11db17 100644 --- a/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/model/Recipe.kt +++ b/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/model/Recipe.kt @@ -6,13 +6,14 @@ import dev.fyloz.trial.colorrecipesexplorer.model.validation.NullOrSize import java.time.LocalDate import java.util.* import javax.persistence.* -import javax.validation.constraints.Min -import javax.validation.constraints.NotBlank -import javax.validation.constraints.NotNull +import javax.validation.constraints.* private const val RECIPE_ID_NULL_MESSAGE = "Un identifiant est requis" private const val RECIPE_NAME_NULL_MESSAGE = "Un nom est requis" private const val RECIPE_DESCRIPTION_NULL_MESSAGE = "Une description est requise" +private const val RECIPE_COLOR_NULL_MESSAGE = "Une couleur est requise" +private const val RECIPE_GLOSS_NULL_MESSAGE = "Le lustre de la couleur est requis" +private const val RECIPE_GLOSS_OUTSIDE_RANGE_MESSAGE = "Le lustre doit être entre 0 et 100" private const val RECIPE_SAMPLE_NULL_MESSAGE = "Un numéro d'échantillon est requis" private const val RECIPE_SAMPLE_TOO_SMALL_MESSAGE = "Le numéro d'échantillon doit être supérieur ou égal à 0" private const val RECIPE_COMPANY_NULL_MESSAGE = "Une bannière est requise" @@ -29,6 +30,12 @@ data class Recipe( val description: String, + /** The color produced by the recipe. The string should be formatted as a hexadecimal color without the sharp (#). */ + val color: String, + + /** The gloss of the color in percents. (0-100) */ + val gloss: Byte, + val sample: Int?, @Column(name = "approbation_date") @@ -54,6 +61,8 @@ data class Recipe( null, "name", "description", + "#ffffff", + 0, 0, null, "remark", @@ -68,11 +77,26 @@ data class Recipe( name: String, company: Company, description: String, + color: String, + gloss: Byte, sample: Int, approbationDate: LocalDate?, remark: String, note: String - ) : this(id, name, description, sample, approbationDate, remark, note, company, mutableListOf(), mutableListOf()) + ) : this( + id, + name, + description, + color, + gloss, + sample, + approbationDate, + remark, + note, + company, + mutableListOf(), + mutableListOf() + ) val mixesSortedById: Collection @JsonIgnore @@ -106,6 +130,15 @@ open class RecipeSaveDto( @field:NotBlank(message = RECIPE_DESCRIPTION_NULL_MESSAGE) val description: String, + @field:NotBlank(message = RECIPE_COLOR_NULL_MESSAGE) + @field:Pattern(regexp = "^#([0-9a-f]{6})$") + val color: String, + + @field:NotNull(message = RECIPE_GLOSS_NULL_MESSAGE) + @field:Min(value = 0, message = RECIPE_GLOSS_OUTSIDE_RANGE_MESSAGE) + @field:Max(value = 100, message = RECIPE_GLOSS_OUTSIDE_RANGE_MESSAGE) + val gloss: Byte, + @field:Min(value = 0, message = RECIPE_SAMPLE_TOO_SMALL_MESSAGE) val sample: Int?, @@ -136,6 +169,14 @@ open class RecipeUpdateDto( @field:NullOrNotBlank(message = RECIPE_DESCRIPTION_NULL_MESSAGE) val description: String?, + @field:NullOrNotBlank(message = RECIPE_COLOR_NULL_MESSAGE) + @field:Pattern(regexp = "^#([0-9a-f]{6})$") + val color: String?, + + @field:Min(value = 0, message = RECIPE_GLOSS_OUTSIDE_RANGE_MESSAGE) + @field:Max(value = 100, message = RECIPE_GLOSS_OUTSIDE_RANGE_MESSAGE) + val gloss: Byte?, + @field:NullOrSize(min = 0, message = RECIPE_SAMPLE_TOO_SMALL_MESSAGE) val sample: Int?, @@ -151,6 +192,8 @@ fun recipe( id: Long? = null, name: String = "name", description: String = "description", + color: String = "ffffff", + gloss: Byte = 0, sample: Int? = -1, approbationDate: LocalDate? = LocalDate.MIN, remark: String = "remark", @@ -159,7 +202,7 @@ fun recipe( mixes: MutableCollection = mutableListOf(), steps: MutableCollection = mutableListOf(), op: Recipe.() -> Unit = {} -) = Recipe(id, name, description, sample, approbationDate, remark, note, company, mixes, steps).apply(op) +) = Recipe(id, name, description, color, gloss, sample, approbationDate, remark, note, company, mixes, steps).apply(op) fun recipePublicDataDto( id: Long = 0L, @@ -171,20 +214,24 @@ fun recipePublicDataDto( fun recipeSaveDto( name: String = "name", description: String = "description", + color: String = "ffffff", + gloss: Byte = 0, sample: Int? = -1, approbationDate: LocalDate? = LocalDate.MIN, remark: String = "remark", companyId: Long = 0L, op: RecipeSaveDto.() -> Unit = {} -) = RecipeSaveDto(name, description, sample, approbationDate, remark, companyId).apply(op) +) = RecipeSaveDto(name, description, color, gloss, sample, approbationDate, remark, companyId).apply(op) fun recipeUpdateDto( id: Long = 0L, name: String? = "name", description: String? = "description", + color: String? = "ffffff", + gloss: Byte? = 0, sample: Int? = -1, approbationDate: LocalDate? = LocalDate.MIN, remark: String? = "remark", steps: List? = listOf(), op: RecipeUpdateDto.() -> Unit = {} -) = RecipeUpdateDto(id, name, description, sample, approbationDate, remark, steps).apply(op) +) = RecipeUpdateDto(id, name, description, color, gloss, sample, approbationDate, remark, steps).apply(op) diff --git a/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/RecipeService.kt b/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/RecipeService.kt index 0b05c70..3190407 100644 --- a/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/RecipeService.kt +++ b/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/RecipeService.kt @@ -46,6 +46,8 @@ class RecipeServiceImpl( recipe( name = name, description = description, + color = color, + gloss = gloss, sample = sample, approbationDate = approbationDate, remark = remark ?: "", @@ -61,11 +63,13 @@ class RecipeServiceImpl( return update(with(entity) { recipe( id = id, - name = name.or(persistedRecipe.name), - description = description.or(persistedRecipe.description), - sample = if (sample != null && sample >= 0) sample else persistedRecipe.sample, + name = name or persistedRecipe.name, + description = description or persistedRecipe.description, + color = color or persistedRecipe.color, + gloss = gloss ?: persistedRecipe.gloss, + sample = sample ?: persistedRecipe.sample, approbationDate = approbationDate ?: persistedRecipe.approbationDate, - remark = remark.or(persistedRecipe.remark), + remark = remark or persistedRecipe.remark, note = persistedRecipe.note, company = persistedRecipe.company, mixes = persistedRecipe.mixes,