Skip to content

Commit

Permalink
Merge branch 'main' of github.com:KBTG-Kampus-ClassNest-SE-Java/works…
Browse files Browse the repository at this point in the history
…hop-group-5
  • Loading branch information
peachoenixzz committed Mar 23, 2024
2 parents 03cca2e + a262bd7 commit afc824e
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 15 deletions.
6 changes: 3 additions & 3 deletions infra/gitops/dev/configmap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

2 changes: 1 addition & 1 deletion infra/gitops/dev/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions infra/gitops/prod/configmap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
22 changes: 14 additions & 8 deletions kbazaar/src/main/java/com/kampus/kbazaar/cart/Cart.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
10 changes: 10 additions & 0 deletions kbazaar/src/main/java/com/kampus/kbazaar/cart/CartController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
17 changes: 17 additions & 0 deletions kbazaar/src/main/java/com/kampus/kbazaar/cart/CartId.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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<Cart, CartId> {

}
16 changes: 16 additions & 0 deletions kbazaar/src/main/java/com/kampus/kbazaar/cart/CartService.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
4 changes: 4 additions & 0 deletions kbazaar/src/main/resources/sql/data/cart.sql
Original file line number Diff line number Diff line change
@@ -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;
8 changes: 8 additions & 0 deletions kbazaar/src/main/resources/sql/schema/cart.sql
Original file line number Diff line number Diff line change
@@ -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);
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,6 +30,8 @@ public class CartControllerTest {

@Autowired private MockMvc mockMvc;

@MockBean private CartService cartService;

@InjectMocks private CartController cartController;

@BeforeEach
Expand Down

0 comments on commit afc824e

Please sign in to comment.