inblog logo
|
jay0628
    SpringBoot

    [Spring Boot] 18. 스프링부트 상점 v1 (9) 상품 구매

    김주희's avatar
    김주희
    Mar 23, 2025
    [Spring Boot] 18. 스프링부트 상점 v1 (9) 상품 구매
    Contents
    1. 구매 페이지

    1. 구매 페이지

     
    notion image
    notion image
    notion image
    여기서 1은 where에 걸리는게 아님 body에 담기는
    package com.metacoding.storev1.log; import java.util.List; import org.springframework.stereotype.Service; import com.metacoding.storev1.store.Store; import com.metacoding.storev1.store.StoreRepository; @Service public class LogService { private LogRepository logRepository; private StoreRepository storeRepository; public LogService(LogRepository logRepository, StoreRepository storeRepository) { this.logRepository = logRepository; this.storeRepository = storeRepository; } public List<LogResponse.ListPage> 구매목록() { return logRepository.findAllJoinStore(); } // 구매하기는 StoreRepository도 의존한다. // query를 재활용한다 (stock 이외의 name이나 price는 기존값 조회해서 받아오도록) public void 구매하기(int storeId, String buyer, int qty) { // 1. 재고 업데이트 Store store = storeRepository.findById(storeId); store.재고감소(qty); storeRepository.update(store.getId(), store.getName(), store.getStock(), store.getPrice()); // 2. 구매 기록하기 logRepository.save(storeId, qty, qty * store.getPrice(), buyer); } }
     
     
     
     
    Share article

    jay0628

    RSS·Powered by Inblog