in process....
This commit is contained in:
parent
d09f2ec19c
commit
19fad7ac71
@ -41,3 +41,7 @@ dependencies {
|
|||||||
tasks.named('test') {
|
tasks.named('test') {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bootRun {
|
||||||
|
args = ['--populate']
|
||||||
|
}
|
@ -47,12 +47,12 @@ public class DemoApplication implements CommandLineRunner {
|
|||||||
final var type3 = typeService.create(new TypeEntity("Сырная"));
|
final var type3 = typeService.create(new TypeEntity("Сырная"));
|
||||||
|
|
||||||
log.info("Create default product values");
|
log.info("Create default product values");
|
||||||
final var product1 = productService.create(new ProductEntity("test", type1, 399.00, 15));
|
final var product1 = productService.create(new ProductEntity("test", type1, 399.00));
|
||||||
final var product2 = productService.create(new ProductEntity("test", type1, 499.00, 10));
|
final var product2 = productService.create(new ProductEntity("test", type1, 499.00));
|
||||||
final var product3 = productService.create(new ProductEntity("test", type2, 450.50, 5));
|
final var product3 = productService.create(new ProductEntity("test", type2, 450.50));
|
||||||
final var product4 = productService.create(new ProductEntity("test", type2, 900.50, 6));
|
final var product4 = productService.create(new ProductEntity("test", type2, 900.50));
|
||||||
final var product5 = productService.create(new ProductEntity("test", type2, 600.00, 8));
|
final var product5 = productService.create(new ProductEntity("test", type2, 600.00));
|
||||||
final var product6 = productService.create(new ProductEntity("test", type3, 750.00, 9));
|
final var product6 = productService.create(new ProductEntity("test", type3, 750.00));
|
||||||
|
|
||||||
log.info("Create default user values");
|
log.info("Create default user values");
|
||||||
final var user1 = userService.create(new UserEntity("kruviii", "Павел", "Крылов", "test@test.ru", "11-11-2023", "+79876543210", "qwerty123"));
|
final var user1 = userService.create(new UserEntity("kruviii", "Павел", "Крылов", "test@test.ru", "11-11-2023", "+79876543210", "qwerty123"));
|
||||||
|
@ -81,7 +81,7 @@ public class OrderService {
|
|||||||
public List<ProductEntity> getOrderProducts(long userId, long id) {
|
public List<ProductEntity> getOrderProducts(long userId, long id) {
|
||||||
userService.get(userId);
|
userService.get(userId);
|
||||||
return get(userId, id).getOrderProducts().stream()
|
return get(userId, id).getOrderProducts().stream()
|
||||||
.map(OrderProductEntity::getProduct)
|
.map(orderProduct -> orderProduct.getProduct())
|
||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,7 +114,7 @@ public class OrderService {
|
|||||||
result.forEach(product -> {
|
result.forEach(product -> {
|
||||||
final OrderProductEntity orderProduct = new OrderProductEntity(existsOrder, product, productsIdsCount.get(product.getId()));
|
final OrderProductEntity orderProduct = new OrderProductEntity(existsOrder, product, productsIdsCount.get(product.getId()));
|
||||||
orderProduct.setOrder(existsOrder);
|
orderProduct.setOrder(existsOrder);
|
||||||
orderProduct.setProduct(product);
|
// orderProduct.setProduct(product);
|
||||||
});
|
});
|
||||||
repository.save(existsOrder);
|
repository.save(existsOrder);
|
||||||
return result;
|
return result;
|
||||||
|
@ -61,13 +61,6 @@ public class OrderProductEntity {
|
|||||||
return product;
|
return product;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setProduct(ProductEntity product) {
|
|
||||||
this.product = product;
|
|
||||||
if (!product.getOrderProducts().contains(this)) {
|
|
||||||
product.getOrderProducts().add(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getCount() {
|
public Integer getCount() {
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
@ -17,9 +17,6 @@ public class ProductDto {
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Min(1)
|
@Min(1)
|
||||||
private Double price;
|
private Double price;
|
||||||
@NotNull
|
|
||||||
@Min(0)
|
|
||||||
private Integer count;
|
|
||||||
|
|
||||||
public Long getId() {
|
public Long getId() {
|
||||||
return id;
|
return id;
|
||||||
@ -52,12 +49,4 @@ public class ProductDto {
|
|||||||
public void setPrice(Double price) {
|
public void setPrice(Double price) {
|
||||||
this.price = price;
|
this.price = price;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getCount() {
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCount(Integer count) {
|
|
||||||
this.count = count;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
package com.example.demo.product.model;
|
package com.example.demo.product.model;
|
||||||
|
|
||||||
import java.util.HashSet;
|
// import java.util.HashSet;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
// import java.util.Set;
|
||||||
|
|
||||||
import com.example.demo.types.model.TypeEntity;
|
import com.example.demo.types.model.TypeEntity;
|
||||||
import com.example.demo.ordersproducts.model.OrderProductEntity;
|
// import com.example.demo.ordersproducts.model.OrderProductEntity;
|
||||||
import com.example.demo.core.model.BaseEntity;
|
import com.example.demo.core.model.BaseEntity;
|
||||||
|
|
||||||
import jakarta.persistence.Column;
|
import jakarta.persistence.Column;
|
||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import jakarta.persistence.OneToMany;
|
// import jakarta.persistence.OneToMany;
|
||||||
import jakarta.persistence.OrderBy;
|
// import jakarta.persistence.OrderBy;
|
||||||
import jakarta.persistence.JoinColumn;
|
import jakarta.persistence.JoinColumn;
|
||||||
import jakarta.persistence.ManyToOne;
|
import jakarta.persistence.ManyToOne;
|
||||||
import jakarta.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
@ -26,21 +26,18 @@ public class ProductEntity extends BaseEntity {
|
|||||||
private TypeEntity type;
|
private TypeEntity type;
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private Double price;
|
private Double price;
|
||||||
@Column(nullable = false)
|
|
||||||
private Integer count;
|
|
||||||
|
|
||||||
@OneToMany(mappedBy = "product")
|
// @OneToMany(mappedBy = "product")
|
||||||
@OrderBy("id ASC")
|
// @OrderBy("id ASC")
|
||||||
private Set<OrderProductEntity> orderProducts = new HashSet<>();
|
// private Set<OrderProductEntity> orderProducts = new HashSet<>();
|
||||||
|
|
||||||
public ProductEntity() {
|
public ProductEntity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProductEntity(String name, TypeEntity type, Double price, Integer count) {
|
public ProductEntity(String name, TypeEntity type, Double price) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.price = price;
|
this.price = price;
|
||||||
this.count = count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
@ -67,28 +64,20 @@ public class ProductEntity extends BaseEntity {
|
|||||||
this.price = price;
|
this.price = price;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getCount() {
|
// public Set<OrderProductEntity> getOrderProducts() {
|
||||||
return count;
|
// return orderProducts;
|
||||||
}
|
// }
|
||||||
|
|
||||||
public void setCount(Integer count) {
|
// public void addOrder(OrderProductEntity orderProduct) {
|
||||||
this.count = count;
|
// if (orderProduct.getProduct() != this) {
|
||||||
}
|
// orderProduct.setProduct(this);
|
||||||
|
// }
|
||||||
public Set<OrderProductEntity> getOrderProducts() {
|
// orderProducts.add(orderProduct);
|
||||||
return orderProducts;
|
// }
|
||||||
}
|
|
||||||
|
|
||||||
public void addOrder(OrderProductEntity orderProduct) {
|
|
||||||
if (orderProduct.getProduct() != this) {
|
|
||||||
orderProduct.setProduct(this);
|
|
||||||
}
|
|
||||||
orderProducts.add(orderProduct);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hash(id, name, type, price, count, orderProducts);
|
return Objects.hash(id, name, type, price/* , orderProducts*/);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -101,8 +90,7 @@ public class ProductEntity extends BaseEntity {
|
|||||||
return Objects.equals(other.getId(), id)
|
return Objects.equals(other.getId(), id)
|
||||||
&& Objects.equals(other.getName(), name)
|
&& Objects.equals(other.getName(), name)
|
||||||
&& Objects.equals(other.getType(), type)
|
&& Objects.equals(other.getType(), type)
|
||||||
&& Objects.equals(other.getPrice(), price)
|
&& Objects.equals(other.getPrice(), price);
|
||||||
&& Objects.equals(other.getCount(), count)
|
// && Objects.equals(other.getOrderProducts(), orderProducts);
|
||||||
&& Objects.equals(other.getOrderProducts(), orderProducts);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,6 @@ public class ProductService {
|
|||||||
existsEntity.setName(entity.getName());
|
existsEntity.setName(entity.getName());
|
||||||
existsEntity.setType(entity.getType());
|
existsEntity.setType(entity.getType());
|
||||||
existsEntity.setPrice(entity.getPrice());
|
existsEntity.setPrice(entity.getPrice());
|
||||||
existsEntity.setCount(entity.getCount());
|
|
||||||
return repository.save(existsEntity);
|
return repository.save(existsEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,9 +49,9 @@ public class OrderServiceTests {
|
|||||||
removeData();
|
removeData();
|
||||||
|
|
||||||
final var type = typeService.create(new TypeEntity("Пепперони"));
|
final var type = typeService.create(new TypeEntity("Пепперони"));
|
||||||
product1 = productService.create(new ProductEntity("test1", type, 399.00, 15));
|
product1 = productService.create(new ProductEntity("test1", type, 399.00));
|
||||||
product2 = productService.create(new ProductEntity("test2", type, 499.00, 10));
|
product2 = productService.create(new ProductEntity("test2", type, 499.00));
|
||||||
product3 = productService.create(new ProductEntity("test3", type, 450.50, 5));
|
product3 = productService.create(new ProductEntity("test3", type, 450.50));
|
||||||
user = userService.create(new UserEntity("kruviii", "Павел", "Крылов", "test@test.ru", "11-11-2023", "+79876543210", "qwerty123"));
|
user = userService.create(new UserEntity("kruviii", "Павел", "Крылов", "test@test.ru", "11-11-2023", "+79876543210", "qwerty123"));
|
||||||
order = orderService.create(user.getId(), new OrderEntity("ул. Северный венец, 32"));
|
order = orderService.create(user.getId(), new OrderEntity("ул. Северный венец, 32"));
|
||||||
orderService.create(user.getId(), new OrderEntity("ул. Северный венец, 32"));
|
orderService.create(user.getId(), new OrderEntity("ул. Северный венец, 32"));
|
||||||
@ -116,7 +116,7 @@ public class OrderServiceTests {
|
|||||||
@Test
|
@Test
|
||||||
void AddOrderProductsTest() {
|
void AddOrderProductsTest() {
|
||||||
final var type = typeService.create(new TypeEntity("3 сыра"));
|
final var type = typeService.create(new TypeEntity("3 сыра"));
|
||||||
final var product = productService.create(new ProductEntity("test1", type, 100.00, 5));
|
final var product = productService.create(new ProductEntity("test1", type, 100.00));
|
||||||
Assertions.assertEquals(3, orderService.getOrderProducts(user.getId(), order.getId()).size());
|
Assertions.assertEquals(3, orderService.getOrderProducts(user.getId(), order.getId()).size());
|
||||||
orderService.addOrderProducts(user.getId(), order.getId(), Map.of(product.getId(), 5));
|
orderService.addOrderProducts(user.getId(), order.getId(), Map.of(product.getId(), 5));
|
||||||
Assertions.assertEquals(4, orderService.getOrderProducts(user.getId(), order.getId()).size());
|
Assertions.assertEquals(4, orderService.getOrderProducts(user.getId(), order.getId()).size());
|
||||||
|
@ -37,9 +37,9 @@ class ProductsServiceTests {
|
|||||||
final var type3 = typeService.create(new TypeEntity("Сырная"));
|
final var type3 = typeService.create(new TypeEntity("Сырная"));
|
||||||
|
|
||||||
|
|
||||||
product = productService.create(new ProductEntity("test", type, 399.00, 15));
|
product = productService.create(new ProductEntity("test", type, 399.00));
|
||||||
productService.create(new ProductEntity("test", type2, 499.00, 10));
|
productService.create(new ProductEntity("test", type2, 499.00));
|
||||||
productService.create(new ProductEntity("test", type3, 450.50, 5));
|
productService.create(new ProductEntity("test", type3, 450.50));
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterEach
|
@AfterEach
|
||||||
@ -62,7 +62,7 @@ class ProductsServiceTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void createNullableTest() {
|
void createNullableTest() {
|
||||||
final ProductEntity nullableProduct = new ProductEntity(null, type, 399.00, 15);;
|
final ProductEntity nullableProduct = new ProductEntity(null, type, 399.00);;
|
||||||
Assertions.assertThrows(DataIntegrityViolationException.class, () -> productService.create(nullableProduct));
|
Assertions.assertThrows(DataIntegrityViolationException.class, () -> productService.create(nullableProduct));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,7 +72,7 @@ class ProductsServiceTests {
|
|||||||
final String test = "TEST";
|
final String test = "TEST";
|
||||||
final TypeEntity newType = typeService.create(new TypeEntity("Фреш"));
|
final TypeEntity newType = typeService.create(new TypeEntity("Фреш"));
|
||||||
final TypeEntity oldType = product.getType();
|
final TypeEntity oldType = product.getType();
|
||||||
final ProductEntity newEntity = productService.update(product.getId(), new ProductEntity(test, newType, 100.00, 15));
|
final ProductEntity newEntity = productService.update(product.getId(), new ProductEntity(test, newType, 100.00));
|
||||||
Assertions.assertEquals(3, productService.getAll(0L).size());
|
Assertions.assertEquals(3, productService.getAll(0L).size());
|
||||||
Assertions.assertEquals(newEntity, productService.get(product.getId()));
|
Assertions.assertEquals(newEntity, productService.get(product.getId()));
|
||||||
Assertions.assertEquals(test, newEntity.getName());
|
Assertions.assertEquals(test, newEntity.getName());
|
||||||
@ -85,7 +85,7 @@ class ProductsServiceTests {
|
|||||||
productService.delete(product.getId());
|
productService.delete(product.getId());
|
||||||
Assertions.assertEquals(2, productService.getAll(0L).size());
|
Assertions.assertEquals(2, productService.getAll(0L).size());
|
||||||
|
|
||||||
final ProductEntity newEntity = productService.create(new ProductEntity(product.getName(), product.getType(), product.getPrice(), product.getCount()));
|
final ProductEntity newEntity = productService.create(new ProductEntity(product.getName(), product.getType(), product.getPrice()));
|
||||||
Assertions.assertEquals(3, typeService.getAll().size());
|
Assertions.assertEquals(3, typeService.getAll().size());
|
||||||
Assertions.assertNotEquals(product.getId(), newEntity.getId());
|
Assertions.assertNotEquals(product.getId(), newEntity.getId());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user