Добавлена возможность создания ингредиентов
This commit is contained in:
@@ -9,6 +9,8 @@ import lombok.Setter;
|
|||||||
import javax.persistence.CascadeType;
|
import javax.persistence.CascadeType;
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.GenerationType;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
import javax.persistence.JoinColumn;
|
import javax.persistence.JoinColumn;
|
||||||
import javax.persistence.JoinTable;
|
import javax.persistence.JoinTable;
|
||||||
@@ -28,6 +30,7 @@ import java.util.List;
|
|||||||
public class IngredientEntity {
|
public class IngredientEntity {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
private Long id;
|
private Long id;
|
||||||
private String name;
|
private String name;
|
||||||
private String enName;
|
private String enName;
|
||||||
|
|||||||
@@ -90,14 +90,16 @@ public class IngredientService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean saveChange(IngredientResponseDto dto) {
|
public boolean saveChange(IngredientResponseDto dto) {
|
||||||
|
IngredientEntity entity;
|
||||||
if (dto.getId() == null) {
|
if (dto.getId() == null) {
|
||||||
return false;
|
entity = new IngredientEntity();
|
||||||
}
|
} else {
|
||||||
IngredientEntity entity = repository.findById(dto.getId())
|
entity = repository.findById(dto.getId())
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
if (entity == null) {
|
if (entity == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
entity.setName(dto.getName());
|
entity.setName(dto.getName());
|
||||||
entity.setDescription(dto.getDescription());
|
entity.setDescription(dto.getDescription());
|
||||||
@@ -105,12 +107,12 @@ public class IngredientService {
|
|||||||
entity.setAlcohol(dto.getAlcohol());
|
entity.setAlcohol(dto.getAlcohol());
|
||||||
|
|
||||||
TypeEntity type = findTypeByName(dto.getType());
|
TypeEntity type = findTypeByName(dto.getType());
|
||||||
if (type == null) {
|
// if (type == null) {
|
||||||
return false;
|
// return false;
|
||||||
}
|
// }
|
||||||
entity.setType(type);
|
entity.setType(type);
|
||||||
repository.save(entity);
|
repository.save(entity);
|
||||||
log.info("Ингредиент {} изменен", entity.getName());
|
log.info("Ингредиент {} {}", entity.getName(), dto.getId() == null ? "создан" : "изменен");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user