From 16f4a36693ff7afae286952da7d9686b13936c0c Mon Sep 17 00:00:00 2001 From: FyloZ Date: Tue, 9 Mar 2021 19:24:00 -0500 Subject: [PATCH 1/2] =?UTF-8?q?Ajout=20d'une=20v=C3=A9rification=20lors=20?= =?UTF-8?q?de=20la=20suppression=20d'une=20entit=C3=A9=20qui=20v=C3=A9rifi?= =?UTF-8?q?e=20si=20l'entit=C3=A9=20peut=20=C3=AAtre=20supprim=C3=A9e.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/EntityNotFoundException.kt | 22 --------- .../service/AbstractJavaNamedService.java | 2 +- .../service/AbstractJavaService.java | 4 +- .../service/model/CompanyJavaService.java | 2 +- .../service/model/MaterialJavaService.java | 2 +- .../model/MaterialTypeJavaService.java | 4 +- .../service/model/MixJavaService.java | 2 +- .../service/model/MixTypeJavaService.java | 4 +- .../thymeleaf/OthersController.java | 2 +- .../thymeleaf/RecipeExplorerController.java | 2 +- .../creators/CompanyCreatorController.java | 2 +- .../creators/MaterialCreatorController.java | 2 +- .../creators/MaterialCreatorController.kt | 2 +- .../MaterialTypeCreatorController.java | 2 +- .../creators/MixCreatorController.java | 4 +- .../editors/MaterialEditorController.java | 4 +- .../editors/MaterialTypeEditorController.java | 4 +- .../editors/MixEditorController.java | 4 +- .../editors/RecipeEditorController.java | 2 +- .../thymeleaf/files/ImageFilesController.java | 2 +- .../files/SimdutFilesController.java | 2 +- .../files/XlsExporterController.java | 2 +- .../removers/CompanyRemoverController.java | 2 +- .../removers/MaterialRemoverController.java | 2 +- .../MaterialTypeRemoverController.java | 2 +- .../removers/MixRemoverController.java | 2 +- .../removers/RecipeRemoverController.java | 2 +- .../config/WebSecurityConfig.kt | 2 +- .../exception/Exception.kt} | 20 +++----- .../exception/RestException.kt | 48 +++++++++++++++++-- .../repository/CompanyRepository.kt | 13 ++++- .../repository/MaterialRepository.kt | 12 +++++ .../repository/MaterialTypeRepository.kt | 11 +++++ .../repository/MixRepository.kt | 11 +++++ .../repository/MixTypeRepository.kt | 11 +++++ .../service/AccountService.kt | 6 +-- .../service/CompanyService.kt | 6 +++ .../service/MaterialService.kt | 6 +++ .../service/MaterialTypeService.kt | 11 ++--- .../service/MixService.kt | 6 +++ .../service/MixTypeService.kt | 10 +++- .../service/RecipeService.kt | 2 +- .../colorrecipesexplorer/service/Service.kt | 4 +- .../service/AbstractServiceTest.kt | 4 +- .../service/AccountsServiceTest.kt | 4 +- .../service/CompanyServiceTest.kt | 6 +++ .../service/MaterialServiceTest.kt | 9 +++- .../service/MaterialTypeServiceTest.kt | 12 ++--- .../service/MixServiceTest.kt | 6 +++ .../service/MixTypeServiceTest.kt | 12 +++-- .../service/RecipeServiceTest.kt | 2 +- 51 files changed, 217 insertions(+), 105 deletions(-) delete mode 100644 src/main/java/dev/fyloz/trial/colorrecipesexplorer/exception/model/EntityNotFoundException.kt rename src/main/{java/dev/fyloz/trial/colorrecipesexplorer/exception/model/EntityAlreadyExistsException.kt => kotlin/dev/fyloz/trial/colorrecipesexplorer/exception/Exception.kt} (53%) rename src/main/{java => kotlin}/dev/fyloz/trial/colorrecipesexplorer/exception/RestException.kt (57%) diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/exception/model/EntityNotFoundException.kt b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/exception/model/EntityNotFoundException.kt deleted file mode 100644 index e40eb45..0000000 --- a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/exception/model/EntityNotFoundException.kt +++ /dev/null @@ -1,22 +0,0 @@ -package dev.fyloz.trial.colorrecipesexplorer.exception.model - -import dev.fyloz.trial.colorrecipesexplorer.exception.RestException -import dev.fyloz.trial.colorrecipesexplorer.model.Model -import org.springframework.http.HttpStatus -import org.springframework.web.bind.annotation.ResponseStatus - -class EntityNotFoundException( - modelType: Class, - val identifierType: IdentifierType, - val requestedId: Any -) : ModelException(modelType) - -@ResponseStatus(HttpStatus.NOT_FOUND) -class EntityNotFoundRestException(val value: Any) : - RestException("An entity could not be found with the given identifier", HttpStatus.NOT_FOUND) { - - @Suppress("unused") - override fun buildBody(): RestExceptionBody = object : RestExceptionBody() { - val id = value - } -} diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/service/AbstractJavaNamedService.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/service/AbstractJavaNamedService.java index 182130d..363996c 100644 --- a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/service/AbstractJavaNamedService.java +++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/service/AbstractJavaNamedService.java @@ -1,6 +1,6 @@ package dev.fyloz.trial.colorrecipesexplorer.service; -import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundException; +import dev.fyloz.trial.colorrecipesexplorer.exception.EntityNotFoundException; import dev.fyloz.trial.colorrecipesexplorer.exception.model.ModelException; import dev.fyloz.trial.colorrecipesexplorer.model.NamedModel; import dev.fyloz.trial.colorrecipesexplorer.repository.NamedJpaRepository; diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/service/AbstractJavaService.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/service/AbstractJavaService.java index 8a8f1f6..51beda2 100644 --- a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/service/AbstractJavaService.java +++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/service/AbstractJavaService.java @@ -3,8 +3,8 @@ package dev.fyloz.trial.colorrecipesexplorer.service; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import dev.fyloz.trial.colorrecipesexplorer.config.Preferences; -import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityAlreadyExistsException; -import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundException; +import dev.fyloz.trial.colorrecipesexplorer.exception.EntityAlreadyExistsException; +import dev.fyloz.trial.colorrecipesexplorer.exception.EntityNotFoundException; import dev.fyloz.trial.colorrecipesexplorer.exception.model.ModelException; import dev.fyloz.trial.colorrecipesexplorer.exception.model.NullIdentifierException; import dev.fyloz.trial.colorrecipesexplorer.model.Model; diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/service/model/CompanyJavaService.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/service/model/CompanyJavaService.java index 71b2bcb..c88cf0f 100644 --- a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/service/model/CompanyJavaService.java +++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/service/model/CompanyJavaService.java @@ -1,6 +1,6 @@ package dev.fyloz.trial.colorrecipesexplorer.service.model; -import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityAlreadyExistsException; +import dev.fyloz.trial.colorrecipesexplorer.exception.EntityAlreadyExistsException; import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityLinkedException; import dev.fyloz.trial.colorrecipesexplorer.exception.model.ModelException; import dev.fyloz.trial.colorrecipesexplorer.model.Company; diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/service/model/MaterialJavaService.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/service/model/MaterialJavaService.java index 369bb22..482b2f0 100644 --- a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/service/model/MaterialJavaService.java +++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/service/model/MaterialJavaService.java @@ -1,6 +1,6 @@ package dev.fyloz.trial.colorrecipesexplorer.service.model; -import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityAlreadyExistsException; +import dev.fyloz.trial.colorrecipesexplorer.exception.EntityAlreadyExistsException; import dev.fyloz.trial.colorrecipesexplorer.exception.model.ModelException; import dev.fyloz.trial.colorrecipesexplorer.model.Material; import dev.fyloz.trial.colorrecipesexplorer.model.MaterialSaveDto; diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/service/model/MaterialTypeJavaService.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/service/model/MaterialTypeJavaService.java index 2477edc..0a93f52 100644 --- a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/service/model/MaterialTypeJavaService.java +++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/service/model/MaterialTypeJavaService.java @@ -2,8 +2,8 @@ package dev.fyloz.trial.colorrecipesexplorer.service.model; import dev.fyloz.trial.colorrecipesexplorer.exception.CannotDeleteDefaultMaterialTypeException; import dev.fyloz.trial.colorrecipesexplorer.exception.CannotEditDefaultMaterialTypeException; -import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityAlreadyExistsException; -import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundException; +import dev.fyloz.trial.colorrecipesexplorer.exception.EntityAlreadyExistsException; +import dev.fyloz.trial.colorrecipesexplorer.exception.EntityNotFoundException; import dev.fyloz.trial.colorrecipesexplorer.exception.model.ModelException; import dev.fyloz.trial.colorrecipesexplorer.model.MaterialType; import dev.fyloz.trial.colorrecipesexplorer.model.dto.MaterialTypeEditorDto; diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/service/model/MixJavaService.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/service/model/MixJavaService.java index 9e60e63..bb1ffb8 100644 --- a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/service/model/MixJavaService.java +++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/service/model/MixJavaService.java @@ -1,6 +1,6 @@ package dev.fyloz.trial.colorrecipesexplorer.service.model; -import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityAlreadyExistsException; +import dev.fyloz.trial.colorrecipesexplorer.exception.EntityAlreadyExistsException; import dev.fyloz.trial.colorrecipesexplorer.exception.model.ModelException; import dev.fyloz.trial.colorrecipesexplorer.model.*; import dev.fyloz.trial.colorrecipesexplorer.model.dto.MixFormDto; diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/service/model/MixTypeJavaService.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/service/model/MixTypeJavaService.java index 92b72ef..dffd318 100644 --- a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/service/model/MixTypeJavaService.java +++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/service/model/MixTypeJavaService.java @@ -1,7 +1,7 @@ package dev.fyloz.trial.colorrecipesexplorer.service.model; -import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityAlreadyExistsException; -import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundException; +import dev.fyloz.trial.colorrecipesexplorer.exception.EntityAlreadyExistsException; +import dev.fyloz.trial.colorrecipesexplorer.exception.EntityNotFoundException; import dev.fyloz.trial.colorrecipesexplorer.exception.model.ModelException; import dev.fyloz.trial.colorrecipesexplorer.model.Material; import dev.fyloz.trial.colorrecipesexplorer.model.MaterialType; diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/OthersController.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/OthersController.java index 684fe40..80d2c2b 100644 --- a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/OthersController.java +++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/OthersController.java @@ -1,6 +1,6 @@ package dev.fyloz.trial.colorrecipesexplorer.web.controller.thymeleaf; -import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundException; +import dev.fyloz.trial.colorrecipesexplorer.exception.EntityNotFoundException; import dev.fyloz.trial.colorrecipesexplorer.web.response.ModelResponseBuilder; import dev.fyloz.trial.colorrecipesexplorer.web.response.ResponseCode; import dev.fyloz.trial.colorrecipesexplorer.service.files.MarkdownFilesService; diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/RecipeExplorerController.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/RecipeExplorerController.java index 1402a12..f1b236e 100644 --- a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/RecipeExplorerController.java +++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/RecipeExplorerController.java @@ -1,6 +1,6 @@ package dev.fyloz.trial.colorrecipesexplorer.web.controller.thymeleaf; -import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundException; +import dev.fyloz.trial.colorrecipesexplorer.exception.EntityNotFoundException; import dev.fyloz.trial.colorrecipesexplorer.model.Recipe; import dev.fyloz.trial.colorrecipesexplorer.web.response.JSONResponseBuilder; import dev.fyloz.trial.colorrecipesexplorer.web.response.ModelResponseBuilder; diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/creators/CompanyCreatorController.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/creators/CompanyCreatorController.java index 54edae7..370c9ba 100644 --- a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/creators/CompanyCreatorController.java +++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/creators/CompanyCreatorController.java @@ -1,6 +1,6 @@ package dev.fyloz.trial.colorrecipesexplorer.web.controller.thymeleaf.creators; -import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityAlreadyExistsException; +import dev.fyloz.trial.colorrecipesexplorer.exception.EntityAlreadyExistsException; import dev.fyloz.trial.colorrecipesexplorer.model.Company; import dev.fyloz.trial.colorrecipesexplorer.web.response.ModelResponseBuilder; import dev.fyloz.trial.colorrecipesexplorer.web.response.ResponseCode; diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/creators/MaterialCreatorController.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/creators/MaterialCreatorController.java index 65c902a..3bc8a42 100644 --- a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/creators/MaterialCreatorController.java +++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/creators/MaterialCreatorController.java @@ -1,7 +1,7 @@ //package dev.fyloz.trial.colorrecipesexplorer.web.controller.thymeleaf.creators; // //import dev.fyloz.trial.colorrecipesexplorer.exception.SimdutException; -//import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityAlreadyExistsException; +//import dev.fyloz.trial.colorrecipesexplorer.exception.EntityAlreadyExistsException; //import dev.fyloz.trial.colorrecipesexplorer.web.response.ModelResponseBuilder; //import dev.fyloz.trial.colorrecipesexplorer.web.response.ResponseCode; //import dev.fyloz.trial.colorrecipesexplorer.web.response.ResponseDataType; diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/creators/MaterialCreatorController.kt b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/creators/MaterialCreatorController.kt index ebc8a4b..80bbe88 100644 --- a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/creators/MaterialCreatorController.kt +++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/creators/MaterialCreatorController.kt @@ -1,7 +1,7 @@ package dev.fyloz.trial.colorrecipesexplorer.web.controller.thymeleaf.creators import dev.fyloz.trial.colorrecipesexplorer.exception.SimdutException -import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityAlreadyExistsException +import dev.fyloz.trial.colorrecipesexplorer.exception.EntityAlreadyExistsException import dev.fyloz.trial.colorrecipesexplorer.web.response.ResponseCode import dev.fyloz.trial.colorrecipesexplorer.model.Material import dev.fyloz.trial.colorrecipesexplorer.model.MaterialSaveDto diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/creators/MaterialTypeCreatorController.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/creators/MaterialTypeCreatorController.java index 6931697..64524d1 100644 --- a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/creators/MaterialTypeCreatorController.java +++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/creators/MaterialTypeCreatorController.java @@ -1,6 +1,6 @@ package dev.fyloz.trial.colorrecipesexplorer.web.controller.thymeleaf.creators; -import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityAlreadyExistsException; +import dev.fyloz.trial.colorrecipesexplorer.exception.EntityAlreadyExistsException; import dev.fyloz.trial.colorrecipesexplorer.exception.model.ModelException; import dev.fyloz.trial.colorrecipesexplorer.web.response.ModelResponseBuilder; import dev.fyloz.trial.colorrecipesexplorer.web.response.ResponseCode; diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/creators/MixCreatorController.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/creators/MixCreatorController.java index b55cdde..8b76a3d 100644 --- a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/creators/MixCreatorController.java +++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/creators/MixCreatorController.java @@ -1,7 +1,7 @@ package dev.fyloz.trial.colorrecipesexplorer.web.controller.thymeleaf.creators; -import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityAlreadyExistsException; -import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundException; +import dev.fyloz.trial.colorrecipesexplorer.exception.EntityAlreadyExistsException; +import dev.fyloz.trial.colorrecipesexplorer.exception.EntityNotFoundException; import dev.fyloz.trial.colorrecipesexplorer.model.MixKt; import dev.fyloz.trial.colorrecipesexplorer.model.MixTypeKt; import dev.fyloz.trial.colorrecipesexplorer.model.Recipe; diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/editors/MaterialEditorController.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/editors/MaterialEditorController.java index 79de636..7e7fde1 100644 --- a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/editors/MaterialEditorController.java +++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/editors/MaterialEditorController.java @@ -1,8 +1,8 @@ package dev.fyloz.trial.colorrecipesexplorer.web.controller.thymeleaf.editors; import dev.fyloz.trial.colorrecipesexplorer.exception.SimdutException; -import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityAlreadyExistsException; -import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundException; +import dev.fyloz.trial.colorrecipesexplorer.exception.EntityAlreadyExistsException; +import dev.fyloz.trial.colorrecipesexplorer.exception.EntityNotFoundException; import dev.fyloz.trial.colorrecipesexplorer.web.response.ModelResponseBuilder; import dev.fyloz.trial.colorrecipesexplorer.web.response.ResponseCode; import dev.fyloz.trial.colorrecipesexplorer.web.response.ResponseDataType; diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/editors/MaterialTypeEditorController.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/editors/MaterialTypeEditorController.java index 9f3d59d..a4f9cd2 100644 --- a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/editors/MaterialTypeEditorController.java +++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/editors/MaterialTypeEditorController.java @@ -1,8 +1,8 @@ package dev.fyloz.trial.colorrecipesexplorer.web.controller.thymeleaf.editors; import dev.fyloz.trial.colorrecipesexplorer.exception.CannotEditDefaultMaterialTypeException; -import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityAlreadyExistsException; -import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundException; +import dev.fyloz.trial.colorrecipesexplorer.exception.EntityAlreadyExistsException; +import dev.fyloz.trial.colorrecipesexplorer.exception.EntityNotFoundException; import dev.fyloz.trial.colorrecipesexplorer.exception.model.ModelException; import dev.fyloz.trial.colorrecipesexplorer.web.response.ModelResponseBuilder; import dev.fyloz.trial.colorrecipesexplorer.web.response.ResponseCode; diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/editors/MixEditorController.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/editors/MixEditorController.java index 92ced92..958bcd3 100644 --- a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/editors/MixEditorController.java +++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/editors/MixEditorController.java @@ -1,7 +1,7 @@ package dev.fyloz.trial.colorrecipesexplorer.web.controller.thymeleaf.editors; -import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityAlreadyExistsException; -import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundException; +import dev.fyloz.trial.colorrecipesexplorer.exception.EntityAlreadyExistsException; +import dev.fyloz.trial.colorrecipesexplorer.exception.EntityNotFoundException; import dev.fyloz.trial.colorrecipesexplorer.model.Mix; import dev.fyloz.trial.colorrecipesexplorer.model.MixKt; import dev.fyloz.trial.colorrecipesexplorer.model.MixTypeKt; diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/editors/RecipeEditorController.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/editors/RecipeEditorController.java index 66b52eb..4c5c30e 100644 --- a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/editors/RecipeEditorController.java +++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/editors/RecipeEditorController.java @@ -1,6 +1,6 @@ package dev.fyloz.trial.colorrecipesexplorer.web.controller.thymeleaf.editors; -import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundException; +import dev.fyloz.trial.colorrecipesexplorer.exception.EntityNotFoundException; import dev.fyloz.trial.colorrecipesexplorer.model.Recipe; import dev.fyloz.trial.colorrecipesexplorer.web.response.ModelResponseBuilder; import dev.fyloz.trial.colorrecipesexplorer.web.response.ResponseCode; diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/files/ImageFilesController.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/files/ImageFilesController.java index ded8fbe..d73b36f 100644 --- a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/files/ImageFilesController.java +++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/files/ImageFilesController.java @@ -1,6 +1,6 @@ package dev.fyloz.trial.colorrecipesexplorer.web.controller.thymeleaf.files; -import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundException; +import dev.fyloz.trial.colorrecipesexplorer.exception.EntityNotFoundException; import dev.fyloz.trial.colorrecipesexplorer.model.Recipe; import dev.fyloz.trial.colorrecipesexplorer.web.response.JSONResponseBuilder; import dev.fyloz.trial.colorrecipesexplorer.web.response.ModelResponseBuilder; diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/files/SimdutFilesController.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/files/SimdutFilesController.java index d79236b..271757b 100644 --- a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/files/SimdutFilesController.java +++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/files/SimdutFilesController.java @@ -1,6 +1,6 @@ package dev.fyloz.trial.colorrecipesexplorer.web.controller.thymeleaf.files; -import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundException; +import dev.fyloz.trial.colorrecipesexplorer.exception.EntityNotFoundException; import dev.fyloz.trial.colorrecipesexplorer.service.files.SimdutService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Profile; diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/files/XlsExporterController.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/files/XlsExporterController.java index a420e4f..db097d7 100644 --- a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/files/XlsExporterController.java +++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/files/XlsExporterController.java @@ -1,6 +1,6 @@ package dev.fyloz.trial.colorrecipesexplorer.web.controller.thymeleaf.files; -import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundException; +import dev.fyloz.trial.colorrecipesexplorer.exception.EntityNotFoundException; import dev.fyloz.trial.colorrecipesexplorer.service.files.XlsService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Profile; diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/removers/CompanyRemoverController.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/removers/CompanyRemoverController.java index 24d9172..d1aee67 100644 --- a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/removers/CompanyRemoverController.java +++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/removers/CompanyRemoverController.java @@ -1,7 +1,7 @@ package dev.fyloz.trial.colorrecipesexplorer.web.controller.thymeleaf.removers; import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityLinkedException; -import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundException; +import dev.fyloz.trial.colorrecipesexplorer.exception.EntityNotFoundException; import dev.fyloz.trial.colorrecipesexplorer.model.Company; import dev.fyloz.trial.colorrecipesexplorer.web.response.ModelResponseBuilder; import dev.fyloz.trial.colorrecipesexplorer.web.response.ResponseCode; diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/removers/MaterialRemoverController.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/removers/MaterialRemoverController.java index e704505..6aec3e6 100644 --- a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/removers/MaterialRemoverController.java +++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/removers/MaterialRemoverController.java @@ -1,7 +1,7 @@ package dev.fyloz.trial.colorrecipesexplorer.web.controller.thymeleaf.removers; import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityLinkedException; -import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundException; +import dev.fyloz.trial.colorrecipesexplorer.exception.EntityNotFoundException; import dev.fyloz.trial.colorrecipesexplorer.web.response.ModelResponseBuilder; import dev.fyloz.trial.colorrecipesexplorer.web.response.ResponseCode; import dev.fyloz.trial.colorrecipesexplorer.web.response.ResponseDataType; diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/removers/MaterialTypeRemoverController.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/removers/MaterialTypeRemoverController.java index 990a3ac..b7e6b1a 100644 --- a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/removers/MaterialTypeRemoverController.java +++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/removers/MaterialTypeRemoverController.java @@ -2,7 +2,7 @@ package dev.fyloz.trial.colorrecipesexplorer.web.controller.thymeleaf.removers; import dev.fyloz.trial.colorrecipesexplorer.exception.CannotDeleteDefaultMaterialTypeException; import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityLinkedException; -import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundException; +import dev.fyloz.trial.colorrecipesexplorer.exception.EntityNotFoundException; import dev.fyloz.trial.colorrecipesexplorer.web.response.ModelResponseBuilder; import dev.fyloz.trial.colorrecipesexplorer.web.response.ResponseCode; import dev.fyloz.trial.colorrecipesexplorer.web.response.ResponseDataType; diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/removers/MixRemoverController.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/removers/MixRemoverController.java index 227efbe..b99d58b 100644 --- a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/removers/MixRemoverController.java +++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/removers/MixRemoverController.java @@ -1,6 +1,6 @@ package dev.fyloz.trial.colorrecipesexplorer.web.controller.thymeleaf.removers; -import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundException; +import dev.fyloz.trial.colorrecipesexplorer.exception.EntityNotFoundException; import dev.fyloz.trial.colorrecipesexplorer.model.Mix; import dev.fyloz.trial.colorrecipesexplorer.web.response.ModelResponseBuilder; import dev.fyloz.trial.colorrecipesexplorer.web.response.ResponseCode; diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/removers/RecipeRemoverController.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/removers/RecipeRemoverController.java index d52af7c..3cff967 100644 --- a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/removers/RecipeRemoverController.java +++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/thymeleaf/removers/RecipeRemoverController.java @@ -1,6 +1,6 @@ package dev.fyloz.trial.colorrecipesexplorer.web.controller.thymeleaf.removers; -import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundException; +import dev.fyloz.trial.colorrecipesexplorer.exception.EntityNotFoundException; import dev.fyloz.trial.colorrecipesexplorer.model.Recipe; import dev.fyloz.trial.colorrecipesexplorer.web.response.ModelResponseBuilder; import dev.fyloz.trial.colorrecipesexplorer.web.response.ResponseCode; diff --git a/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/config/WebSecurityConfig.kt b/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/config/WebSecurityConfig.kt index 9863b35..8e08a7f 100644 --- a/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/config/WebSecurityConfig.kt +++ b/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/config/WebSecurityConfig.kt @@ -1,7 +1,7 @@ package dev.fyloz.trial.colorrecipesexplorer.config import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper -import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundRestException +import dev.fyloz.trial.colorrecipesexplorer.exception.EntityNotFoundRestException import dev.fyloz.trial.colorrecipesexplorer.model.Employee import dev.fyloz.trial.colorrecipesexplorer.model.EmployeeLoginRequest import dev.fyloz.trial.colorrecipesexplorer.model.EmployeePermission diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/exception/model/EntityAlreadyExistsException.kt b/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/exception/Exception.kt similarity index 53% rename from src/main/java/dev/fyloz/trial/colorrecipesexplorer/exception/model/EntityAlreadyExistsException.kt rename to src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/exception/Exception.kt index 26232c5..1be48d6 100644 --- a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/exception/model/EntityAlreadyExistsException.kt +++ b/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/exception/Exception.kt @@ -1,9 +1,7 @@ -package dev.fyloz.trial.colorrecipesexplorer.exception.model +package dev.fyloz.trial.colorrecipesexplorer.exception -import dev.fyloz.trial.colorrecipesexplorer.exception.RestException +import dev.fyloz.trial.colorrecipesexplorer.exception.model.ModelException import dev.fyloz.trial.colorrecipesexplorer.model.Model -import org.springframework.http.HttpStatus -import org.springframework.web.bind.annotation.ResponseStatus class EntityAlreadyExistsException( modelType: Class, @@ -26,12 +24,8 @@ class EntityAlreadyExistsException( ) } -@ResponseStatus(HttpStatus.CONFLICT) -class EntityAlreadyExistsRestException(val value: Any) : - RestException("An entity with the given identifier already exists", HttpStatus.CONFLICT) { - - @Suppress("unused") - override fun buildBody(): RestExceptionBody = object : RestExceptionBody() { - val id = value - } -} +class EntityNotFoundException( + modelType: Class, + val identifierType: IdentifierType, + val requestedId: Any +) : ModelException(modelType) diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/exception/RestException.kt b/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/exception/RestException.kt similarity index 57% rename from src/main/java/dev/fyloz/trial/colorrecipesexplorer/exception/RestException.kt rename to src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/exception/RestException.kt index 137afb9..6ac470e 100644 --- a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/exception/RestException.kt +++ b/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/exception/RestException.kt @@ -2,6 +2,7 @@ package dev.fyloz.trial.colorrecipesexplorer.exception import com.fasterxml.jackson.annotation.JsonProperty import dev.fyloz.trial.colorrecipesexplorer.exception.model.* +import dev.fyloz.trial.colorrecipesexplorer.model.Model import org.springframework.context.annotation.Profile import org.springframework.http.HttpHeaders import org.springframework.http.HttpStatus @@ -10,15 +11,51 @@ import org.springframework.validation.FieldError import org.springframework.web.bind.MethodArgumentNotValidException import org.springframework.web.bind.annotation.ControllerAdvice import org.springframework.web.bind.annotation.ExceptionHandler +import org.springframework.web.bind.annotation.ResponseStatus import org.springframework.web.context.request.WebRequest import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler -abstract class RestException(val exceptionMessage: String, val httpStatus: HttpStatus) : RuntimeException(exceptionMessage) { +abstract class RestException(val exceptionMessage: String, val httpStatus: HttpStatus) : + RuntimeException(exceptionMessage) { abstract fun buildBody(): RestExceptionBody - open inner class RestExceptionBody(val status: Int = httpStatus.value(), @JsonProperty("message") val message: String = exceptionMessage) + open inner class RestExceptionBody( + val status: Int = httpStatus.value(), + @JsonProperty("message") val message: String = exceptionMessage + ) } +@ResponseStatus(HttpStatus.CONFLICT) +class EntityAlreadyExistsRestException(val value: Any) : + RestException("An entity with the given identifier already exists", HttpStatus.CONFLICT) { + @Suppress("unused") + override fun buildBody(): RestExceptionBody = object : RestExceptionBody() { + val id = value + } +} + +@ResponseStatus(HttpStatus.NOT_FOUND) +class EntityNotFoundRestException(val value: Any) : + RestException("An entity could not be found with the given identifier", HttpStatus.NOT_FOUND) { + @Suppress("unused") + override fun buildBody(): RestExceptionBody = object : RestExceptionBody() { + val id = value + } +} + +@ResponseStatus(HttpStatus.CONFLICT) +class CannotDeleteEntityRestException(val value: Long) : + RestException( + "The entity with the given identifier could not be deleted because it is required by other entities", + HttpStatus.CONFLICT + ) { + @Suppress("unused") + override fun buildBody(): RestExceptionBody = object : RestExceptionBody() { + val id = value + } +} + + @ControllerAdvice @Profile("rest") class RestResponseEntityExceptionHandler : ResponseEntityExceptionHandler() { @@ -32,7 +69,12 @@ class RestResponseEntityExceptionHandler : ResponseEntityExceptionHandler() { return handleExceptionInternal(exception, exception.buildBody(), HttpHeaders(), exception.httpStatus, request) } - override fun handleMethodArgumentNotValid(ex: MethodArgumentNotValidException, headers: HttpHeaders, status: HttpStatus, request: WebRequest): ResponseEntity { + override fun handleMethodArgumentNotValid( + ex: MethodArgumentNotValidException, + headers: HttpHeaders, + status: HttpStatus, + request: WebRequest + ): ResponseEntity { val errors = hashMapOf() ex.bindingResult.allErrors.forEach { val fieldName = (it as FieldError).field diff --git a/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/repository/CompanyRepository.kt b/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/repository/CompanyRepository.kt index f07b1bd..c0a6a5a 100644 --- a/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/repository/CompanyRepository.kt +++ b/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/repository/CompanyRepository.kt @@ -1,7 +1,18 @@ package dev.fyloz.trial.colorrecipesexplorer.repository import dev.fyloz.trial.colorrecipesexplorer.model.Company +import org.springframework.data.jpa.repository.Query import org.springframework.stereotype.Repository @Repository -interface CompanyRepository : NamedJpaRepository +interface CompanyRepository : NamedJpaRepository { + @Query( + """ + select case when(count(r.id) > 0) then false else true end + from Company c + left join Recipe r on c.id = r.company.id + where c.id = :id + """ + ) + fun canBeDeleted(id: Long): Boolean +} diff --git a/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/repository/MaterialRepository.kt b/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/repository/MaterialRepository.kt index 13a36bf..a678110 100644 --- a/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/repository/MaterialRepository.kt +++ b/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/repository/MaterialRepository.kt @@ -2,6 +2,7 @@ package dev.fyloz.trial.colorrecipesexplorer.repository import dev.fyloz.trial.colorrecipesexplorer.model.Material import dev.fyloz.trial.colorrecipesexplorer.model.MaterialType +import org.springframework.data.jpa.repository.Query import org.springframework.stereotype.Repository @Repository @@ -11,4 +12,15 @@ interface MaterialRepository : NamedJpaRepository { /** Gets all the materials with the given [materialType]. */ fun findAllByMaterialType(materialType: MaterialType): Collection + + @Query( + """ + select case when(count(mm.id) + count(mt.id) > 0) then false else true end + from Material m + left join MixMaterial mm on m.id = mm.material.id + left join MixType mt on m.id = mt.material.id + where m.id = :id + """ + ) + fun canBeDeleted(id: Long): Boolean } diff --git a/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/repository/MaterialTypeRepository.kt b/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/repository/MaterialTypeRepository.kt index 14b2870..737500e 100644 --- a/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/repository/MaterialTypeRepository.kt +++ b/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/repository/MaterialTypeRepository.kt @@ -1,6 +1,7 @@ package dev.fyloz.trial.colorrecipesexplorer.repository import dev.fyloz.trial.colorrecipesexplorer.model.MaterialType +import org.springframework.data.jpa.repository.Query import org.springframework.stereotype.Repository @Repository @@ -13,4 +14,14 @@ interface MaterialTypeRepository : NamedJpaRepository { /** Gets the material type with the given [prefix]. */ fun findByPrefix(prefix: String): MaterialType? + + @Query( + """ + select case when(count(m.id) > 0) then false else true end + from MaterialType t + left join Material m on t.id = m.materialType.id + where t.id = :id + """ + ) + fun canBeDeleted(id: Long): Boolean } diff --git a/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/repository/MixRepository.kt b/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/repository/MixRepository.kt index 0c53732..082439e 100644 --- a/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/repository/MixRepository.kt +++ b/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/repository/MixRepository.kt @@ -3,8 +3,19 @@ package dev.fyloz.trial.colorrecipesexplorer.repository import dev.fyloz.trial.colorrecipesexplorer.model.Mix import dev.fyloz.trial.colorrecipesexplorer.model.MixType import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.data.jpa.repository.Query interface MixRepository : JpaRepository { /** Finds all mixes with the given [mixType]. */ fun findAllByMixType(mixType: MixType): Collection + + @Query( + """ + select case when(count(mm.id) > 0) then false else true end + from Mix m + left join MixMaterial mm on m.mixType.material.id = mm.material.id + where m.id = :id + """ + ) + fun canBeDeleted(id: Long): Boolean } diff --git a/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/repository/MixTypeRepository.kt b/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/repository/MixTypeRepository.kt index 0ae4ccc..87430d6 100644 --- a/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/repository/MixTypeRepository.kt +++ b/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/repository/MixTypeRepository.kt @@ -2,10 +2,21 @@ package dev.fyloz.trial.colorrecipesexplorer.repository import dev.fyloz.trial.colorrecipesexplorer.model.Material import dev.fyloz.trial.colorrecipesexplorer.model.MixType +import org.springframework.data.jpa.repository.Query import org.springframework.stereotype.Repository @Repository interface MixTypeRepository : NamedJpaRepository { /** Gets the mix type with the given [material]. */ fun findByMaterial(material: Material): MixType? + + @Query( + """ + select case when(count(m.id) > 0) then false else true end + from MixType t + left join Mix m on t.id = m.mixType.id + where t.id = :id + """ + ) + fun canBeDeleted(id: Long): Boolean } diff --git a/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/AccountService.kt b/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/AccountService.kt index 8240d29..d8aea18 100644 --- a/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/AccountService.kt +++ b/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/AccountService.kt @@ -2,9 +2,9 @@ package dev.fyloz.trial.colorrecipesexplorer.service import dev.fyloz.trial.colorrecipesexplorer.config.blacklistedJwtTokens import dev.fyloz.trial.colorrecipesexplorer.config.defaultGroupCookieName -import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityAlreadyExistsRestException -import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundException -import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundRestException +import dev.fyloz.trial.colorrecipesexplorer.exception.EntityAlreadyExistsRestException +import dev.fyloz.trial.colorrecipesexplorer.exception.EntityNotFoundException +import dev.fyloz.trial.colorrecipesexplorer.exception.EntityNotFoundRestException import dev.fyloz.trial.colorrecipesexplorer.model.* import dev.fyloz.trial.colorrecipesexplorer.model.validation.or import dev.fyloz.trial.colorrecipesexplorer.repository.EmployeeGroupRepository diff --git a/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/CompanyService.kt b/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/CompanyService.kt index 9556cbd..80b5129 100644 --- a/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/CompanyService.kt +++ b/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/CompanyService.kt @@ -1,5 +1,6 @@ package dev.fyloz.trial.colorrecipesexplorer.service +import dev.fyloz.trial.colorrecipesexplorer.exception.CannotDeleteEntityRestException import dev.fyloz.trial.colorrecipesexplorer.model.Company import dev.fyloz.trial.colorrecipesexplorer.model.CompanySaveDto import dev.fyloz.trial.colorrecipesexplorer.model.CompanyUpdateDto @@ -30,4 +31,9 @@ class CompanyServiceImpl(companyRepository: CompanyRepository, val recipeService ) }) } + + override fun deleteById(id: Long) { + if (!repository.canBeDeleted(id)) throw CannotDeleteEntityRestException(id) + super.deleteById(id) + } } diff --git a/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/MaterialService.kt b/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/MaterialService.kt index 8f97ccd..c72536d 100644 --- a/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/MaterialService.kt +++ b/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/MaterialService.kt @@ -1,5 +1,6 @@ package dev.fyloz.trial.colorrecipesexplorer.service +import dev.fyloz.trial.colorrecipesexplorer.exception.CannotDeleteEntityRestException import dev.fyloz.trial.colorrecipesexplorer.model.* import dev.fyloz.trial.colorrecipesexplorer.repository.MaterialRepository import dev.fyloz.trial.colorrecipesexplorer.service.files.SimdutService @@ -90,4 +91,9 @@ class MaterialServiceImpl( private fun assertPersistedMaterial(material: Material) { Assert.notNull(material.name, "The persisted material with the id ${material.id} has a null name") } + + override fun deleteById(id: Long) { + if (!repository.canBeDeleted(id)) throw CannotDeleteEntityRestException(id) + super.deleteById(id) + } } diff --git a/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/MaterialTypeService.kt b/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/MaterialTypeService.kt index 81a4bc2..fd6741d 100644 --- a/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/MaterialTypeService.kt +++ b/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/MaterialTypeService.kt @@ -1,8 +1,9 @@ package dev.fyloz.trial.colorrecipesexplorer.service import dev.fyloz.trial.colorrecipesexplorer.config.properties.MaterialTypeProperties +import dev.fyloz.trial.colorrecipesexplorer.exception.CannotDeleteEntityRestException import dev.fyloz.trial.colorrecipesexplorer.exception.RestException -import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityAlreadyExistsRestException +import dev.fyloz.trial.colorrecipesexplorer.exception.EntityAlreadyExistsRestException import dev.fyloz.trial.colorrecipesexplorer.model.MaterialType import dev.fyloz.trial.colorrecipesexplorer.model.MaterialTypeSaveDto import dev.fyloz.trial.colorrecipesexplorer.model.MaterialTypeUpdateDto @@ -73,11 +74,9 @@ class MaterialTypeServiceImpl(repository: MaterialTypeRepository, private val ma return super.update(entity) } - override fun delete(entity: MaterialType) { - if (isUsedByMaterial(entity)) - throw CannotDeleteUsedMaterialTypeRestException() - - super.delete(entity) + override fun deleteById(id: Long) { + if (!repository.canBeDeleted(id)) throw CannotDeleteEntityRestException(id) + super.deleteById(id) } override fun saveSystemTypes(systemTypeProperties: Collection) { diff --git a/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/MixService.kt b/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/MixService.kt index 386e65b..390674a 100644 --- a/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/MixService.kt +++ b/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/MixService.kt @@ -1,5 +1,6 @@ package dev.fyloz.trial.colorrecipesexplorer.service +import dev.fyloz.trial.colorrecipesexplorer.exception.CannotDeleteEntityRestException import dev.fyloz.trial.colorrecipesexplorer.model.* import dev.fyloz.trial.colorrecipesexplorer.repository.MixRepository import org.springframework.context.annotation.Lazy @@ -110,4 +111,9 @@ class MixServiceImpl( recipeService.removeMix(entity) super.delete(entity) } + + override fun deleteById(id: Long) { + if (!repository.canBeDeleted(id)) throw CannotDeleteEntityRestException(id) + super.deleteById(id) + } } diff --git a/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/MixTypeService.kt b/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/MixTypeService.kt index aee1bb7..8911b23 100644 --- a/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/MixTypeService.kt +++ b/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/MixTypeService.kt @@ -1,7 +1,8 @@ package dev.fyloz.trial.colorrecipesexplorer.service -import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityAlreadyExistsRestException -import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundRestException +import dev.fyloz.trial.colorrecipesexplorer.exception.CannotDeleteEntityRestException +import dev.fyloz.trial.colorrecipesexplorer.exception.EntityAlreadyExistsRestException +import dev.fyloz.trial.colorrecipesexplorer.exception.EntityNotFoundRestException import dev.fyloz.trial.colorrecipesexplorer.model.* import dev.fyloz.trial.colorrecipesexplorer.repository.MixTypeRepository import org.springframework.context.annotation.Lazy @@ -53,4 +54,9 @@ class MixTypeServiceImpl( material.name = name material.materialType = materialType }) + + override fun deleteById(id: Long) { + if (!repository.canBeDeleted(id)) throw CannotDeleteEntityRestException(id) + super.deleteById(id) + } } 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 210d7f4..0b05c70 100644 --- a/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/RecipeService.kt +++ b/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/RecipeService.kt @@ -1,6 +1,6 @@ package dev.fyloz.trial.colorrecipesexplorer.service -import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundRestException +import dev.fyloz.trial.colorrecipesexplorer.exception.EntityNotFoundRestException import dev.fyloz.trial.colorrecipesexplorer.model.* import dev.fyloz.trial.colorrecipesexplorer.model.validation.isNotNullAndNotBlank import dev.fyloz.trial.colorrecipesexplorer.model.validation.or diff --git a/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/Service.kt b/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/Service.kt index 1c6fc82..8e90de3 100644 --- a/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/Service.kt +++ b/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/Service.kt @@ -1,8 +1,8 @@ package dev.fyloz.trial.colorrecipesexplorer.service import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper -import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityAlreadyExistsRestException -import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundRestException +import dev.fyloz.trial.colorrecipesexplorer.exception.EntityAlreadyExistsRestException +import dev.fyloz.trial.colorrecipesexplorer.exception.EntityNotFoundRestException import dev.fyloz.trial.colorrecipesexplorer.model.EntityDto import dev.fyloz.trial.colorrecipesexplorer.model.Model import dev.fyloz.trial.colorrecipesexplorer.model.NamedModel diff --git a/src/test/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/AbstractServiceTest.kt b/src/test/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/AbstractServiceTest.kt index ff0baf2..17d0ea3 100644 --- a/src/test/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/AbstractServiceTest.kt +++ b/src/test/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/AbstractServiceTest.kt @@ -1,8 +1,8 @@ package dev.fyloz.trial.colorrecipesexplorer.service import com.nhaarman.mockitokotlin2.* -import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityAlreadyExistsRestException -import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundRestException +import dev.fyloz.trial.colorrecipesexplorer.exception.EntityAlreadyExistsRestException +import dev.fyloz.trial.colorrecipesexplorer.exception.EntityNotFoundRestException import dev.fyloz.trial.colorrecipesexplorer.model.EntityDto import dev.fyloz.trial.colorrecipesexplorer.model.Model import dev.fyloz.trial.colorrecipesexplorer.model.NamedModel diff --git a/src/test/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/AccountsServiceTest.kt b/src/test/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/AccountsServiceTest.kt index b862d96..ac9b44a 100644 --- a/src/test/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/AccountsServiceTest.kt +++ b/src/test/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/AccountsServiceTest.kt @@ -2,8 +2,8 @@ package dev.fyloz.trial.colorrecipesexplorer.service import com.nhaarman.mockitokotlin2.* import dev.fyloz.trial.colorrecipesexplorer.config.defaultGroupCookieName -import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityAlreadyExistsRestException -import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundRestException +import dev.fyloz.trial.colorrecipesexplorer.exception.EntityAlreadyExistsRestException +import dev.fyloz.trial.colorrecipesexplorer.exception.EntityNotFoundRestException import dev.fyloz.trial.colorrecipesexplorer.model.* import dev.fyloz.trial.colorrecipesexplorer.repository.EmployeeGroupRepository import dev.fyloz.trial.colorrecipesexplorer.repository.EmployeeRepository diff --git a/src/test/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/CompanyServiceTest.kt b/src/test/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/CompanyServiceTest.kt index 458f688..ebf45ce 100644 --- a/src/test/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/CompanyServiceTest.kt +++ b/src/test/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/CompanyServiceTest.kt @@ -52,4 +52,10 @@ class CompanyServiceTest : override fun `update(dto) calls and returns update() with the created entity`() = withBaseUpdateDtoTest(entity, entityUpdateDto, service, any()) + + // delete() + + override fun `deleteById() deletes the entity with the given id in the repository`() { + super.`deleteById() deletes the entity with the given id in the repository`() + } } diff --git a/src/test/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/MaterialServiceTest.kt b/src/test/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/MaterialServiceTest.kt index 24ed8a4..5856582 100644 --- a/src/test/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/MaterialServiceTest.kt +++ b/src/test/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/MaterialServiceTest.kt @@ -1,12 +1,11 @@ package dev.fyloz.trial.colorrecipesexplorer.service import com.nhaarman.mockitokotlin2.* -import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityAlreadyExistsRestException +import dev.fyloz.trial.colorrecipesexplorer.exception.EntityAlreadyExistsRestException import dev.fyloz.trial.colorrecipesexplorer.model.* import dev.fyloz.trial.colorrecipesexplorer.repository.MaterialRepository import dev.fyloz.trial.colorrecipesexplorer.service.files.SimdutService import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.Nested import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertThrows import org.springframework.mock.web.MockMultipartFile @@ -191,6 +190,12 @@ class MaterialServiceTest : verify(simdutService).update(eq(mockSimdutFile), any()) } + // delete() + + override fun `deleteById() deletes the entity with the given id in the repository`() { + super.`deleteById() deletes the entity with the given id in the repository`() + } + /** Helper function to replace collections.in because the id is not considered in the equals function of Material while Thymeleaf is supported. */ private infix fun Collection.contains(material: Material): Boolean = any { it.id == material.id } diff --git a/src/test/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/MaterialTypeServiceTest.kt b/src/test/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/MaterialTypeServiceTest.kt index 802cdd3..10a2fee 100644 --- a/src/test/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/MaterialTypeServiceTest.kt +++ b/src/test/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/MaterialTypeServiceTest.kt @@ -1,12 +1,11 @@ package dev.fyloz.trial.colorrecipesexplorer.service import com.nhaarman.mockitokotlin2.* -import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityAlreadyExistsRestException -import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundRestException +import dev.fyloz.trial.colorrecipesexplorer.exception.EntityAlreadyExistsRestException +import dev.fyloz.trial.colorrecipesexplorer.exception.EntityNotFoundRestException import dev.fyloz.trial.colorrecipesexplorer.model.* import dev.fyloz.trial.colorrecipesexplorer.repository.MaterialTypeRepository import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.Nested import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertThrows import kotlin.test.assertEquals @@ -167,10 +166,7 @@ class MaterialTypeServiceTest : verify(repository).delete(entity) } - @Test - fun `delete() throws CannotDeleteUsedMaterialTypeRestException when the material type is in use`() { - doReturn(true).whenever(service).isUsedByMaterial(entity) - - assertThrows { service.delete(entity) } + override fun `deleteById() deletes the entity with the given id in the repository`() { + super.`deleteById() deletes the entity with the given id in the repository`() } } diff --git a/src/test/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/MixServiceTest.kt b/src/test/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/MixServiceTest.kt index 728f344..43c1d13 100644 --- a/src/test/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/MixServiceTest.kt +++ b/src/test/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/MixServiceTest.kt @@ -191,6 +191,12 @@ class MixServiceTest : AbstractExternalModelServiceTest Date: Tue, 9 Mar 2021 19:51:31 -0500 Subject: [PATCH 2/2] =?UTF-8?q?La=20cr=C3=A9ation=20d'un=20m=C3=A9lange=20?= =?UTF-8?q?v=C3=A9rifie=20si=20le=20type=20de=20m=C3=A9lange=20existe=20av?= =?UTF-8?q?ant=20de=20tenter=20de=20le=20cr=C3=A9er.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/MixTypeRepository.kt | 8 +++ .../service/MixService.kt | 4 +- .../service/MixTypeService.kt | 26 +++++++- .../service/MixServiceTest.kt | 11 ++-- .../service/MixTypeServiceTest.kt | 59 +++++++++++++++++-- 5 files changed, 95 insertions(+), 13 deletions(-) diff --git a/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/repository/MixTypeRepository.kt b/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/repository/MixTypeRepository.kt index 87430d6..0838acf 100644 --- a/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/repository/MixTypeRepository.kt +++ b/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/repository/MixTypeRepository.kt @@ -1,15 +1,23 @@ package dev.fyloz.trial.colorrecipesexplorer.repository import dev.fyloz.trial.colorrecipesexplorer.model.Material +import dev.fyloz.trial.colorrecipesexplorer.model.MaterialType import dev.fyloz.trial.colorrecipesexplorer.model.MixType import org.springframework.data.jpa.repository.Query import org.springframework.stereotype.Repository @Repository interface MixTypeRepository : NamedJpaRepository { + @Query("select case when(count(m) > 0) then true else false end from MixType m where m.name = :name and m.material.materialType = :materialType") + fun existsByNameAndMaterialType(name: String, materialType: MaterialType): Boolean + /** Gets the mix type with the given [material]. */ fun findByMaterial(material: Material): MixType? + /** Gets the [MixType] with the given [name] and [materialType]. */ + @Query("select m from MixType m where m.name = :name and m.material.materialType = :materialType") + fun findByNameAndMaterialType(name: String, materialType: MaterialType): MixType? + @Query( """ select case when(count(m.id) > 0) then false else true end diff --git a/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/MixService.kt b/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/MixService.kt index 390674a..4745815 100644 --- a/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/MixService.kt +++ b/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/MixService.kt @@ -34,7 +34,7 @@ class MixServiceImpl( override fun save(entity: MixSaveDto): Mix { val recipe = recipeService.getById(entity.recipeId) val materialType = materialTypeService.getById(entity.materialTypeId) - val mixType = mixTypeService.createForNameAndMaterialType(entity.name, materialType) + val mixType = mixTypeService.getOrCreateForNameAndMaterialType(entity.name, materialType) var mix = save(mix(recipe = recipe, mixType = mixType)) val mixMaterials = @@ -84,7 +84,7 @@ class MixServiceImpl( val mix = getById(entity.id) if (entity.name != null || entity.materialTypeId != null) { mix.mixType = if (mixTypeIsShared(mix.mixType)) { - mixTypeService.createForNameAndMaterialType( + mixTypeService.saveForNameAndMaterialType( entity.name ?: mix.mixType.name, if (entity.materialTypeId != null) materialTypeService.getById(entity.materialTypeId) else mix.mixType.material.materialType!! ) diff --git a/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/MixTypeService.kt b/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/MixTypeService.kt index 8911b23..f9890a5 100644 --- a/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/MixTypeService.kt +++ b/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/MixTypeService.kt @@ -9,11 +9,20 @@ import org.springframework.context.annotation.Lazy import org.springframework.stereotype.Service interface MixTypeService : NamedModelService { + /** Checks if a [MixType] with the given [name] and [materialType] exists. */ + fun existsByNameAndMaterialType(name: String, materialType: MaterialType): Boolean + /** Gets the mix type with the given [material]. */ fun getByMaterial(material: Material): MixType + /** Gets the [MixType] with the given [name] and [materialType]. */ + fun getByNameAndMaterialType(name: String, materialType: MaterialType): MixType + + /** Returns a [MixType] for the given [name] and [materialType]. If a mix type with these does not already exists, it will be created. */ + fun getOrCreateForNameAndMaterialType(name: String, materialType: MaterialType): MixType + /** Returns a new and persisted [MixType] with the given [name] and [materialType]. */ - fun createForNameAndMaterialType(name: String, materialType: MaterialType): MixType + fun saveForNameAndMaterialType(name: String, materialType: MaterialType): MixType /** Returns the given [mixType] updated with the given [name] and [materialType]. */ fun updateForNameAndMaterialType(mixType: MixType, name: String, materialType: MaterialType): MixType @@ -26,16 +35,29 @@ class MixTypeServiceImpl( @Lazy val mixService: MixService ) : AbstractNamedModelService(mixTypeRepository), MixTypeService { + override fun existsByNameAndMaterialType(name: String, materialType: MaterialType): Boolean = + repository.existsByNameAndMaterialType(name, materialType) + override fun getByMaterial(material: Material): MixType = repository.findByMaterial(material) ?: throw EntityNotFoundRestException(material.name) + override fun getByNameAndMaterialType(name: String, materialType: MaterialType): MixType = + repository.findByNameAndMaterialType(name, materialType) + ?: throw EntityNotFoundRestException("$name/${materialType.name}") + + override fun getOrCreateForNameAndMaterialType(name: String, materialType: MaterialType): MixType = + if (existsByNameAndMaterialType(name, materialType)) + getByNameAndMaterialType(name, materialType) + else + saveForNameAndMaterialType(name, materialType) + override fun save(entity: MixType): MixType { if (materialService.existsByName(entity.name)) throw EntityAlreadyExistsRestException(entity.name) return super.save(entity) } - override fun createForNameAndMaterialType(name: String, materialType: MaterialType): MixType = + override fun saveForNameAndMaterialType(name: String, materialType: MaterialType): MixType = save( mixType( name = name, diff --git a/src/test/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/MixServiceTest.kt b/src/test/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/MixServiceTest.kt index 43c1d13..dd5dd4c 100644 --- a/src/test/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/MixServiceTest.kt +++ b/src/test/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/MixServiceTest.kt @@ -36,6 +36,7 @@ class MixServiceTest : AbstractExternalModelServiceTest() { @@ -17,7 +18,8 @@ class MixTypeServiceTest : AbstractNamedModelServiceTest