๊ฐœ๋ฐœ์ผ์ง€-33 [๐Ÿ›’์žฅ๋ฐ”๊ตฌ๋‹ˆ ๋„๋ฉ”์ธ: ์žฅ๋ฐ”๊ตฌ๋‹ˆ ์ˆ˜์ •]

๊น€์„ฑ์ธยท2023๋…„ 9์›” 25์ผ
0

์žฅ๋ฐ”๊ตฌ๋‹ˆ ๊ธฐ๋Šฅ ๊ด€๋ จ ํฌ์ŠคํŒ…


5. [PATCH] /jat/app/basket

์žฅ๋ฐ”๊ตฌ๋‹ˆ์— ์กด์žฌํ•˜๋Š” ๋ฉ”๋‰ด๋ฅผ ์‚ญ์ œ or ์ˆ˜์ •

  • ์žฅ๋ฐ”๊ตฌ๋‹ˆ์— ๋‹ด๊ธด ๋ฉ”๋‰ด๋ฅผ ์ฃผ๋ฌธํ•˜์ง€ ์•Š์•„๋„ ๊ตฌ๋งค์ž๊ฐ€ ์ž„์˜๋กœ ์ˆ˜์ •ํ•  ์ˆ˜ ์žˆ์–ด์•ผํ•œ๋‹ค๊ณ  ์ƒ๊ฐํ•ด์„œ ๋กœ์ง์„ ๊ตฌํ˜„ํ•˜๊ฒŒ ๋˜์—ˆ๋‹ค.
  • ์š”์ฒญ ๋ฐ”๋””
  • ์‘๋‹ต๋ฐ”๋””
    : [GET] ์žฅ๋ฐ”๊ตฌ๋‹ˆ ์กฐํšŒ์™€ ๊ฐ™์Œ
  • ์ปจํŠธ๋กค๋Ÿฌ
  • ์„œ๋น„์Šค
    • ๋ฉ”๋‰ด๋ฅผ ์ˆ˜์ •/์‚ญ์ œํ•˜๋Š” ๋‘๊ฐ€์ง€ ์ƒํƒœ๊ฐ’์„ ๊ตฌ๋ณ„ํ•˜๊ธฐ ์œ„ํ•ด ํ”„๋ก ํŠธ์™€ ํ˜‘์˜๋ฅผ ํ•˜์˜€๋‹ค.
      • ๊ฐœ์ˆ˜ ์กฐ์ • ์‹œ patchStatus = "count"
      • ๋ฉ”๋‰ด ์‚ญ์ œ ์‹œ patchStatus = "remove"
    public GetBasketRes patchBasket(int userIdx, PatchBasketReq basketReq) throws BaseException {
        try{
            if(basketReq.getPatchStatus().equals("count")){
                basketDao.patchBasketCount(basketReq.getBasketIdx(), basketReq.getInDecrease());
            } else if (basketReq.getPatchStatus().equals("remove")) {
                // ์žฅ๋ฐ”๊ตฌ๋‹ˆ ํ•ญ๋ชฉ ์‚ญ์ œ
                basketDao.removeBasketItem(basketReq.getBasketIdx());
            }

        }catch(Exception e){
            throw new BaseException(ORDER_FAILED);
        }

        return getBasket(userIdx);
    }
  • Dao
// ๋ฉ”๋‰ด ๊ฐœ์ˆ˜ 1๊ฐœ ์ฆ๊ฐ€/๊ฐ์†Œ
    public void patchBasketCount(int basketIdx, int inDecrease) {
        String query = "UPDATE Basket \n" +
                "SET cnt = cnt + ?\n" +
                "WHERE basketIdx = ?";

        Object[] params = new Object[]{
                inDecrease == 1 ? 1: -1,
                basketIdx
        };

        this.jdbcTemplate.update(query, params);
    }
// ์žฅ๋ฐ”๊ตฌ๋‹ˆ์—์„œ ๋ฉ”๋‰ด ์‚ญ์ œ
    public void removeBasketItem(int basketIdx) {
        String query = "UPDATE Basket\n" +
                "SET status = 'D'\n" +
                "WHERE basketIdx = ?";

        this.jdbcTemplate.update(query, basketIdx);

    }

ํ…Œ์ŠคํŠธ

  1. ํ˜„์žฌ ์žฅ๋ฐ”๊ตฌ๋‹ˆ์—๋Š” ์ €๋ฒˆ ํฌ์ŠคํŒ…์—์„œ ๋‹ด์€ ์†Œ๊ธˆ๋นต์ด 2๊ฐœ ๋‹ด๊ฒจ์žˆ๋Š” ์ƒํƒœ์ด๋‹ค.

  2. ํ•ด๋‹น ์†Œ๊ธˆ๋นต์˜ ๊ฐœ์ˆ˜๋ฅผ ํ•˜๋‚˜ ์˜ฌ๋ ค๋ณด๊ฒ ๋‹ค.

์žฅ๋ฐ”๊ตฌ๋‹ˆ์— 2๊ฐœ์˜€๋˜ ์†Œ๊ธˆ๋นต์ด 3๊ฐœ๋กœ ์ฆ๊ฐ€ํ•œ ๊ฒฐ๊ณผ

  1. ํ•ด๋‹น ์†Œ๊ธˆ๋นต์„ ์žฅ๋ฐ”๊ตฌ๋‹ˆ์—์„œ ์‚ญ์ œํ•ด๋ณด๊ฒ ๋‹ค.

    ์‚ญ์ œ ํ›„ ์กฐํšŒ๋ฅผ ํ•ด๋ณด๋ฉด ๋นˆ ์žฅ๋ฐ”๊ตฌ๋‹ˆ์ธ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜๊ฐ€ ์žˆ๋‹ค.

0๊ฐœ์˜ ๋Œ“๊ธ€