๊ฐœ๋ฐœ์ผ์ง€-36 [๐Ÿ“ ์ฃผ๋ฌธ ๋„๋ฉ”์ธ(๊ตฌ๋งค์ž): ์ฃผ๋ฌธ ๋‚ด์—ญ ์กฐํšŒ & ์‚ญ์ œ]

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

์ฃผ๋ฌธ ๋„๋ฉ”์ธ ๊ด€๋ จ ํฌ์ŠคํŒ…(๊ตฌ๋งค์ž)

์ฃผ๋ฌธ ๋„๋ฉ”์ธ ๊ด€๋ จ ํฌ์ŠคํŒ…(ํŒ๋งค์ž)


์ฃผ๋ฌธ ๋‚ด์—ญ ์กฐํšŒ ํ™”๋ฉด


1. [GET] /jat/app/orders

์ฃผ๋ฌธ์ด ์™„๋ฃŒ๋œ ๋‚ด์—ญ๋“ค์„ ํ™•์ธ

  • ํŒ๋งค์ž๊ฐ€ "ํ”ฝ์—…์™„๋ฃŒ" ์ƒํƒœ๋กœ ๋ถ„๋ฅ˜ํ•œ ์ฃผ๋ฌธ์„ ์ฃผ๋ฌธ๋‚ด์—ญํ™”๋ฉด์—์„œ ์กฐํšŒ๊ฐ€๋Šฅํ•˜๋„๋ก ๊ตฌํ˜„ํ•˜์˜€๋‹ค.
  • ์‘๋‹ต ๋ฐ”๋””
    • ์ฃผ๋ฌธ ๋‚ด์—ญ ์กฐํšŒ ํ™”๋ฉด์—์„œ ํ•„์š”ํ•œ ์ •๋ณด๋Š” [์ฃผ๋ฌธ๋‚ ์งœ, ์ฃผ๋ฌธ ํ•œ๊ฐ€๊ฒŒ, ์ฃผ๋ฌธ ๋‚ด์šฉ, ์ฃผ๋ฌธ ๊ธˆ์•ก, ๋ฆฌ๋ทฐ ์ž‘์„ฑ ์—ฌ๋ถ€] ๋“ฑ์ด ํฌํ•จ๋œ๋‹ค.
  • ์ปจํŠธ๋กค๋Ÿฌ
  • ์„œ๋น„์Šค
    public List<GetOrderListRes> getOrderList(int customerIdx) throws BaseException {
        String[] weekDays = new String[]{"์ผ", "์›”", "ํ™”", "์ˆ˜", "๋ชฉ", "๊ธˆ", "ํ† "};
        // ์ฃผ๋ฌธ ๋‚ด์—ญ ๊ฐ€์ ธ์˜ค๊ธฐ
        List<GetOrderListRes> orderList;
        try{
            orderList = appOrderDao.getOrderList(customerIdx, weekDays);
        }catch (Exception e){
            throw new BaseException(DATABASE_ERROR);
        }
        // ์ฃผ๋ฌธ๋‚ด์—ญ s3
        try{
            for(GetOrderListRes order : orderList){
                if(order.getMenuUrl() != null && !order.getMenuUrl().equals("")){
                    order.setMenuUrl(""+s3Client.getUrl(bucketName, order.getMenuUrl()));
                }
            }
        }catch (Exception e){
            throw new BaseException(DATABASE_ERROR);
        }

        return orderList;
    }
  1. ์ฃผ๋ฌธ ๋‚ด์—ญ์— ์š”์ผ์ด ํฌํ•จ๋˜์–ด ์žˆ๊ธฐ ๋•Œ๋ฌธ์—, DB์—์„œ ์กฐํšŒ ์‹œ ๋‚ ์งœ+์š”์ผ ์ •๋ณด๋ฅผ ๊ฐ™์ด ๊ฐ€์ ธ์˜ค๋„๋ก ํ•˜์˜€๋‹ค.
  2. ๊ฐ DBํ…Œ์ด๋ธ”์„ joinํ•ด์„œ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ ธ์˜ด
  3. ๋ฆฌ๋ทฐ๋ฅผ ์ž‘์„ฑํ–ˆ๋Š”์ง€๋„ ๋ทฐ์—์„œ ์‹๋ณ„ํ•ด์•ผํ•˜๊ธฐ ๋•Œ๋ฌธ์—, ๋ฆฌ๋ทฐ๋ฅผ ์ž‘์„ฑํ•˜์ง€ ์•Š์•˜๋‹ค๋ฉด ์กฐ์ธ ํ…Œ์ด๋ธ”์— ๋‚˜ํƒ€๋‚˜์ง€ ์•Š์•„์„œ null ๊ฐ’์„ ํ†ตํ•ด ์‹๋ณ„ํ•˜์˜€๋‹ค.
  • Dao
// ์ฃผ๋ฌธ๋‚ด์—ญ ์กฐํšŒ
    public List<GetOrderListRes> getOrderList(int customerIdx, String[] weekDays) {
        String query = "SELECT\n" +
                "    O.orderIdx,\n" +
                "    DATE_FORMAT(O.created, '%Y.%m.%d') as orderDate,\n" +
                "    DATE_FORMAT(O.created, '%w') as weekDay,\n" +
                "    S.storeIdx,\n" +
                "    S.store_name,\n" +
                "    M.menu_name,\n" +
                "    M.menu_url,\n" +
                "    TM.price,\n" +
                "    COUNT(OL.orderIdx) as orerItemCount,\n" +
                "    reviewIdx\n" +
                "FROM Orders O\n" +
                "LEFT JOIN OrderLists OL on O.orderIdx = OL.orderIdx\n" +
                "LEFT JOIN TodayMenu TM on TM.todaymenuIdx = OL.todaymenuIdx\n" +
                "LEFT JOIN Menu M on M.menuIdx = TM.menuIdx\n" +
                "LEFT JOIN Stores S on O.storeIdx = S.storeIdx\n" +
                "LEFT JOIN Review R on O.orderIdx = R.orderIdx\n" +
                "WHERE O.customerIdx = ?  AND O.status LIKE '%A%'\n" +
                "GROUP BY O.orderIdx\n" +
                "ORDER BY O.created DESC";

        return this.jdbcTemplate.query(query,
                (rs, rowNum) -> new GetOrderListRes(
                        rs.getInt("orderIdx"),
                        rs.getString("orderDate"),
                        rs.getInt("weekDay"),
                        weekDays[rs.getInt("weekDay")],
                        rs.getInt("storeIdx"),
                        rs.getString("store_name"),
                        rs.getString("menu_name"),
                        rs.getString("menu_url"),
                        rs.getInt("price"),
                        rs.getInt("orerItemCount"),
                        rs.getInt("reviewIdx") != 0 ? 1 : 0
                ), customerIdx);
    }

ํ…Œ์ŠคํŠธ


2. [GET] /jat/app/orders/details

์ฃผ๋ฌธ ์ƒ์„ธ ๋‚ด์—ญ ์กฐํšŒ

  • ์ฃผ๋ฌธ์„ ํ†ตํ•ด ๋ณธ์ธ์ด ํ•œ ์ฃผ๋ฌธ ์ •๋ณด๋ฅผ ์ƒ์„ธํ•˜๊ฒŒ ์กฐํšŒ
  • ์‘๋‹ต ๋ฐ”๋””
  • ์ปจํŠธ๋กค๋Ÿฌ
  • ์„œ๋น„์Šค
    public OrderDetailRes getOrderDetail(int orderIdx) throws BaseException{

        // 1. ์ฃผ๋ฌธ ์ƒ์„ธ ๊ธฐ๋ณธ์ •๋ณด ๊ฐ€์ ธ์˜ค๊ธฐ
        OrderDetailRes orderDetails;
        try{
            orderDetails = appOrderDao.getOrderDetail(orderIdx);
        }catch (Exception e){
            throw new BaseException(DATABASE_ERROR);
        }

        // 2. ์ฃผ๋ฌธ์— ๋”ธ๋ฆฐ ๋ฉ”๋‰ด ์ƒ์„ธ ์ •๋ด… ๊ฐ€์ ธ์˜ค๊ธฐ
        try{
            List<OrderMenuItem> orderItems = appOrderDao.getOrderItems(orderIdx);

            orderDetails.setOrderMenus(orderItems);

            return orderDetails;
        }catch (Exception e){
            throw new BaseException(DATABASE_ERROR);
        }
    }
  1. ์ฃผ๋ฌธ ์ƒ์„ธ๋ฅผ ์œ„ํ•œ ๊ธฐ๋ณธ ์ •๋ณด๋ฅผ ๊ฐ€์ ธ์˜ค๊ณ 
  2. ์ฃผ๋ฌธ์— ๋”ธ๋ฆฐ ์ฃผ๋ฌธ ํ’ˆ๋ชฉ ๋‚ด์—ญ๋“ค์„ ๊ฐ™์ด ์กฐํšŒ
  • Dao
// ์ฃผ๋ฌธ ์ƒ์„ธ ๊ธฐ๋ณธ ์ •๋ณด(์‹œ๊ฐ„, ๊ฐ€๊ฒŒIdx, ๊ฐ€๊ฒŒ์ด๋ฆ„, ๊ฐ€๊ฒŒ ์ „ํ™”๋ฒˆํ˜ธ, ๊ธˆ์•ก, ๊ฐœ์ˆ˜, ์š”์ฒญ์‚ฌํ•ญ, ๊ฒฐ์ œ์ •๋ณด)
    public OrderDetailRes getOrderDetail(int orderIdx) {
        String query = "SELECT\n" +
                "    DATE_FORMAT(O.created, '%Y๋…„ %m์›” %d์ผ') as orderDate,\n" +
                "    DATE_FORMAT(O.created, '%h:%i:%s') as orderTime,\n" +
                "    DATE_FORMAT(O.created, '%p') as pmam,\n" +
                "    S.storeIdx, S.store_name, S.store_phone,\n" +
                "    CONCAT( M.menu_name, ' ', TM.price, '์›') simpleMenu,\n" +
                "    COUNT(OL.orderIdx) count,\n" +
                "    SUM(OL.cnt * TM.price) as totalPrice,\n" +
                "    O.payment_status,\n" +
                "    O.request\n" +
                "FROM Orders O\n" +
                "    LEFT JOIN OrderLists OL on O.orderIdx = OL.orderIdx\n" +
                "    LEFT JOIN TodayMenu TM on TM.todaymenuIdx = OL.todaymenuIdx\n" +
                "    LEFT JOIN Menu M on M.menuIdx = TM.menuIdx\n" +
                "    LEFT JOIN Stores S on O.storeIdx = S.storeIdx\n" +
                "WHERE O.orderIdx = ?";

        return this.jdbcTemplate.queryForObject(query,
                (rs, rowNum) -> new OrderDetailRes(
                        rs.getString("orderDate") + " "+
                            rs.getString("orderTime") +
                            (rs.getString("pmam").equals("AM") ? "AM" : "PM"),
                        rs.getInt("storeIdx"),
                        rs.getString("store_name"),
                        rs.getString("store_phone"),
                        rs.getString("simpleMenu")
                                + (rs.getInt("count") >= 2 ?
                                " ์™ธ" + (rs.getInt("count") -1) + "๊ฐœ": ""),
                        null,
                        rs.getInt("count"),
                        rs.getInt("totalPrice"),
                        rs.getString("payment_status"),
                        rs.getString("request")
                ), orderIdx);
    }
// ๊ฐ€๊ฒŒ ์ด๋ฆ„, ์ฃผ๋ฌธํ•œ ๋ฉ”๋‰ด ๊ฐœ์ˆ˜, ๋ฉ”๋‰ด ๊ฐ€๊ฒฉ, ํ• ์ธ์œจ, ํ• ์ธ๊ฐ€๊ฒฉ
    public List<OrderMenuItem> getOrderItems(int orderIdx) {
        String query = "SELECT\n" +
                "    M.menu_name, \n" +
                "    OL.cnt,\n" +
                "    M.price, TM.discount, TM.price as todayPrice\n" +
                "FROM Orders O \n" +
                "    LEFT JOIN OrderLists OL on O.orderIdx = OL.orderIdx\n" +
                "    LEFT JOIN TodayMenu TM on TM.todaymenuIdx = OL.todaymenuIdx\n" +
                "    LEFT JOIN Menu M on M.menuIdx = TM.menuIdx\n" +
                "WHERE O.orderIdx = ?";

        return this.jdbcTemplate.query(query,
                (rs, rowNum) -> new OrderMenuItem(
                        rs.getString("menu_name"),
                        rs.getInt("cnt"),
                        rs.getInt("price"),
                        rs.getInt("discount"),
                        rs.getInt("todayPrice")
                ), orderIdx);
    }

ํ…Œ์ŠคํŠธ


3. [PATCH] /jat/app/orders

์ฃผ๋ฌธ ๋‚ด์—ญ ์‚ญ์ œ

์ฃผ๋ฌธ ๋‚ด์—ญ์— ์กด์žฌํ•˜๋Š” ์ƒํƒœ๊ฐ’์„ 'AD'๋กœ ๋ณ€๊ฒฝ
'AD' ์œ ํšจํ•œ ์ฃผ๋ฌธ์ด๋‚˜, ๊ตฌ๋งค์ž๊ฐ€ ์ฃผ๋ฌธ ๋‚ด์—ญ์„ ์‚ญ์ œํ•œ ์ƒํƒœ
๊ตฌ๋งค์ž๋Š” ๋งค์ถœ ์กฐํšŒ ์‹œ, ํ”ฝ์—…์™„๋ฃŒ ์ฃผ๋ฌธ ์กฐํšŒ์‹œ์— ์ƒํƒœ์— 'A'๊ฐ€ ํฌํ•จ๋œ ์ฃผ๋ฌธ์„ ์กฐํšŒํ•˜๊ฒŒ ๋จ


ํ›„๊ธฐ

์ด๋ฏธ ์ฃผ๋ฌธ ๋„๋ฉ”์ธ์„ ๋‹ค๋ฃจ๊ธฐ๋„ํ•˜์˜€๊ณ , ์ƒํƒœ๋ณ„๋กœ ๊ตฌ๋ถ„ํ•  ํ•„์š” ์—†์ด ์™„๋ฃŒ๋œ ์ฃผ๋ฌธ์„ ๊ธฐ์ค€์œผ๋กœ ํ…Œ์ด๋ธ”์„ ์กฐ์ธ๋งŒ ํ•˜๋Š” ์กฐํšŒ๊ฐ€ ๋Œ€๋ถ€๋ถ„์ด์—ฌ์„œ ๋ณ„๋กœ ๊ตฌํ˜„์ด ์–ด๋ ต์ง€ ์•Š์Œ!
๊ฒฐ์ œ ์ •๋ณด ๋ฐœ์ƒ์€ ์‹ฌํžˆ ํ•„์š”ํ•˜๊ธด ํ•˜์ง€๋งŒ ์‚ฌ์—…์ž ๋“ฑ๋ก์ฆ ์ด์Šˆ ๋•Œ๋ฌธ์— ๋ถˆ๊ฐ€๋Šฅํ•˜๋‹ˆ ์–ด์ฉ”์ˆ˜๊ฐ€ ์—†๋‹ค..

profile
๊ฐœ๋ฐœ์ž๊ฐ€ ๊ฟˆ์ธ 25์‚ด ๋Œ€ํ•™์ƒ์ž…๋‹ˆ๋‹ค.

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