-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add cart service and cart repository
- Loading branch information
Bank
authored and
Bank
committed
Mar 23, 2024
1 parent
dceb02a
commit 0056c84
Showing
5 changed files
with
52 additions
and
21 deletions.
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
42 changes: 23 additions & 19 deletions
42
kbazaar/src/main/java/com/kampus/kbazaar/cart/CartController.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 |
---|---|---|
@@ -1,35 +1,39 @@ | ||
package com.kampus.kbazaar.cart; | ||
|
||
import com.kampus.kbazaar.shopper.ShopperService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequestMapping("/api/v1") | ||
@RequiredArgsConstructor | ||
public class CartController { | ||
|
||
private final ShopperService shopperService; | ||
|
||
@GetMapping("/carts") | ||
public ResponseEntity getCart() { // NOSONAR | ||
return ResponseEntity.ok().build(); | ||
} | ||
|
||
// @PostMapping("/carts/{username}/products") | ||
// public ResponseEntity<AddProductResponse> addProduct( | ||
// @PathVariable("username") String username, | ||
// @RequestBody AddProductRequest addProductRequest) { | ||
// | ||
// Product product = productService.getProductBySku(addProductRequest.getProductSku()); | ||
// if (product.getQuantity() < addProductRequest.getQuantity()) { | ||
// return ResponseEntity.badRequest().build(); | ||
// } | ||
// | ||
// // return ResponseEntity.ok(cartService | ||
// // .findCartByUsername(username)); | ||
// // .addProduct(product) | ||
// // .toAddProductResponse()); | ||
// return ResponseEntity.ok().build(); | ||
// } | ||
@PostMapping("/carts/{username}/products") | ||
public ResponseEntity<String> addProduct( | ||
@PathVariable("username") String username, | ||
@RequestBody AddProductRequest addProductRequest) { | ||
|
||
// Cart cart = cartService.findCartByUsername(username); | ||
// Product product = | ||
// productService.getProductBySku(addProductRequest.getProductSku()); | ||
// if (product.getQuantity() < addProductRequest.getQuantity()) { | ||
// return ResponseEntity.badRequest().build(); | ||
// } | ||
|
||
// return ResponseEntity.ok(cartService | ||
// .findCartByUsername(username)); | ||
// .addProduct(product) | ||
// .toAddProductResponse()); | ||
|
||
return ResponseEntity.ok("hey"); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
kbazaar/src/main/java/com/kampus/kbazaar/cart/CartRepository.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,7 @@ | ||
package com.kampus.kbazaar.cart; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface CartRepository extends JpaRepository<Cart, Long> {} |
14 changes: 14 additions & 0 deletions
14
kbazaar/src/main/java/com/kampus/kbazaar/cart/CartService.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,14 @@ | ||
package com.kampus.kbazaar.cart; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class CartService { | ||
private final CartRepository cartRepository; | ||
|
||
public Cart findCartByUsername(String username) { | ||
return null; | ||
} | ||
} |
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