-
Notifications
You must be signed in to change notification settings - Fork 1
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
4 changed files
with
37 additions
and
4 deletions.
There are no files selected for viewing
11 changes: 10 additions & 1 deletion
11
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,20 +1,29 @@ | ||
package com.kampus.kbazaar.cart; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequestMapping("/api/v1") | ||
public class CartController { | ||
|
||
@Autowired | ||
private final CartService cartService; | ||
|
||
public CartController(CartService cartService) { | ||
this.cartService = cartService; | ||
} | ||
|
||
@GetMapping("/carts") | ||
public ResponseEntity getCart() { // NOSONAR | ||
return ResponseEntity.ok().build(); | ||
} | ||
|
||
|
||
@PostMapping("/carts/{username}/promotions") | ||
public ResponseEntity createCartPromotions(@PathVariable String username) { | ||
|
||
cartService.createCartPromotions30UpTo200(); | ||
return ResponseEntity.ok().build(); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
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 |
---|---|---|
@@ -1,7 +1,13 @@ | ||
package com.kampus.kbazaar.cart; | ||
|
||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.List; | ||
|
||
@Repository | ||
public interface CartRepository { | ||
@Query("SELECT c FROM Cart c WHERE c.shopper.id = :userId") | ||
List<Cart> findByUserId(@Param("userId") Long userId); | ||
} |
18 changes: 18 additions & 0 deletions
18
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 |
---|---|---|
@@ -1,5 +1,23 @@ | ||
package com.kampus.kbazaar.cart; | ||
|
||
import com.kampus.kbazaar.exceptions.NotFoundException; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
|
||
@Service | ||
public class CartService { | ||
@Autowired | ||
private final CartRepository cartRepository; | ||
|
||
public CartService(CartRepository cartRepository) { | ||
this.cartRepository = cartRepository; | ||
} | ||
|
||
public void createCartPromotions30UpTo200() { | ||
List<Cart> carts = cartRepository.findByUserId(1L); | ||
if (cartRepository.findByUserId(1L).isEmpty()) | ||
throw new NotFoundException("Cart not found"); | ||
} | ||
} |
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,7 +1,7 @@ | ||
CREATE TABLE cart ( | ||
cart_id SERIAL PRIMARY KEY, | ||
quantity INT NOT NULL, | ||
(user_id) REFERENCES shopper(id) | ||
(product_id) REFERENCES product(id) | ||
(promotion_id) REFERENCES promotion(promotion_id) | ||
user_id INT NOT NULL, | ||
product_id INT NOT NULL, | ||
promotion_id INT NOT NULL | ||
) |