Skip to content

Commit fc8280f

Browse files
exercise 2 sol
1 parent 789755d commit fc8280f

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

src/main/java/com/amigoscode/Main.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,26 @@ public static void main(String[] args) {
2121
public CommandLineRunner commandLineRunner(
2222
ProductRepository productRepository) {
2323
return args -> {
24-
Product product = new Product();
25-
product.setName("Macbook Pro");
26-
product.setDescription("Macbook Pro M4");
27-
product.setPrice(new BigDecimal(3000));
28-
product.setId(UUID.fromString(
24+
Product product1 = new Product();
25+
product1.setName("Macbook Pro");
26+
product1.setDescription("Macbook Pro M4");
27+
product1.setPrice(new BigDecimal(3000));
28+
product1.setId(UUID.fromString(
2929
"d95062e6-9f0b-4224-bc9d-d0723949848f")
3030
);
31-
product.setStockLevel(100);
32-
productRepository.save(product);
31+
product1.setStockLevel(100);
32+
productRepository.save(product1);
33+
34+
Product product2 = new Product();
35+
product2.setId(UUID.fromString(
36+
"94d2cc8a-ad09-4902-a321-a6bf658e2463"
37+
));
38+
product2.setName("Mouse");
39+
product2.setDescription("LG Mouse");
40+
product2.setPrice(new BigDecimal(78));
41+
product2.setStockLevel(1000);
42+
43+
productRepository.save(product2);
3344
};
3445
}
3546

src/main/java/com/amigoscode/product/Product.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public class Product {
3838

3939
private Instant deletedAt;
4040

41+
private Boolean isPublished = true;
42+
4143
public Product() {
4244
}
4345

@@ -141,11 +143,19 @@ public void setDeletedAt(Instant deletedAt) {
141143
this.deletedAt = deletedAt;
142144
}
143145

146+
public Boolean getPublished() {
147+
return isPublished;
148+
}
149+
150+
public void setPublished(Boolean published) {
151+
isPublished = published;
152+
}
153+
144154
@Override
145155
public boolean equals(Object o) {
146156
if (o == null || getClass() != o.getClass()) return false;
147157
Product product = (Product) o;
148-
return stockLevel == product.stockLevel && Objects.equals(id, product.id) && Objects.equals(name, product.name) && Objects.equals(description, product.description) && Objects.equals(price, product.price) && Objects.equals(imageUrl, product.imageUrl) && Objects.equals(createdAt, product.createdAt) && Objects.equals(updatedAt, product.updatedAt) && Objects.equals(deletedAt, product.deletedAt);
158+
return Objects.equals(stockLevel, product.stockLevel) && Objects.equals(id, product.id) && Objects.equals(name, product.name) && Objects.equals(description, product.description) && Objects.equals(price, product.price) && Objects.equals(imageUrl, product.imageUrl) && Objects.equals(createdAt, product.createdAt) && Objects.equals(updatedAt, product.updatedAt) && Objects.equals(deletedAt, product.deletedAt);
149159
}
150160

151161
@Override
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ALTER TABLE product
2+
ALTER COLUMN is_published
3+
SET NOT NULL;

0 commit comments

Comments
 (0)