diff --git a/infra/gitops/dev/configmap.yml b/infra/gitops/dev/configmap.yml index 836a647..4c7851b 100644 --- a/infra/gitops/dev/configmap.yml +++ b/infra/gitops/dev/configmap.yml @@ -4,8 +4,8 @@ metadata: name: app-config namespace: group-5-dev data: - db.url: "jdbc:postgresql://db-postgresql-sgp1-09974-do-user-856918-0.c.db.ondigitalocean.com:25060/dev-group-5" - db.username: "doadmin" - db.password: "AVNS_2KxS7zrsXbMV3L_4Eaj" + db.url: "jdbc:postgresql://ec2-13-250-18-96.ap-southeast-1.compute.amazonaws.com/dev-group-5" + db.username: "postgres" + db.password: "YGSQOnBlYd+6" enabled.feature.promotion.list.api: "true" \ No newline at end of file diff --git a/infra/gitops/dev/deployment.yml b/infra/gitops/dev/deployment.yml index 660ceac..76d23c2 100644 --- a/infra/gitops/dev/deployment.yml +++ b/infra/gitops/dev/deployment.yml @@ -15,7 +15,7 @@ spec: spec: containers: - name: kbazaar-api - image: ghcr.io/kbtg-kampus-classnest-se-java/workshop-group-5:8cbac4f42b99dc6982b97bddd49bbf0cfe1260ba + image: ghcr.io/kbtg-kampus-classnest-se-java/workshop-group-5:b047ab3f3d01f0e0304478826ea1adf0b4e6c532 imagePullPolicy: Always ports: - containerPort: 8080 diff --git a/infra/gitops/prod/configmap.yml b/infra/gitops/prod/configmap.yml index 6e743de..26396f4 100644 --- a/infra/gitops/prod/configmap.yml +++ b/infra/gitops/prod/configmap.yml @@ -4,7 +4,7 @@ metadata: name: app-config namespace: group-5-prod data: - db.url: "jdbc:postgresql://db-postgresql-sgp1-09974-do-user-856918-0.c.db.ondigitalocean.com:25060/prod-group-5" - db.username: "doadmin" - db.password: "AVNS_2KxS7zrsXbMV3L_4Eaj" + db.url: "jdbc:postgresql://ec2-13-250-18-96.ap-southeast-1.compute.amazonaws.com/prod-group-5" + db.username: "postgres" + db.password: "YGSQOnBlYd+6" enabled.feature.promotion.list.api: "true" \ No newline at end of file diff --git a/kbazaar/src/main/java/com/kampus/kbazaar/cart/Cart.java b/kbazaar/src/main/java/com/kampus/kbazaar/cart/Cart.java index 70902cb..32bf612 100644 --- a/kbazaar/src/main/java/com/kampus/kbazaar/cart/Cart.java +++ b/kbazaar/src/main/java/com/kampus/kbazaar/cart/Cart.java @@ -3,14 +3,20 @@ import com.kampus.kbazaar.product.Product; import lombok.Data; -@Data -public class Cart { - private int userID; +import jakarta.persistence.EmbeddedId; +import jakarta.persistence.Entity; +import lombok.Getter; +import lombok.Setter; - private Product[] products; +@Entity(name = "cart") +@Getter +@Setter +public class Cart { + @EmbeddedId private CartId cartId; + private Integer quantity; - public Cart(int userID, Product[] products) { - this.userID = userID; - this.products = products; + public Cart(CartId cartId, Integer quantity) { + this.cartId = cartId; + this.quantity = quantity; } -} +} \ No newline at end of file diff --git a/kbazaar/src/main/java/com/kampus/kbazaar/cart/CartController.java b/kbazaar/src/main/java/com/kampus/kbazaar/cart/CartController.java index f5cd0ea..9375264 100644 --- a/kbazaar/src/main/java/com/kampus/kbazaar/cart/CartController.java +++ b/kbazaar/src/main/java/com/kampus/kbazaar/cart/CartController.java @@ -6,9 +6,19 @@ @RestController @RequestMapping("/api/v1") public class CartController { + private CartService cartService; + + public CartController(CartService cartService) { + this.cartService = cartService; + } @GetMapping("/carts") public ResponseEntity getCart() { // NOSONAR return ResponseEntity.ok().build(); } + + @DeleteMapping("/carts/{username}/items/{product_sku}") + public String deleteCartItem(@PathVariable String username, @PathVariable String product_sku) { + return cartService.deleteCartItem(username, product_sku); + } } diff --git a/kbazaar/src/main/java/com/kampus/kbazaar/cart/CartId.java b/kbazaar/src/main/java/com/kampus/kbazaar/cart/CartId.java new file mode 100644 index 0000000..0b22c58 --- /dev/null +++ b/kbazaar/src/main/java/com/kampus/kbazaar/cart/CartId.java @@ -0,0 +1,17 @@ +package com.kampus.kbazaar.cart; + +import jakarta.persistence.Embeddable; +import java.io.Serializable; +import lombok.Getter; + +@Getter +@Embeddable +public class CartId implements Serializable { + private Long shopper_id; + private Long product_id; + + public CartId(Long shopper_id, Long product_id) { + this.shopper_id = shopper_id; + this.product_id = product_id; + } +} \ No newline at end of file diff --git a/kbazaar/src/main/java/com/kampus/kbazaar/cart/CartRepository.java b/kbazaar/src/main/java/com/kampus/kbazaar/cart/CartRepository.java new file mode 100644 index 0000000..e01e9a8 --- /dev/null +++ b/kbazaar/src/main/java/com/kampus/kbazaar/cart/CartRepository.java @@ -0,0 +1,9 @@ +package com.kampus.kbazaar.cart; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface CartRepository extends JpaRepository { + +} diff --git a/kbazaar/src/main/java/com/kampus/kbazaar/cart/CartService.java b/kbazaar/src/main/java/com/kampus/kbazaar/cart/CartService.java new file mode 100644 index 0000000..a22d3fa --- /dev/null +++ b/kbazaar/src/main/java/com/kampus/kbazaar/cart/CartService.java @@ -0,0 +1,16 @@ +package com.kampus.kbazaar.cart; + +import org.springframework.stereotype.Service; + +@Service +public class CartService { + private CartRepository cartRepository; + + public CartService(CartRepository cartRepository) { + this.cartRepository = cartRepository; + } + + public String deleteCartItem(String username, String product_sku) { + return "deleteL: " + username + product_sku; + } +} \ No newline at end of file diff --git a/kbazaar/src/main/resources/sql/data/cart.sql b/kbazaar/src/main/resources/sql/data/cart.sql new file mode 100644 index 0000000..55fb06b --- /dev/null +++ b/kbazaar/src/main/resources/sql/data/cart.sql @@ -0,0 +1,4 @@ +INSERT INTO cart (quantity,product_sku) VALUES + (2,'MOBILE-APPLE-IPHONE-12-PRO') ON CONFLICT DO NOTHING; +INSERT INTO cart (quantity,product_sku) VALUES + (1,'MOBILE-SAMSUNG-GALAXY-S21-ULTRA') ON CONFLICT DO NOTHING; diff --git a/kbazaar/src/main/resources/sql/schema/cart.sql b/kbazaar/src/main/resources/sql/schema/cart.sql new file mode 100644 index 0000000..4a12923 --- /dev/null +++ b/kbazaar/src/main/resources/sql/schema/cart.sql @@ -0,0 +1,8 @@ +CREATE TABLE IF NOT EXISTS cart ( + shopper_id bigserial NOT NULL, + product_id bigserial NOT NULL, + quantity int4 NOT NULL, + product_sku varchar(255) NOT NULL, + CONSTRAINT cart_pk PRIMARY KEY (product_id, shopper_id) +); +CREATE INDEX IF NOT EXISTS cart_shopper_id_idx ON cart USING btree (shopper_id); diff --git a/kbazaar/src/test/java/com/kampus/kbazaar/cart/CartControllerTest.java b/kbazaar/src/test/java/com/kampus/kbazaar/cart/CartControllerTest.java index e70bfda..44a62f2 100644 --- a/kbazaar/src/test/java/com/kampus/kbazaar/cart/CartControllerTest.java +++ b/kbazaar/src/test/java/com/kampus/kbazaar/cart/CartControllerTest.java @@ -11,6 +11,7 @@ import org.mockito.MockitoAnnotations; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.FilterType; import org.springframework.http.MediaType; @@ -29,6 +30,8 @@ public class CartControllerTest { @Autowired private MockMvc mockMvc; + @MockBean private CartService cartService; + @InjectMocks private CartController cartController; @BeforeEach