Ajout de equals/hashcode corrects dans le modèle.
Correction: Aucun message d'erreur lors de la création d'un mélange.
This commit is contained in:
parent
73f6a97a21
commit
12433c353c
|
@ -6,10 +6,10 @@ import org.hibernate.validator.constraints.Length;
|
|||
import javax.persistence.*;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
|
||||
@Entity
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@NoArgsConstructor
|
||||
@RequiredArgsConstructor
|
||||
@AllArgsConstructor
|
||||
|
@ -24,4 +24,17 @@ public class Company implements IModel {
|
|||
@Length(min = 2, max = 50)
|
||||
@Column(unique = true)
|
||||
private String name;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Company company = (Company) o;
|
||||
return Objects.equals(name, company.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(name);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,12 +43,11 @@ public class Material implements IModel {
|
|||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Material material = (Material) o;
|
||||
return Objects.equals(id, material.id) &&
|
||||
Objects.equals(name, material.name);
|
||||
return Objects.equals(name, material.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id, name);
|
||||
return Objects.hash(name);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,10 +5,10 @@ import lombok.*;
|
|||
import javax.persistence.*;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@Entity
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@RequiredArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class Mix implements IModel {
|
||||
|
@ -37,4 +37,18 @@ public class Mix implements IModel {
|
|||
|
||||
// Casier
|
||||
private String location;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Mix mix = (Mix) o;
|
||||
return Objects.equals(recipe, mix.recipe) &&
|
||||
Objects.equals(mixType, mix.mixType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(recipe, mixType);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,10 +5,10 @@ import lombok.*;
|
|||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.Objects;
|
||||
|
||||
@Entity
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@RequiredArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class MixQuantity implements IModel {
|
||||
|
@ -32,4 +32,19 @@ public class MixQuantity implements IModel {
|
|||
@NonNull
|
||||
@NotNull
|
||||
private Float quantity;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
MixQuantity that = (MixQuantity) o;
|
||||
return Objects.equals(mix, that.mix) &&
|
||||
Objects.equals(material, that.material) &&
|
||||
Objects.equals(quantity, that.quantity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(mix, material, quantity);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,15 +6,11 @@ import org.hibernate.validator.constraints.Length;
|
|||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Entity
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@RequiredArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class Recipe implements IModel {
|
||||
|
@ -100,4 +96,17 @@ public class Recipe implements IModel {
|
|||
return getMixTypes().contains(mixType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Recipe recipe = (Recipe) o;
|
||||
return Objects.equals(name, recipe.name) &&
|
||||
Objects.equals(company, recipe.company);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(name, company);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,10 +6,10 @@ import lombok.*;
|
|||
import javax.persistence.*;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
|
||||
@Entity
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@RequiredArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class RecipeStep implements IModel {
|
||||
|
@ -19,7 +19,6 @@ public class RecipeStep implements IModel {
|
|||
private Long id;
|
||||
|
||||
@NonNull
|
||||
@ToString.Exclude
|
||||
@JsonIgnore
|
||||
@ManyToOne
|
||||
private Recipe recipe;
|
||||
|
@ -27,4 +26,18 @@ public class RecipeStep implements IModel {
|
|||
@NonNull
|
||||
@NotNull
|
||||
private String message;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
RecipeStep that = (RecipeStep) o;
|
||||
return Objects.equals(recipe, that.recipe) &&
|
||||
Objects.equals(message, that.message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(recipe, message);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@ import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.ModelException;
|
|||
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.MixType;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.Recipe;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.dto.MixFormDto;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.model.*;
|
||||
|
@ -74,9 +76,9 @@ public class MixCreatorController {
|
|||
} catch (EntityNotFoundException ex) {
|
||||
modelResponseBuilder.addResponseCode(ResponseCode.MATERIAL_NOT_FOUND, ex.getRequestedId());
|
||||
} catch (EntityAlreadyExistsException ex) {
|
||||
if (ex.getIdentifierName().equals(ModelException.IdentifierType.NAME.getName()))
|
||||
if (ex.getIdentifierName().equals(Mix.IDENTIFIER_MIX_TYPE_NAME))
|
||||
modelResponseBuilder.addResponseCode(ResponseCode.MIX_TYPE_ALREADY_USED, ex.getRequestedId());
|
||||
else if (ex.getIdentifierName().equals("materialName"))
|
||||
else if (ex.getIdentifierName().equals(MixType.IDENTIFIER_MATERIAL_NAME))
|
||||
modelResponseBuilder.addResponseCode(ResponseCode.MATERIAL_AND_MIX_TYPE_CANNOT_HAVE_SAME_NAME);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue