Browse Source

cart services added and not tested along with this uer services are tested and they are working fine

gauravMain
Gaurav 4 years ago
parent
commit
d96a90b4f8
5 changed files with 203 additions and 28 deletions
  1. 39
      src/main/java/com/example/urbanbazaar/Controller/CartController.java
  2. 69
      src/main/java/com/example/urbanbazaar/Controller/UserController.java
  3. 103
      src/main/java/com/example/urbanbazaar/Model/Cart.java
  4. 9
      src/main/java/com/example/urbanbazaar/Repository/CartRepository.java
  5. 11
      src/main/java/com/example/urbanbazaar/Repository/UserRepository.java

39
src/main/java/com/example/urbanbazaar/Controller/CartController.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();
}
}

69
src/main/java/com/example/urbanbazaar/Controller/UserController.java

@ -19,45 +19,76 @@ public class UserController {
@Autowired
private UserRepository repo;
@PostMapping("/addUser")
public void addUser(@RequestBody User user) {
repo.save(user);
}
@GetMapping("/showAllUsers")
public List<User> showUsers() {
return repo.findAll();
}
@GetMapping("/findUserById/{userId}")
public User findUserById(@PathVariable int userId) {
return repo.findById(userId).get();
}
// @PutMapping("/{id}/{first}/{second}")
// public void updateName(@PathVariable String userfirstname, @PathVariable String userlastname, @PathVariable Integer id)
// {
// repo.updateName(userfirstname, userlastname, id);
// }
@PutMapping("/{id}/{userfirstname}/{userlastname}")
public void updateName(@PathVariable Integer id, @PathVariable String userfirstname,
@PathVariable String userlastname) {
User user = repo.findById(id).get();
if (user.getUserfirstname() != userfirstname && user.getUserlastname() != userlastname) {
user.setUserfirstname(userfirstname);
user.setUserlastname(userlastname);
repo.save(user);
}
if (user.getUserfirstname() != userfirstname) {
user.setUserfirstname(userfirstname);
repo.save(user);
}
if (user.getUserlastname() != userlastname) {
user.setUserlastname(userlastname);
repo.save(user);
}
@PutMapping("/{email}/{id}")
public void updateEmail(@PathVariable String email,@PathVariable Integer id)
{
repo.updateEmail(email, id);
}
@PutMapping("/{id}/{email}")
public void updateEmail(@PathVariable String email, @PathVariable Integer id) {
repo.updateEmail(email, id);
}
@PutMapping("/phone/{userphone}/{id}")
public void updatephoneNumber(@PathVariable String userphone,@PathVariable Integer id)
{
public void updatephoneNumber(@PathVariable String userphone, @PathVariable Integer id) {
repo.updatePhoneNumber(userphone, id);
}
// @PutMapping("/useraddress/{address}/{id}")
// public void updateaddressOne(@PathVariable String useraddress,@PathVariable Integer id)
// {
// repo.updateAddressOne(useraddress, id);
// }
@PutMapping("/address/{id}/{useraddress}")
public void updateaddressOne(@PathVariable String useraddress,@PathVariable
Integer id)
{
User user = repo.findById(id).get();
if(user.getUseraddress() !=useraddress)
{
user.setUseraddress(useraddress);
repo.save(user);
}
}
@PutMapping("/address2/{id}/{useraddress2}")
public void updateaddressTwo(@PathVariable String useraddress2,@PathVariable
Integer id)
{
User user = repo.findById(id).get();
if(user.getUseraddress2() !=useraddress2)
{
user.setUseraddress2(useraddress2);;
repo.save(user);
}
}
}

103
src/main/java/com/example/urbanbazaar/Model/Cart.java

@ -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() {
}
}

9
src/main/java/com/example/urbanbazaar/Repository/CartRepository.java

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

11
src/main/java/com/example/urbanbazaar/Repository/UserRepository.java

@ -10,11 +10,7 @@ import javax.transaction.Transactional;
import com.example.urbanbazaar.Model.User;
public interface UserRepository extends JpaRepository<User, Integer> {
// @Transactional
// @Modifying
// @Query(value="UPDATE User u SET userfirstname=:userfirstname,userlastname=:userlastname WHERE u.userid=:id")
// void updateName(@Param("userfirstname") String userfirstname, @Param("userlastname") String userlastname,
// @Param("id") int id);
@Transactional
@Modifying
@ -26,10 +22,7 @@ public interface UserRepository extends JpaRepository<User, Integer> {
@Query("UPDATE User u SET userphone=:userphone WHERE u.userid=:id")
void updatePhoneNumber(@Param("userphone") String userphone, @Param("id") int id);
// @Transactional
// @Modifying
// @Query("UPDATE User u SET useraddress=:useraddress WHERE u.userid=:id")
// void updateAddressOne(@Param("useraddress") String useraddress, @Param("id") int id);
}
Loading…
Cancel
Save