Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id 'java'
id 'org.springframework.boot' version '3.5.5'
id 'org.springframework.boot' version '3.2.5'
id 'io.spring.dependency-management' version '1.1.7'
id 'org.asciidoctor.jvm.convert' version '3.3.2'
}
Expand Down Expand Up @@ -32,6 +32,7 @@ ext {
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity6'
Expand All @@ -51,6 +52,12 @@ dependencies {
implementation ('com.github.javafaker:javafaker:1.0.2') {
exclude group: 'org.yaml', module: 'snakeyaml'
}

// Actuator
implementation 'org.springframework.boot:spring-boot-starter-actuator'
// Prometheus
implementation 'io.micrometer:micrometer-registry-prometheus'

}

tasks.named('test') {
Expand Down
19 changes: 19 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: '3.8'
services:
prometheus:
image: prom/prometheus
container_name: prometheus
ports:
- "9090:9090"
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
command:
- '--config.file=/etc/prometheus/prometheus.yml'

grafana:
image: grafana/grafana
container_name: grafana
ports:
- "3000:3000"
depends_on:
- prometheus
6 changes: 6 additions & 0 deletions prometheus.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
scrape_configs:
- job_name: 'shoppay-app'
metrics_path: '/actuator/prometheus'
scrape_interval: 15s
static_configs:
- targets: ['host.docker.internal:8080']
21 changes: 15 additions & 6 deletions src/main/java/org/zerock/shoppay/Controller/CartController.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.zerock.shoppay.Controller;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
Expand All @@ -18,7 +19,9 @@
import java.util.Map;

@Controller
@RequestMapping("/cart")
@RequiredArgsConstructor
@Slf4j
public class CartController {

private final CartService cartService;
Expand All @@ -28,7 +31,7 @@ public class CartController {
private String clientKey;

// 장바구니 페이지
@GetMapping("/cart")
@GetMapping
public String cart(@AuthenticationPrincipal UserDetails userDetails, Model model) {
if (userDetails != null) {
Member member = memberService.findByEmail(userDetails.getUsername());
Expand All @@ -43,7 +46,7 @@ public String cart(@AuthenticationPrincipal UserDetails userDetails, Model model
}

// 장바구니에 상품 추가 (AJAX)
@PostMapping("/cart/add")
@PostMapping("/add")
@ResponseBody
public ResponseEntity<Map<String, Object>> addToCart(
@AuthenticationPrincipal UserDetails userDetails,
Expand Down Expand Up @@ -76,7 +79,7 @@ public ResponseEntity<Map<String, Object>> addToCart(
}

// 장바구니 아이템 수량 변경 (AJAX)
@PostMapping("/cart/update/{cartItemId}")
@PostMapping("/update/{cartItemId}")
@ResponseBody
public ResponseEntity<Map<String, Object>> updateQuantity(
@AuthenticationPrincipal UserDetails userDetails,
Expand Down Expand Up @@ -110,22 +113,26 @@ public ResponseEntity<Map<String, Object>> updateQuantity(
}

// 장바구니 아이템 삭제 (AJAX)
@DeleteMapping("/cart/remove/{cartItemId}")
@DeleteMapping("/remove/{cartItemId}")
@ResponseBody
public ResponseEntity<Map<String, Object>> removeFromCart(
@AuthenticationPrincipal UserDetails userDetails,
@PathVariable Long cartItemId) {

log.info("Attempting to remove cart item. ID: {}", cartItemId);
Map<String, Object> response = new HashMap<>();

try {
if (userDetails == null) {
log.warn("Unauthorized attempt to remove cart item. User is not logged in.");
response.put("success", false);
response.put("message", "로그인이 필요합니다.");
return ResponseEntity.ok(response);
}

log.info("User '{}' is attempting to remove cart item ID: {}", userDetails.getUsername(), cartItemId);
cartService.removeFromCart(cartItemId);
log.info("Successfully called cartService.removeFromCart for item ID: {}", cartItemId);

Member member = memberService.findByEmail(userDetails.getUsername());
Cart cart = cartService.getCartWithItems(member);
Expand All @@ -134,8 +141,10 @@ public ResponseEntity<Map<String, Object>> removeFromCart(
response.put("message", "장바구니에서 삭제되었습니다.");
response.put("totalPrice", cart.getTotalPrice());
response.put("totalItems", cart.getTotalItems());
log.info("Successfully removed cart item ID: {}. Returning success response.", cartItemId);

} catch (Exception e) {
log.error("Error removing cart item ID: {}", cartItemId, e);
response.put("success", false);
response.put("message", "삭제 중 오류가 발생했습니다.");
}
Expand All @@ -144,7 +153,7 @@ public ResponseEntity<Map<String, Object>> removeFromCart(
}

// 장바구니 비우기
@PostMapping("/cart/clear")
@PostMapping("/clear")
public String clearCart(@AuthenticationPrincipal UserDetails userDetails) {
if (userDetails != null) {
Member member = memberService.findByEmail(userDetails.getUsername());
Expand All @@ -154,7 +163,7 @@ public String clearCart(@AuthenticationPrincipal UserDetails userDetails) {
}

// 장바구니 아이템 개수 조회 (헤더용)
@GetMapping("/cart/count")
@GetMapping("/count")
@ResponseBody
public ResponseEntity<Integer> getCartItemCount(@AuthenticationPrincipal UserDetails userDetails) {
if (userDetails != null) {
Expand Down
Loading