Skip to content

Commit 6811cd8

Browse files
committed
refactor: removes quantity attribute from product table
1 parent 5a8752f commit 6811cd8

File tree

6 files changed

+17
-35
lines changed

6 files changed

+17
-35
lines changed

db/01-create-tables.sql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ create table if not exists prd_product
7777
(
7878
deleted boolean not null,
7979
price double precision not null,
80-
quantity double precision not null,
8180
category bigint not null
8281
constraint fk_product_category
8382
references cat_category,

db/03-insert-example-data.sql

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
-- Registros para a categoria 'Lanche'
2-
INSERT INTO prd_product (deleted, price, quantity, category, creation_date, last_update_date, name)
3-
VALUES (false, 10.99, 5, (SELECT id FROM cat_category WHERE name = 'Lanche'), NOW(), NOW(), 'Hambúrguer');
2+
INSERT INTO prd_product (deleted, price, category, creation_date, last_update_date, name)
3+
VALUES (false, 10.99, (SELECT id FROM cat_category WHERE name = 'Lanche'), NOW(), NOW(), 'Hambúrguer');
44

5-
INSERT INTO prd_product (deleted, price, quantity, category, creation_date, last_update_date, name)
6-
VALUES (false, 8.99, 3, (SELECT id FROM cat_category WHERE name = 'Lanche'), NOW(), NOW(), 'Sanduíche de Frango');
5+
INSERT INTO prd_product (deleted, price, category, creation_date, last_update_date, name)
6+
VALUES (false, 8.99, (SELECT id FROM cat_category WHERE name = 'Lanche'), NOW(), NOW(), 'Sanduíche de Frango');
77

88
-- Registros para a categoria 'Acompanhamento'
9-
INSERT INTO prd_product (deleted, price, quantity, category, creation_date, last_update_date, name)
10-
VALUES (false, 3.99, 10, (SELECT id FROM cat_category WHERE name = 'Acompanhamento'), NOW(), NOW(), 'Batata Frita');
9+
INSERT INTO prd_product (deleted, price, category, creation_date, last_update_date, name)
10+
VALUES (false, 3.99, (SELECT id FROM cat_category WHERE name = 'Acompanhamento'), NOW(), NOW(), 'Batata Frita');
1111

12-
INSERT INTO prd_product (deleted, price, quantity, category, creation_date, last_update_date, name)
13-
VALUES (false, 2.99, 8, (SELECT id FROM cat_category WHERE name = 'Acompanhamento'), NOW(), NOW(), 'Nuggets');
12+
INSERT INTO prd_product (deleted, price, category, creation_date, last_update_date, name)
13+
VALUES (false, 2.99, (SELECT id FROM cat_category WHERE name = 'Acompanhamento'), NOW(), NOW(), 'Nuggets');
1414

1515
-- Registros para a categoria 'Bebida'
16-
INSERT INTO prd_product (deleted, price, quantity, category, creation_date, last_update_date, name)
17-
VALUES (false, 4.99, 20, (SELECT id FROM cat_category WHERE name = 'Bebida'), NOW(), NOW(), 'Refrigerante');
16+
INSERT INTO prd_product (deleted, price, category, creation_date, last_update_date, name)
17+
VALUES (false, 4.99, (SELECT id FROM cat_category WHERE name = 'Bebida'), NOW(), NOW(), 'Refrigerante');
1818

19-
INSERT INTO prd_product (deleted, price, quantity, category, creation_date, last_update_date, name)
20-
VALUES (false, 2.49, 15, (SELECT id FROM cat_category WHERE name = 'Bebida'), NOW(), NOW(), 'Suco');
19+
INSERT INTO prd_product (deleted, price, category, creation_date, last_update_date, name)
20+
VALUES (false, 2.49, (SELECT id FROM cat_category WHERE name = 'Bebida'), NOW(), NOW(), 'Suco');
2121

2222
-- Registros para a categoria 'Sobremesa'
23-
INSERT INTO prd_product (deleted, price, quantity, category, creation_date, last_update_date, name)
24-
VALUES (false, 6.99, 5, (SELECT id FROM cat_category WHERE name = 'Sobremesa'), NOW(), NOW(), 'Sorvete');
23+
INSERT INTO prd_product (deleted, price, category, creation_date, last_update_date, name)
24+
VALUES (false, 6.99, (SELECT id FROM cat_category WHERE name = 'Sobremesa'), NOW(), NOW(), 'Sorvete');
2525

26-
INSERT INTO prd_product (deleted, price, quantity, category, creation_date, last_update_date, name)
27-
VALUES (false, 4.49, 3, (SELECT id FROM cat_category WHERE name = 'Sobremesa'), NOW(), NOW(), 'Bolo de Chocolate');
26+
INSERT INTO prd_product (deleted, price, category, creation_date, last_update_date, name)
27+
VALUES (false, 4.49, (SELECT id FROM cat_category WHERE name = 'Sobremesa'), NOW(), NOW(), 'Bolo de Chocolate');

techchallenge/src/main/java/br/com/grupo63/techchallenge/adapter/out/repository/product/entity/ProductEntity.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ public class ProductEntity extends DomainEntity {
2727
@Column(name = "price", nullable = false)
2828
private Double price;
2929

30-
@Basic
31-
@Column(name = "quantity", nullable = false)
32-
private Double quantity;
33-
3430
@JoinColumn(name = "category", foreignKey = @ForeignKey(name = "fk_product_category"), nullable = false)
3531
@ManyToOne(cascade = {CascadeType.DETACH, CascadeType.REFRESH}, fetch = FetchType.EAGER)
3632
private CategoryEntity category;
@@ -39,7 +35,6 @@ public ProductEntity(Product product) {
3935
super(product);
4036
this.name = product.getName();
4137
this.price = product.getPrice();
42-
this.quantity = product.getQuantity();
4338
if (product.getCategory() != null)
4439
this.category = new CategoryEntity(product.getCategory());
4540
}
@@ -49,7 +44,6 @@ public Product toModel() {
4944
this.isDeleted(),
5045
this.getName(),
5146
this.getPrice(),
52-
this.getQuantity(),
5347
this.getCategory() != null ? this.getCategory().toModel() : null);
5448
}
5549
}

