From 5fde4078f7b762bf3ea5f8e4c8a018a52e2bdef7 Mon Sep 17 00:00:00 2001 From: FyloZ Date: Mon, 17 Feb 2020 17:15:04 -0500 Subject: [PATCH] =?UTF-8?q?D=C3=A9but=20transition=20vers=20exceptions=20+?= =?UTF-8?q?=20DTO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/EntityAlreadyExistsException.java | 23 ++++ .../model/EntityNotFoundException.java | 35 ++++++ .../core/exception/model/ModelException.java | 27 +++++ .../model/NullIdentifierException.java | 15 +++ .../core/model/dto/RecipeExplorerFormDto.java | 14 +++ .../core/services/GenericService.java | 101 +++++++++--------- .../core/services/IGenericService.java | 66 +++++------- .../{model => }/TouchUpKitService.java | 2 +- .../core/services/model/MixService.java | 2 +- .../core/services/model/RecipeService.java | 63 ++++++----- .../controller/RecipeExplorerController.java | 77 ++++++------- .../files/TouchUpKitController.java | 2 +- src/main/resources/updates.md | 2 +- 13 files changed, 259 insertions(+), 170 deletions(-) create mode 100644 src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/exception/model/EntityAlreadyExistsException.java create mode 100644 src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/exception/model/EntityNotFoundException.java create mode 100644 src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/exception/model/ModelException.java create mode 100644 src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/exception/model/NullIdentifierException.java create mode 100644 src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/model/dto/RecipeExplorerFormDto.java rename src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/services/{model => }/TouchUpKitService.java (93%) diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/exception/model/EntityAlreadyExistsException.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/exception/model/EntityAlreadyExistsException.java new file mode 100644 index 0000000..c6296dc --- /dev/null +++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/exception/model/EntityAlreadyExistsException.java @@ -0,0 +1,23 @@ +package dev.fyloz.trial.colorrecipesexplorer.core.exception.model; + +import dev.fyloz.trial.colorrecipesexplorer.core.model.IModel; + +public class EntityAlreadyExistsException extends ModelException { + + private IdentifierType identifierType; + private Object requestedId; + + public EntityAlreadyExistsException(Class type, IdentifierType identifierType, Object requestedId) { + super(type); + this.identifierType = identifierType; + this.requestedId = requestedId; + } + + public IdentifierType getIdentifierType() { + return identifierType; + } + + public Object getRequestedId() { + return requestedId; + } +} diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/exception/model/EntityNotFoundException.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/exception/model/EntityNotFoundException.java new file mode 100644 index 0000000..301de4b --- /dev/null +++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/exception/model/EntityNotFoundException.java @@ -0,0 +1,35 @@ +package dev.fyloz.trial.colorrecipesexplorer.core.exception.model; + +import dev.fyloz.trial.colorrecipesexplorer.core.model.IModel; +import org.hibernate.type.IdentifierType; + +/** + * Représente une exception qui sera lancée lorsqu'un objet du modèle n'est pas trouvé. + */ +public class EntityNotFoundException extends ModelException { + + /** + * Le type d'identifiant utilisé + */ + private IdentifierType identifierType; + + /** + * La valeur de l'identifiant + */ + private Object requestedId; + + public EntityNotFoundException(Class type, IdentifierType identifierType, Object requestedId) { + super(type); + this.identifierType = identifierType; + this.requestedId = requestedId; + } + + public IdentifierType getIdentifierType() { + return identifierType; + } + + public Object getRequestedId() { + return requestedId; + } + +} diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/exception/model/ModelException.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/exception/model/ModelException.java new file mode 100644 index 0000000..33f0556 --- /dev/null +++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/exception/model/ModelException.java @@ -0,0 +1,27 @@ +package dev.fyloz.trial.colorrecipesexplorer.core.exception.model; + +import dev.fyloz.trial.colorrecipesexplorer.core.model.IModel; + +/** + * Représente une exception qui sera déclenchée lors des opérations sur le modèle. + */ +public class ModelException extends RuntimeException { + + /** + * Le type de modèle qui est sujette à l'exception + */ + protected Class type; + + public ModelException(Class type) { + this.type = type; + } + + public Class getType() { + return type; + } + + public enum IdentifierType { + ID, + NAME + } +} diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/exception/model/NullIdentifierException.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/exception/model/NullIdentifierException.java new file mode 100644 index 0000000..ede0a92 --- /dev/null +++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/exception/model/NullIdentifierException.java @@ -0,0 +1,15 @@ +package dev.fyloz.trial.colorrecipesexplorer.core.exception.model; + +import dev.fyloz.trial.colorrecipesexplorer.core.model.IModel; + +public class NullIdentifierException extends ModelException { + + public NullIdentifierException(Class type) { + super(type); + } + + @Override + public String getMessage() { + return String.format("Un modèle de type '%s' avait un identifiant nécessaire null", type.getSimpleName()); + } +} diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/model/dto/RecipeExplorerFormDto.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/model/dto/RecipeExplorerFormDto.java new file mode 100644 index 0000000..e2dbfdb --- /dev/null +++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/model/dto/RecipeExplorerFormDto.java @@ -0,0 +1,14 @@ +package dev.fyloz.trial.colorrecipesexplorer.core.model.dto; + +import lombok.Data; + +import java.util.Map; + +@Data +public class RecipeExplorerFormDto { + + private Long recipeId; + private Map locations; + private String note; + +} diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/services/GenericService.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/services/GenericService.java index 709ba13..95c7e6f 100644 --- a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/services/GenericService.java +++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/services/GenericService.java @@ -3,27 +3,40 @@ package dev.fyloz.trial.colorrecipesexplorer.core.services; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import dev.fyloz.trial.colorrecipesexplorer.ColorRecipesExplorerApplication; +import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.EntityAlreadyExistsException; +import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.EntityNotFoundException; +import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.ModelException; +import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.NullIdentifierException; import dev.fyloz.trial.colorrecipesexplorer.core.model.IModel; import org.slf4j.Logger; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.lang.NonNull; +import org.springframework.transaction.annotation.Transactional; +import javax.validation.constraints.NotNull; +import java.util.Collection; import java.util.List; import java.util.Optional; +import java.util.stream.Collectors; -public abstract class GenericService> implements IGenericService { +public class GenericService> implements IGenericService { protected Logger logger = ColorRecipesExplorerApplication.LOGGER; - protected R dao; - public GenericService(R dao) { + private Class type; + + public GenericService(R dao, Class type) { this.dao = dao; + this.type = type; } @Override - public Optional getById(Long id) { - return dao.findById(id); + public T getById(Long id) { + Optional found = dao.findById(id); + if (found.isEmpty()) throw new EntityNotFoundException(type, EntityNotFoundException.IdentifierType.ID, id); + + return found.get(); } @Override @@ -32,60 +45,45 @@ public abstract class GenericService save(T entity) { - if (isValidForCreation(entity)) { - return Optional.of(dao.save(entity)); - } + public T save(@NotNull T entity) { + if (entity.getId() != null && existsById(entity.getId())) + throw new EntityAlreadyExistsException(type, ModelException.IdentifierType.ID, entity.getId()); - return Optional.empty(); + return dao.save(entity); } @Override - public boolean saveAll(Iterable entities) { - if (entities == null) return false; - - for (T e : entities) { - if (!save(e).isPresent()) { - return false; - } - } - - dao.saveAll(entities); - - return true; + @Transactional + public Collection saveAll(@NotNull Collection entities) { + return entities + .stream() + .map(this::save) + .collect(Collectors.toList()); } @Override - public Optional update(@NonNull T entity) { - if (isValidForUpdate(entity)) { - return Optional.of(dao.save(entity)); - } + public T update(@NonNull T entity) { + if (entity.getId() == null) throw new NullIdentifierException(type); + if (!existsById(entity.getId())) + throw new EntityNotFoundException(type, ModelException.IdentifierType.ID, entity.getId()); - return Optional.empty(); + return dao.save(entity); } @Override - public boolean delete(T entity) { - if (entity == null) return false; + public void delete(@NonNull T entity) { + if (entity.getId() == null) throw new NullIdentifierException(type); + if (!existsById(entity.getId())) + throw new EntityNotFoundException(type, ModelException.IdentifierType.ID, entity.getId()); - if (exists(entity)) { - dao.delete(entity); - return true; - } - - return false; + dao.delete(entity); } @Override - public boolean deleteAll(List entities) { - if (entities == null) return false; - - for (T entity : entities) { - if (!exists(entity)) return false; - } - - dao.deleteAll(entities); - return true; + @Transactional + public void deleteAll(@NonNull List entities) { + entities + .forEach(this::delete); } /** @@ -94,8 +92,9 @@ public abstract class GenericService { /** - * Récupère toutes les entités du même type dans la base de données. + * Récupère toutes les entités de type T. * - * @return Une collection contenant toutes les entités du même type. + * @return Toutes les entités de type T */ List getAll(); /** - * Récupère l'entité correspondant à l'identifiant spécifié dans la base de données. + * Récupère l'entité de type T correspondant à un identifiant. * * @param id L'identifiant de l'entité - * @return L'entité correspondant à l'identifiant. + * @return L'entité correspondant à l'identifiant */ - Optional getById(Long id); + T getById(Long id); /** - * Sauvegarde une entité dans la base de données. - *

- * La sauvegarde sera exécutée si l'entité est valide pour la création. + * Crée une entité. * - * @param entity L'entité à sauvegarder - * @return Si la sauvegarde a fonctionné. + * @param entity L'entité à créer + * @return L'entité créée */ - Optional save(T entity); + T save(T entity); /** - * Sauvegarde des entités dans la base de données. - *

- * Les sauvegardes seront exécutée si toutes les entités sont valides pour la création. + * Crée plusieurs entités. * - * @param entities La liste d'entités à sauvegarder - * @return Si la sauvegarde a fonctionné. + * @param entities Les entités à créer + * @return Les entités créées */ - @Transactional - boolean saveAll(Iterable entities); + Collection saveAll(Collection entities); /** - * Met à jour une entité dans la base de données. - *

- * La mise à jour sera exécutée si l'entité existe dans la BDD. + * Met à jour une entité dans le stockage. * * @param entity L'entité à mettre à jour - * @return Si la mise à jour a fonctionné. + * @return L'entité mise à jour */ - Optional update(T entity); + T update(T entity); /** - * Supprime une entité dans la base de données. - *

- * La suppression sera exécutée si l'entité existe dans la BDD. + * Supprime une entité. * * @param entity L'entité à supprimer - * @return Si la suppression a fonctionné. */ - boolean delete(T entity); + void delete(T entity); /** - * Supprime des entités dans la base de données. - *

- * Les suppressions seront exécutée si toutes les entités existes dans la BDD. + * Supprime plusieurs entités. * - * @param entities La liste d'entités à supprimer - * @return Si la suppression a fonctionné. + * @param entities Les entités à supprimer */ - @Transactional - boolean deleteAll(List entities); + void deleteAll(List entities); + @Deprecated(since = "1.3.0", forRemoval = true) boolean exists(T entity); + /** + * Vérifie si une entité correspondant à un identifiant existe. + * + * @param id L'identifiant de l'entité + * @return Si un entité correspondant à l'identifiant existe + */ boolean existsById(Long id); } diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/services/model/TouchUpKitService.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/services/TouchUpKitService.java similarity index 93% rename from src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/services/model/TouchUpKitService.java rename to src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/services/TouchUpKitService.java index 92eafed..c72b7d8 100644 --- a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/services/model/TouchUpKitService.java +++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/services/TouchUpKitService.java @@ -1,4 +1,4 @@ -package dev.fyloz.trial.colorrecipesexplorer.core.services.model; +package dev.fyloz.trial.colorrecipesexplorer.core.services; import dev.fyloz.trial.colorrecipesexplorer.core.utils.PdfBuilder; import org.springframework.beans.factory.annotation.Autowired; diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/services/model/MixService.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/services/model/MixService.java index a3568cf..4404afe 100644 --- a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/services/model/MixService.java +++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/services/model/MixService.java @@ -24,7 +24,7 @@ public class MixService extends GenericService { @Autowired public MixService(MixDao mixDao, MaterialService materialService, MixQuantityService mixQuantityService, MixTypeService mixTypeService, RecipeService recipeService) { - super(mixDao); + super(mixDao, Mix.class); this.materialService = materialService; this.mixQuantityService = mixQuantityService; this.mixTypeService = mixTypeService; diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/services/model/RecipeService.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/services/model/RecipeService.java index 99b06ab..43e8c89 100644 --- a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/services/model/RecipeService.java +++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/services/model/RecipeService.java @@ -3,6 +3,7 @@ package dev.fyloz.trial.colorrecipesexplorer.core.services.model; import dev.fyloz.trial.colorrecipesexplorer.core.io.file.FileHandler; import dev.fyloz.trial.colorrecipesexplorer.core.io.file.ImageHandler; import dev.fyloz.trial.colorrecipesexplorer.core.model.*; +import dev.fyloz.trial.colorrecipesexplorer.core.model.dto.RecipeExplorerFormDto; import dev.fyloz.trial.colorrecipesexplorer.core.services.GenericService; import dev.fyloz.trial.colorrecipesexplorer.dao.RecipeDao; import org.springframework.beans.factory.annotation.Autowired; @@ -18,12 +19,14 @@ import java.util.stream.Collectors; public class RecipeService extends GenericService { private CompanyService companyService; + private MixService mixService; private StepService stepService; @Autowired - public RecipeService(RecipeDao recipeDao, CompanyService companyService, StepService stepService) { - super(recipeDao); + public RecipeService(RecipeDao recipeDao, CompanyService companyService, MixService mixService, StepService stepService) { + super(recipeDao, Recipe.class); this.companyService = companyService; + this.mixService = mixService; this.stepService = stepService; } @@ -58,7 +61,7 @@ public class RecipeService extends GenericService { return mappedByCompany(getAll()); } - public Optional updateRecipe(Recipe newRecipe, Recipe storedRecipe, MultiValueMap form) { + public Recipe updateRecipe(Recipe newRecipe, Recipe storedRecipe, MultiValueMap form) { storedRecipe.setName(newRecipe.getName()); storedRecipe.setCompany(newRecipe.getCompany()); storedRecipe.setDescription(newRecipe.getDescription()); @@ -67,18 +70,32 @@ public class RecipeService extends GenericService { storedRecipe.setRemark(newRecipe.getRemark()); storedRecipe.setNote(newRecipe.getNote()); - Optional optionalRecipe = convertAndCreateSteps(storedRecipe, form); - if (optionalRecipe.isEmpty()) { - return Optional.empty(); - } - - return update(optionalRecipe.get()); + return convertAndCreateSteps(storedRecipe, form); } - @Transactional - public boolean deleteRecipe(Recipe recipe) { - if (!delete(recipe)) return false; - return removeAllFiles(recipe); + public void updateRecipeExplorerInfos(RecipeExplorerFormDto form) { + long recipeId = form.getRecipeId(); + Map locations = form.getLocations(); + String note = form.getNote(); + + Recipe recipe = getById(recipeId); + + // Note + recipe.setNote(note); + save(recipe); + + // Casiers + for (Map.Entry location : locations.entrySet()) { + Mix mix = mixService.getById(location.getKey()); + mix.setLocation(location.getValue()); + mixService.update(mix); + } + } + + @Override + public void delete(Recipe recipe) { + super.delete(recipe); + removeAllFiles(recipe); } /** @@ -126,13 +143,6 @@ public class RecipeService extends GenericService { .contains(mixType); } - @Deprecated(since = "1.2.0") - public Map> getRecipesForSearchString(String searchString) { - List recipes = dao.findAllByRecipeDescriptionContainsOrRecipeCodeContains(searchString.toUpperCase()); - - return mappedByCompany(recipes); - } - private Map> mappedByCompany(List recipes) { List companies = companyService.getAll(); Map> mappedRecipes = new HashMap<>(); @@ -156,9 +166,7 @@ public class RecipeService extends GenericService { * @return La recette avec les étapes. */ @Transactional - public Optional convertAndCreateSteps(Recipe recipe, MultiValueMap input) { - if (recipe == null || input == null) return Optional.empty(); - + public Recipe convertAndCreateSteps(Recipe recipe, MultiValueMap input) { // Convertit les étapes en RecipeSteps List steps = new ArrayList<>(); if (input.containsKey("step")) { @@ -174,14 +182,11 @@ public class RecipeService extends GenericService { return setSteps(recipe, steps); } - private Optional setSteps(Recipe recipe, List steps) { - if (!stepService.deleteAll(recipe.getRecipeSteps())) return Optional.empty(); - - recipe.setRecipeSteps(null); - update(recipe); + private Recipe setSteps(Recipe recipe, List steps) { + stepService.deleteAll(recipe.getRecipeSteps()); recipe.setRecipeSteps(steps); - return Optional.of(recipe); + return update(recipe); } private boolean removeAllFiles(Recipe recipe) { diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/RecipeExplorerController.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/RecipeExplorerController.java index 8408abf..b774b7a 100644 --- a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/RecipeExplorerController.java +++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/RecipeExplorerController.java @@ -1,11 +1,13 @@ package dev.fyloz.trial.colorrecipesexplorer.web.controller; +import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.EntityNotFoundException; import dev.fyloz.trial.colorrecipesexplorer.core.io.response.JSONResponseBuilder; import dev.fyloz.trial.colorrecipesexplorer.core.io.response.ModelResponseBuilder; import dev.fyloz.trial.colorrecipesexplorer.core.io.response.ResponseCode; import dev.fyloz.trial.colorrecipesexplorer.core.io.response.ResponseDataType; import dev.fyloz.trial.colorrecipesexplorer.core.model.Mix; import dev.fyloz.trial.colorrecipesexplorer.core.model.Recipe; +import dev.fyloz.trial.colorrecipesexplorer.core.model.dto.RecipeExplorerFormDto; import dev.fyloz.trial.colorrecipesexplorer.core.services.model.MixService; import dev.fyloz.trial.colorrecipesexplorer.core.services.model.RecipeService; import org.springframework.beans.factory.annotation.Autowired; @@ -47,66 +49,47 @@ public class RecipeExplorerController { public ModelAndView getPage(@PathVariable Long id) { ModelResponseBuilder modelResponseBuilder = new ModelResponseBuilder(EXPLORER_RECIPE); - Optional optionalRecipe = recipeService.getById(id); - if (optionalRecipe.isEmpty()) { + try { + Recipe recipe = recipeService.getById(id); + + modelResponseBuilder.addResponseData(ResponseDataType.RECIPE, recipe); + + List mixes = new ArrayList<>(recipe.getMixes()); // Convertit le PersistentBag en ArrayList + mixes.sort(Comparator.comparing(Mix::getId)); + + return modelResponseBuilder + .addResponseData(ResponseDataType.RECIPE, recipe) + .addResponseData(ResponseDataType.MIXES, mixes) + .addResponseData(ResponseDataType.IMAGES, recipeService.getImageFiles(recipe)) + .build(); + } catch (EntityNotFoundException e) { return modelResponseBuilder .withView(INDEX) .addResponseCode(ResponseCode.RECIPE_NOT_FOUND, id) .build(); } - - Recipe recipe = optionalRecipe.get(); - List mixes = new ArrayList<>(recipe.getMixes()); // Convertit le PersistentBag en ArrayList - mixes.sort(Comparator.comparing(Mix::getId)); - - return modelResponseBuilder - .addResponseData(ResponseDataType.RECIPE, recipe) - .addResponseData(ResponseDataType.MIXES, mixes) - .addResponseData(ResponseDataType.IMAGES, recipeService.getImageFiles(recipe)) - .build(); } - // TODO convertir form en DTO @PostMapping(value = EXPLORER_RECIPE, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody - public Map saveRecipeInformations(@RequestBody Map form) { + public Map saveRecipeInformations(RecipeExplorerFormDto form) { JSONResponseBuilder responseBuilder = new JSONResponseBuilder(); + try { - long recipeId = Long.parseLong(form.get("recipeId").toString()); - Map location = (Map) form.get("locations"); - String note = form.get("note").toString(); - - Optional optionalRecipe = recipeService.getById(recipeId); - if (optionalRecipe.isEmpty()) { - responseBuilder.addResponseCode(ResponseCode.RECIPE_NOT_FOUND, recipeId); - } else { - Recipe recipe = optionalRecipe.get(); - - recipe.setNote(note); - recipeService.save(recipe); - } - - for (String mixIdStr : location.keySet()) { - long mixId = Long.parseLong(mixIdStr); - - Optional optionalMix = mixService.getById(mixId); - if (optionalMix.isEmpty()) { - responseBuilder.addResponseCode(ResponseCode.MIX_NOT_FOUND, mixId); - } else { - Mix mix = optionalMix.get(); - - if (mix.getRecipe().getId() != recipeId) { - responseBuilder.addResponseCode(ResponseCode.MIX_NOT_ASSOCIATED_WITH_RECIPE, mixId, recipeId); - } else { - mix.setLocation(location.get(mixIdStr)); - mixService.update(mix); - } - } - } - - if (!responseBuilder.containsErrors()) { responseBuilder.addResponseCode(ResponseCode.SUCCESS_SAVING_RECIPE_INFORMATIONS); + } catch (EntityNotFoundException e) { + ResponseCode responseCode = null; + switch (e.getType().getSimpleName()) { + case "Recipe": + responseCode = ResponseCode.RECIPE_NOT_FOUND; + break; + case "Mix": + responseCode = ResponseCode.MIX_NOT_FOUND; + break; + } + + responseBuilder.addResponseCode(responseCode, e.getRequestedId()); } return responseBuilder.build(); diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/files/TouchUpKitController.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/files/TouchUpKitController.java index 581dd90..a190e34 100644 --- a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/files/TouchUpKitController.java +++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/files/TouchUpKitController.java @@ -3,7 +3,7 @@ package dev.fyloz.trial.colorrecipesexplorer.web.controller.files; import dev.fyloz.trial.colorrecipesexplorer.core.io.response.ModelResponseBuilder; import dev.fyloz.trial.colorrecipesexplorer.core.io.response.ResponseDataType; import dev.fyloz.trial.colorrecipesexplorer.core.services.model.RecipeService; -import dev.fyloz.trial.colorrecipesexplorer.core.services.model.TouchUpKitService; +import dev.fyloz.trial.colorrecipesexplorer.core.services.TouchUpKitService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; diff --git a/src/main/resources/updates.md b/src/main/resources/updates.md index f7cd2d9..9b2a816 100644 --- a/src/main/resources/updates.md +++ b/src/main/resources/updates.md @@ -1,7 +1,7 @@ # v1.3.0 (Optimisations back-end) ### Note: Cette mise à jour n'est pas compatible avec les anciennes versions. ### Corrections -* Reusinage des modèles. (Empêche la compatibilité avec les anciennes versions) +* Réusinage des modèles. (Empêche la compatibilité avec les anciennes versions) # v1.2.0 (Imprimante P-touch) ### Corrections