-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
119 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,5 @@ public void addCorsMappings(CorsRegistry registry) { | |
.maxAge(3600) | ||
.allowCredentials(true); | ||
} | ||
|
||
} |
95 changes: 95 additions & 0 deletions
95
ShoppingCart/Backend/src/main/java/com/yen/ShoppingCart/model/Product.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package com.yen.ShoppingCart.model; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
import com.sun.istack.NotNull; | ||
|
||
import javax.persistence.*; | ||
|
||
@Entity | ||
@Table(name = "products") | ||
public class Product { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Integer id; | ||
|
||
private @NotNull String name; | ||
private @NotNull String imageURL; | ||
private @NotNull double price; | ||
private @NotNull String description; | ||
|
||
@JsonIgnore | ||
@ManyToOne(fetch = FetchType.LAZY, optional = false) | ||
@JoinColumn(name = "category_id", nullable = false) | ||
Category category; | ||
|
||
public Product(String name, String imageURL, double price, String description, Category category) { | ||
super(); | ||
this.name = name; | ||
this.imageURL = imageURL; | ||
this.price = price; | ||
this.description = description; | ||
this.category = category; | ||
} | ||
|
||
public Integer getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Integer id) { | ||
this.id = id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getImageURL() { | ||
return imageURL; | ||
} | ||
|
||
public void setImageURL(String imageURL) { | ||
this.imageURL = imageURL; | ||
} | ||
|
||
public double getPrice() { | ||
return price; | ||
} | ||
|
||
public void setPrice(double price) { | ||
this.price = price; | ||
} | ||
|
||
public String getDescription() { | ||
return description; | ||
} | ||
|
||
public void setDescription(String description) { | ||
this.description = description; | ||
} | ||
|
||
public Category getCategory() { | ||
return category; | ||
} | ||
|
||
public void setCategory(Category category) { | ||
this.category = category; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Product{" + | ||
"id=" + id + | ||
", name='" + name + '\'' + | ||
", imageURL='" + imageURL + '\'' + | ||
", price=" + price + | ||
", description='" + description + '\'' + | ||
", category=" + category + | ||
'}'; | ||
} | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
ShoppingCart/Backend/src/main/java/com/yen/ShoppingCart/repository/ProductRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.yen.ShoppingCart.repository; | ||
|
||
import com.yen.ShoppingCart.model.Product; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface ProductRepository extends JpaRepository<Product, Integer> { | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
ShoppingCart/Backend/src/main/java/com/yen/ShoppingCart/service/ProductService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.yen.ShoppingCart.service; | ||
|
||
import com.yen.ShoppingCart.repository.ProductRepository; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class ProductService { | ||
|
||
@Autowired | ||
private ProductRepository productRepository; | ||
} |