techchallenge/src/main/java/br/com/grupo63/techchallenge/core/application/usecase/dto/ProductDTO.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ public class ProductDTO extends AbstractUseCaseDomainDTO<Product> {
2828
@Min(message = "product.price.notLessThanZero", value = 0)
2929
private Double price;
3030

31-
@Schema(example = "10.0")
32-
@NotNull(message = "product.quantity.notNull")
33-
@Min(message = "product.quantity.notLessThanZero", value = 0)
34-
private Double quantity;
35-
3631
@Schema(example = "1")
3732
@NotNull(message = "product.category.notNull")
3833
@Min(message = "product.category.notLessThanOne", value = 1)
@@ -44,7 +39,6 @@ public static ProductDTO toDto(Product product) {
4439
productDTO.setId(product.getId());
4540
productDTO.setName(product.getName());
4641
productDTO.setPrice(product.getPrice());
47-
productDTO.setQuantity(product.getQuantity());
4842
productDTO.setCategory(product.getCategory().getId());
4943

5044
return productDTO;
@@ -53,7 +47,6 @@ public static ProductDTO toDto(Product product) {
5347
public void fillDomain(Product product) {
5448
product.setName(name);
5549
product.setPrice(price);
56-
product.setQuantity(quantity);
5750
product.setCategory(new Category(category));
5851
}
5952
}

techchallenge/src/main/java/br/com/grupo63/techchallenge/core/domain/model/product/Product.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,16 @@ public class Product extends Domain {
1616

1717
private String name;
1818
private Double price;
19-
private Double quantity; // (stock)
2019
private Category category;
2120

2221
public Product(Long id) {
2322
this.id = id;
2423
}
2524

26-
public Product(Long id, boolean deleted, String name, Double price, Double quantity, Category category) {
25+
public Product(Long id, boolean deleted, String name, Double price, Category category) {
2726
super(id, deleted);
2827
this.name = name;
2928
this.price = price;
30-
this.quantity = quantity;
3129
this.category = category;
3230
}
3331
}

techchallenge/src/main/resources/messages_pt_BR.properties

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,5 @@ product.name.notEmpty=O nome é obrigatório
2525
product.name.notNull=O nome é obrigatório
2626
product.price.notNull=O preço é obrigatório
2727
product.price.notLessThanZero=O preço precisa ser maior que 0
28-
product.quantity.notNull=A quantidade precisa ser maior que 0
29-
product.quantity.notLessThanZero=A quantidade precisa ser maior que 0
3028
product.category.notNull=A categoria precisa estar registrada
3129
product.category.notLessThanOne=A categoria precisa estar registrada

0 commit comments

Comments
 (0)