Skip to content

Commit

Permalink
add bean, repository, service
Browse files Browse the repository at this point in the history
  • Loading branch information
yennanliu committed Nov 27, 2023
1 parent 2b67947 commit 2e527c9
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ShoppingCart/Backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
<artifactId>springfox-swagger-ui</artifactId>
<version>2.7.0</version>
</dependency>

<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ public void addCorsMappings(CorsRegistry registry) {
.maxAge(3600)
.allowCredentials(true);
}

}
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 +
'}';
}

}
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> {

}
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;
}

0 comments on commit 2e527c9

Please sign in to comment.