Browse Source
cart services added and not tested along with this uer services are tested and they are working fine
gauravMain
cart services added and not tested along with this uer services are tested and they are working fine
gauravMain
5 changed files with 203 additions and 28 deletions
Unified View
Diff Options
-
39src/main/java/com/example/urbanbazaar/Controller/CartController.java
-
69src/main/java/com/example/urbanbazaar/Controller/UserController.java
-
103src/main/java/com/example/urbanbazaar/Model/Cart.java
-
9src/main/java/com/example/urbanbazaar/Repository/CartRepository.java
-
11src/main/java/com/example/urbanbazaar/Repository/UserRepository.java
@ -0,0 +1,39 @@ |
|||||
|
package com.example.urbanbazaar.Controller; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
import com.example.urbanbazaar.Model.Cart; |
||||
|
import com.example.urbanbazaar.Repository.CartRepository; |
||||
|
|
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.web.bind.annotation.DeleteMapping; |
||||
|
import org.springframework.web.bind.annotation.PostMapping; |
||||
|
import org.springframework.web.bind.annotation.RequestBody; |
||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||
|
import org.springframework.web.bind.annotation.RestController; |
||||
|
|
||||
|
@RestController |
||||
|
public class CartController { |
||||
|
|
||||
|
@Autowired |
||||
|
private CartRepository repo; |
||||
|
|
||||
|
@PostMapping("/addCart") |
||||
|
public void addtoCart(@RequestBody Cart cart) |
||||
|
{ |
||||
|
repo.save(cart); |
||||
|
} |
||||
|
|
||||
|
@DeleteMapping("/deleteCart") |
||||
|
public void deletefromCart(@RequestBody Cart cart) |
||||
|
{ |
||||
|
repo.delete(cart); |
||||
|
} |
||||
|
|
||||
|
@RequestMapping("/showCart") |
||||
|
public List<Cart>showAll() |
||||
|
{ |
||||
|
return repo.findAll(); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,103 @@ |
|||||
|
package com.example.urbanbazaar.Model; |
||||
|
|
||||
|
import javax.persistence.Entity; |
||||
|
import javax.persistence.GeneratedValue; |
||||
|
import javax.persistence.Id; |
||||
|
import javax.persistence.Table; |
||||
|
|
||||
|
@Entity |
||||
|
@Table(name = "Cart") |
||||
|
public class Cart { |
||||
|
|
||||
|
@Id |
||||
|
@GeneratedValue |
||||
|
private int productid; |
||||
|
private String productname; |
||||
|
private float productprice; |
||||
|
private float productweight; |
||||
|
private String productshortdesc; |
||||
|
private String productlongdesc; |
||||
|
private String productimage; |
||||
|
private int productcategoryid; |
||||
|
|
||||
|
public int getProductid() { |
||||
|
return productid; |
||||
|
} |
||||
|
|
||||
|
public void setProductid(int productid) { |
||||
|
this.productid = productid; |
||||
|
} |
||||
|
|
||||
|
public String getProductname() { |
||||
|
return productname; |
||||
|
} |
||||
|
|
||||
|
public void setProductname(String productname) { |
||||
|
this.productname = productname; |
||||
|
} |
||||
|
|
||||
|
public float getProductprice() { |
||||
|
return productprice; |
||||
|
} |
||||
|
|
||||
|
public void setProductprice(float productprice) { |
||||
|
this.productprice = productprice; |
||||
|
} |
||||
|
|
||||
|
public float getProductweight() { |
||||
|
return productweight; |
||||
|
} |
||||
|
|
||||
|
public void setProductweight(float productweight) { |
||||
|
this.productweight = productweight; |
||||
|
} |
||||
|
|
||||
|
public String getProductshortdesc() { |
||||
|
return productshortdesc; |
||||
|
} |
||||
|
|
||||
|
public void setProductshortdesc(String productshortdesc) { |
||||
|
this.productshortdesc = productshortdesc; |
||||
|
} |
||||
|
|
||||
|
public String getProductlongdesc() { |
||||
|
return productlongdesc; |
||||
|
} |
||||
|
|
||||
|
public void setProductlongdesc(String productlongdesc) { |
||||
|
this.productlongdesc = productlongdesc; |
||||
|
} |
||||
|
|
||||
|
public String getProductimage() { |
||||
|
return productimage; |
||||
|
} |
||||
|
|
||||
|
public void setProductimage(String productimage) { |
||||
|
this.productimage = productimage; |
||||
|
} |
||||
|
|
||||
|
public int getProductcategoryid() { |
||||
|
return productcategoryid; |
||||
|
} |
||||
|
|
||||
|
public void setProductcategoryid(int productcategoryid) { |
||||
|
this.productcategoryid = productcategoryid; |
||||
|
} |
||||
|
|
||||
|
public Cart(int productid, String productname, float productprice, float productweight, String productshortdesc, |
||||
|
String productlongdesc, String productimage, int productcategoryid) { |
||||
|
this.productid = productid; |
||||
|
this.productname = productname; |
||||
|
this.productprice = productprice; |
||||
|
this.productweight = productweight; |
||||
|
this.productshortdesc = productshortdesc; |
||||
|
this.productlongdesc = productlongdesc; |
||||
|
this.productimage = productimage; |
||||
|
this.productcategoryid = productcategoryid; |
||||
|
} |
||||
|
|
||||
|
public Cart() { |
||||
|
|
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,9 @@ |
|||||
|
package com.example.urbanbazaar.Repository; |
||||
|
|
||||
|
import com.example.urbanbazaar.Model.Cart; |
||||
|
|
||||
|
import org.springframework.data.jpa.repository.JpaRepository; |
||||
|
|
||||
|
public interface CartRepository extends JpaRepository<Cart,Integer> { |
||||
|
|
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue