Merge branch 'model-modifications' into 'master'
Model modifications See merge request color-recipes-explorer/backend!11
This commit is contained in:
commit
89fd34b645
|
@ -31,7 +31,7 @@ dependencies {
|
|||
implementation("org.apache.pdfbox:pdfbox:2.0.4")
|
||||
implementation("com.atlassian.commonmark:commonmark:0.13.1")
|
||||
implementation("commons-io:commons-io:2.6")
|
||||
implementation("dev.fyloz.colorrecipesexplorer:database-manager:1.0.1")
|
||||
implementation("dev.fyloz.colorrecipesexplorer:database-manager:1.1.0")
|
||||
|
||||
implementation("org.springframework.boot:spring-boot-starter-data-jpa:2.3.4.RELEASE")
|
||||
implementation("org.springframework.boot:spring-boot-starter-jdbc:2.3.4.RELEASE")
|
||||
|
|
|
@ -29,11 +29,11 @@ public class RecipeEditorFormDto {
|
|||
private List<String> 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ import org.springframework.context.annotation.Configuration
|
|||
import org.springframework.core.env.Environment
|
||||
import javax.sql.DataSource
|
||||
|
||||
const val SUPPORTED_DATABASE_VERSION = 2
|
||||
const val SUPPORTED_DATABASE_VERSION = 3
|
||||
const val ENV_VAR_ENABLE_DATABASE_UPDATE_NAME = "CRE_ENABLE_DB_UPDATE"
|
||||
val DATABASE_NAME_REGEX = Regex("(\\w+)$")
|
||||
|
||||
|
|
|
@ -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,7 +30,13 @@ data class Recipe(
|
|||
|
||||
val description: String,
|
||||
|
||||
val sample: Int,
|
||||
/** 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")
|
||||
val approbationDate: LocalDate?,
|
||||
|
@ -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<Mix>
|
||||
@JsonIgnore
|
||||
|
@ -106,9 +130,17 @@ open class RecipeSaveDto(
|
|||
@field:NotBlank(message = RECIPE_DESCRIPTION_NULL_MESSAGE)
|
||||
val description: String,
|
||||
|
||||
@field:NotNull(message = RECIPE_SAMPLE_NULL_MESSAGE)
|
||||
@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,
|
||||
val sample: Int?,
|
||||
|
||||
val approbationDate: LocalDate?,
|
||||
|
||||
|
@ -137,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?,
|
||||
|
||||
|
@ -145,24 +185,16 @@ open class RecipeUpdateDto(
|
|||
val remark: String?,
|
||||
|
||||
val steps: List<RecipeStep>?
|
||||
) : EntityDto<Recipe> {
|
||||
override fun toEntity(): Recipe = recipe(
|
||||
id,
|
||||
name = name ?: "name",
|
||||
description = description ?: "description",
|
||||
sample = sample ?: -1,
|
||||
approbationDate = approbationDate ?: LocalDate.MIN,
|
||||
remark = remark ?: "remark",
|
||||
steps = steps?.toMutableList() ?: mutableListOf()
|
||||
)
|
||||
}
|
||||
) : EntityDto<Recipe>
|
||||
|
||||
// ==== DSL ====
|
||||
fun recipe(
|
||||
id: Long? = null,
|
||||
name: String = "name",
|
||||
description: String = "description",
|
||||
sample: Int = -1,
|
||||
color: String = "ffffff",
|
||||
gloss: Byte = 0,
|
||||
sample: Int? = -1,
|
||||
approbationDate: LocalDate? = LocalDate.MIN,
|
||||
remark: String = "remark",
|
||||
note: String = "",
|
||||
|
@ -170,7 +202,7 @@ fun recipe(
|
|||
mixes: MutableCollection<Mix> = mutableListOf(),
|
||||
steps: MutableCollection<RecipeStep> = 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,
|
||||
|
@ -182,20 +214,24 @@ fun recipePublicDataDto(
|
|||
fun recipeSaveDto(
|
||||
name: String = "name",
|
||||
description: String = "description",
|
||||
sample: Int = -1,
|
||||
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",
|
||||
sample: Int = -1,
|
||||
name: String? = "name",
|
||||
description: String? = "description",
|
||||
color: String? = "ffffff",
|
||||
gloss: Byte? = 0,
|
||||
sample: Int? = -1,
|
||||
approbationDate: LocalDate? = LocalDate.MIN,
|
||||
remark: String? = "remark",
|
||||
steps: List<RecipeStep> = listOf(),
|
||||
steps: List<RecipeStep>? = 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)
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue