๊ฐœ๋ฐœ์ผ์ง€-22 [๐Ÿ’ฌ๋ฆฌ๋ทฐ ๋„๋ฉ”์ธ: ์กฐํšŒ, ํ‰์ ]

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

๋ฆฌ๋ทฐ ๋„๋ฉ”์ธ ๊ธฐ๋Šฅ ์ •์˜ ํฌ์ŠคํŒ…


๋ฆฌ๋ทฐ ํ™”๋ฉด

๊ตฌ๋งค์ž ๋„๋ฉ”์ธ์˜ ๊ธฐ๋Šฅ์ด ๋ฐœ์ƒํ•˜๋ฉด ํ…Œ์ŠคํŠธ๋ฅผ ์‹œ๋„ํ•˜๋„๋ก ํ•˜๊ฒ ๋‹ค..


1. [GET] /jat/review/average

๊ฐ€๊ฒŒ์˜ ๋ฆฌ๋ทฐ ํ‰์ 

  • ๊ตฌ๋งค์ž๊ฐ€ ์ฃผ๋ฌธ์— ๋Œ€ํ•œ ๋ฆฌ๋ทฐ๋ฅผ ๋‚จ๊ธธ ๋•Œ, ๋ฆฌ๋ทฐ์˜ ํ‰์ ๋„ ๊ฐ™์ด DB์— ์ €์žฅ๋˜๋„๋ก ํ•˜์˜€๋‹ค!
  • ๊ฐ€๊ฒŒ ๋‚ด์˜ ์œ ํšจํ•œ ๋ฆฌ๋ทฐ์˜ ๋ณ„ ํ‰์ ์ด ์–ผ๋งˆ์ธ์ง€ ํ‰๊ท ์„ ๋‚ด์–ด์„œ ๊ฒฐ๊ณผ๋ฅผ ๊ฐ€์ ธ์˜ด.
  • ํ‰๊ท  ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ๊ฐ ๋ณ„์˜ ํ‰์  ํผ์„ผํ‹ฐ์ง€๋„ ๊ฐ™์ด ์กฐํšŒํ•˜๊ฒŒ๋œ๋‹ค.
  • ์‘๋‹ต ๋ฐ”๋””
    StarCountRatio(์–ด๋–ค๋ณ„์ , ๋ณ„์  ๊ฐœ์ˆ˜, ๋ณ„์  ๋น„์œจ)
  • ReviewController.java
  • ReviewService.java
    public GetReviewStarTotalRes reviewStarTotal(int sellerIdx) throws BaseException {

        // 1) ์‚ฌ์šฉ์ž ๊ฐ€๊ฒŒ ์กฐํšŒ
        int storeIdx;
        try {
            storeIdx = storeDao.storeIdxBySellerIdx(sellerIdx);
        } catch (Exception e) {
            throw new BaseException(POST_STORES_NOT_REGISTERD); // 2030 : ์‚ฌ์šฉ์ž์˜ ๊ฐ€๊ฒŒ๊ฐ€ ๋“ฑ๋ก๋˜์–ด์žˆ์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
        }

        // 2)๋ฆฌ๋ทฐ ๊ฐœ์ˆ˜,๋ณ„์  ํ‰๊ท ,๋ณ„์  ๊ฐ€์ง€๊ณ  ์˜ค๊ธฐ
        try{
            GetReviewStarRes reviewStar = reviewDao.reviewStarTotal(storeIdx);

            List<StarCountRatio> starCountRatios = new ArrayList<>();
            starCountRatios.add(new StarCountRatio("๋ณ„ 5๊ฐœ", reviewStar.getStar5(), (int) (reviewStar.getStar5() * 1.0 / reviewStar.getReviews_total() * 100)));
            starCountRatios.add(new StarCountRatio("๋ณ„ 4๊ฐœ", reviewStar.getStar4(), (int) (reviewStar.getStar4() * 1.0  / reviewStar.getReviews_total() * 100)));
            starCountRatios.add(new StarCountRatio("๋ณ„ 3๊ฐœ", reviewStar.getStar3(), (int) (reviewStar.getStar3() * 1.0  / reviewStar.getReviews_total() * 100)));
            starCountRatios.add(new StarCountRatio("๋ณ„ 2๊ฐœ", reviewStar.getStar2(), (int) (reviewStar.getStar2() * 1.0  / reviewStar.getReviews_total() * 100)));
            starCountRatios.add(new StarCountRatio("๋ณ„ 1๊ฐœ", reviewStar.getStar1(), (int) (reviewStar.getStar1() * 1.0  / reviewStar.getReviews_total() * 100)));

            return new GetReviewStarTotalRes(storeIdx, reviewStar.getStar_average(), reviewStar.getReviews_total(), starCountRatios);
        }catch (Exception e){
            throw new BaseException(DATABASE_ERROR);
        }

    }

JWTํ† ํฐ์— ์กด์žฌํ•˜๋Š” ์‚ฌ์šฉ์ž ์‹๋ณ„์ž๋กœ ๊ฐ€๊ฒŒ Idx๋ฅผ ์กฐํšŒํ•œ ํ›„, ๊ฐ€๊ฒŒ์˜ ๋ฆฌ๋ทฐ๋ฅผ ์กฐํšŒํ•˜์—ฌ ๊ณ„์‚ฐ

  • ReviewDao.java
    public GetReviewStarRes reviewStarTotal(int storeIdx){
        String query ="SELECT\n" +
                "      ROUND(AVG(star),1) AS star_average,\n" +
                "      COUNT(*) AS reviews_total,\n" +
                "      COUNT(CASE WHEN star = 1 THEN 1 END) AS star1_count,\n" +
                "      COUNT(CASE WHEN star = 2 THEN 1 END) AS star2_count,\n" +
                "      COUNT(CASE WHEN star = 3 THEN 1 END) AS star3_count,\n" +
                "      COUNT(CASE WHEN star = 4 THEN 1 END) AS star4_count,\n" +
                "      COUNT(CASE WHEN star = 5 THEN 1 END) AS star5_count\n" +
                "      FROM Review\n" +
                "WHERE storeIdx = ? AND status != 'D'";

        return this.jdbcTemplate.queryForObject(query,
                (rs, rowNum) -> new GetReviewStarRes(
                        storeIdx,
                        rs.getDouble("star_average"),
                        rs.getInt("reviews_total"),
                        rs.getInt("star1_count"),
                        rs.getInt("star2_count"),
                        rs.getInt("star3_count"),
                        rs.getInt("star4_count"),
                        rs.getInt("star5_count")
                )
                ,storeIdx);
    }

๊ฐ€๊ฒŒ Id ๊ธฐ์ค€ ๋ณ„์ ์„ ์ง‘๊ณ„ ํ‰๊ท ์œผ๋กœ ์กฐํšŒํ•˜๊ณ , ๊ฐ ๋ณ„์ ์— ๋Œ€ํ•ด์„œ ๊ฐœ์ˆ˜๋ฅผ ์นด์šดํŠธํ•œ๋‹ค.
์นด์šดํŠธํ•œ ๋ณ„์ ์˜ ๊ฐœ์ˆ˜๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์ „์ฒด ๊ฐœ์ˆ˜์—์„œ ์–ผ๋งŒํผ์˜ ๋น„์œจ์„ ๊ฐ€์ง€๋Š”์ง€ ์—ฐ์‚ฐํ•˜์—ฌ ๋ฐ˜ํ™˜ํ•  ์ค€๋น„๋ฅผ ํ•˜๊ธฐ ์œ„ํ•ด ์ฟผ๋ฆฌ๋ฅผ ์ž‘์„ฑํ•จ


2. [GET] /jat/review

๊ฐ€๊ฒŒ์— ์กด์žฌํ•˜๋Š” ๋ฆฌ๋ทฐ ํ™•์ธ

  • ๊ฐ ๋ฆฌ๋ทฐ๋Š” ๋ˆ„๊ฐ€ ์ž‘์„ฑํ•˜์˜€๋Š”์ง€, ํ•ด๋‹น ๋ฆฌ๋ทฐ์˜ ํ‰์ , ์–ด๋–ค ๋ฉ”๋‰ด๋ฅผ ๋ช‡๊ฐœ ๊ตฌ๋งคํ–ˆ๋Š”์ง€, ๋ฆฌ๋ทฐ ๊ธ€, ์‚ฌ์ง„์œผ๋กœ ์ด๋ฃจ์–ด์ ธ์žˆ๋‹ค.
  • ํ•ด๋‹น ๋ถ€๋ถ„์„ ์กฐํšŒํ•˜๊ธฐ ์œ„ํ•ด ์ฟผ๋ฆฌ๋ฅผ ์ž‘์„ฑํ•˜์˜€๊ณ , ๋ฆฌ๋ทฐ ์กฐํšŒ ์‹œ ์ƒํƒœ๋ฅผ ๊ธฐ์ค€์œผ๋กœ ํ™•์ธํ•˜์˜€๋‹ค.
  • ๋ฆฌ๋ทฐ์˜ ์ƒํƒœ์—๋Š” ์ผ๋ฐ˜('A'), ์‹ ๊ณ ๋œ('R'), ์‚ญ์ œ๋œ('D') 3๊ฐ€์ง€๊ฐ€ ์กด์žฌํ•ด์„œ, ์‹ ๊ณ  ๋˜์—ˆ๋”๋ผ๋„ ์•„์ง ๊ด€๋ฆฌ์ž๊ฐ€ ์‚ญ์ œ๋ฅผ ํ•˜์ง€ ์•Š์€ ์ƒํƒœ๋ผ๋ฉด ์กฐํšŒ๋ฅผ ํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•จ.
  • ์‘๋‹ต ๋ฐ”๋””
  • ์ปจํŠธ๋กค๋Ÿฌ
  • ์„œ๋น„์Šค
  1. jwt ๋‚ด ์กด์žฌํ•˜๋Š” userIdx๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์‚ฌ์šฉ์ž ๊ฐ€๊ฒŒ Idx ์กฐํšŒ ํ›„, ์ด์šฉํ•˜์—ฌ ๊ฐ€๊ฒŒ์˜ ๋ฆฌ๋ทฐ ๋ชฉ๋ก์„ ์กฐํšŒ
    ๋ฆฌ๋ทฐ์— ๋”ธ๋ฆฐ ๋ฉ”๋‰ด๋„ ์ถ”๊ฐ€๋กœ ์กฐํšŒํ•ด์•ผ ํ•˜๊ธฐ ๋•Œ๋ฌธ์—, orderIdx๋„ ๊ฐ™์ด ์กฐํšŒํ•˜์˜€๋‹ค.
    public GetReviewRes getReview(int sellerIdx) throws BaseException {
        // 1) ์‚ฌ์šฉ์ž ๊ฐ€๊ฒŒ ์กฐํšŒ
        int storeIdx;
        try {
            storeIdx = storeDao.storeIdxBySellerIdx(sellerIdx);
        } catch (Exception e) {
            throw new BaseException(POST_STORES_NOT_REGISTERD); // 2030 : ์‚ฌ์šฉ์ž์˜ ๊ฐ€๊ฒŒ๊ฐ€ ๋“ฑ๋ก๋˜์–ด์žˆ์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
        }

        // 2) ๋ฆฌ๋ทฐ ์กฐํšŒ
        List<ReviewItems> reviewItems;
        try {
            reviewItems = reviewDao.reviewItems(storeIdx);
        } catch (Exception e) {
            throw new BaseException(BaseResponseStatus.RESPONSE_ERROR);    // ๋ฆฌ๋ทฐ ์กฐํšŒ์— ์‹คํŒจํ•˜์˜€์Šต๋‹ˆ๋‹ค.
        }
  1. ๋ฆฌ๋ทฐ ๋‚ด์— ์กด์žฌํ•˜๋Š” ๋ฆฌ๋ทฐ ์‚ฌ์ง„์„ s3 ์„œ๋น„์Šค๋ฅผ ์ด์šฉํ•˜์—ฌ url์„ ๊ฐ€์ ธ์˜ค๊ณ ,
    ๋ฆฌ๋ทฐ ์ฃผ๋ฌธ ๋‚ด์˜ ๋ฉ”๋‰ด ๋ชฉ๋ก์„ ์ฃผ๋ฌธ Idx๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์กฐํšŒํ•˜๊ธฐ
        // ๋ฆฌ๋ทฐ์— ์‚ฌ์ง„ ์ •๋ณด ์žˆ์œผ๋ฉด s3์—์„œ url ๊ฐ€์ ธ์˜ค๊ธฐ
        try{
            for (ReviewItems item : reviewItems) {
                if(item.getReview_url() != null )
                    item.setReview_url(""+s3Client.getUrl(bucketName, item.getReview_url()));
            }
        }catch (Exception e) {
            throw new BaseException(BaseResponseStatus.RESPONSE_ERROR);    // ๋ฆฌ๋ทฐ ์ด๋ฏธ์ง€ url ์‹คํŒจํ•˜์˜€์Šต๋‹ˆ๋‹ค.
        }

        // 3) ๋ฆฌ๋ทฐ ์ฃผ๋ฌธ ๋‚ด์˜ ๋ฉ”๋‰ด ๋ชฉ๋ก ์กฐํšŒ
        try {
            for (ReviewItems item : reviewItems) {
                item.setOrderTodayMenu(reviewDao.orderTodayMenus(storeIdx, item.getOrderIdx()));
            }
            return new GetReviewRes(storeIdx, reviewItems);
        } catch (Exception e) {
            //System.out.println("exception2: " + e);
            throw new BaseException(BaseResponseStatus.RESPONSE_ERROR);    // ๋ฆฌ๋ทฐ ์กฐํšŒ์— ์‹คํŒจํ•˜์˜€์Šต๋‹ˆ๋‹ค.
        }
    }
  • Dao
// ๋ฆฌ๋ทฐ ๋ชฉ๋ก์„ ์กฐํšŒ -> ์ฃผ๋ฌธIdx, ๋ฆฌ๋ทฐIdx, ๊ตฌ๋งค์ž, ๋ฆฌ๋ทฐํ‰์ , ๋ฆฌ๋ทฐ๋‚ด์šฉ, ๋ฆฌ๋ทฐ๋‹ต๊ธ€, ๋ฆฌ๋ทฐ์ด๋ฏธ์ง€URL
    public List<ReviewItems> reviewItems(int storeIdx) {
        String query = "SELECT\n" +
                "    O.orderIdx,\n" +
                "    R.reviewIdx,\n" +
                "    C.name,\n" +
                "    R.star ,\n" +
                "    R.contents, R.comment, R.review_url\n" +
                "FROM Orders O\n" +
                "JOIN Review R on O.orderIdx = R.orderIdx\n" +
                "JOIN Customers C ON R.customerIdx = C.customerIdx\n" +
                "WHERE\n" +
                "    R.storeIdx = ?\n" +
                "  AND O.status = 'A'\n" +
                "  AND R.status <> 'D'\n" +
                "ORDER BY reviewIdx;"; // 23.07.13 ์ƒํƒœ๊ฐ’ ๊ณ ๊ฐ์ด์“ด ๋ฆฌ๋ทฐ ์ •๋ณด ์—†์œผ๋ฏ€๋กœ ์ˆ˜์ • ํ•„์š”

        return this.jdbcTemplate.query(query,
                (rs, rowNum) -> new ReviewItems(
                        rs.getInt("orderIdx"),
                        rs.getInt("reviewIdx"),
                        rs.getString("name"),
                        rs.getInt("star"),
                        rs.getString("contents"),
                        rs.getString("comment") == null? "" : rs.getString("comment"),
                        rs.getString("review_url"),
                        null
                ), storeIdx);
    }

3. [PATCH] /jat/review/comment

์กฐํšŒ๋œ ๋ฆฌ๋ทฐ์— ๋‹ต๊ธ€ ๋‹ฌ๊ธฐ

  • ๋ฆฌ๋ทฐ ์กฐํšŒ์‹œ ์‘๋‹ต์œผ๋กœ ๋ณด๋‚ด์คฌ๋˜ reviewIdx์™€ ํŒ๋งค์ž๊ฐ€ ๋‹จ ๋‹ต๊ธ€์„ ๋ฐ”๋””๋กœ ๋ฐ›์•„์„œ,
  • ํ•ด๋‹น ๋ฆฌ๋ทฐ๊ฐ€ ๋‹ต๊ธ€์„ ๋‹ฌ ์ˆ˜ ์žˆ๋Š” ์˜ฌ๋ฐ”๋ฅธ ํ˜•์‹์˜ ๋ฆฌ๋ทฐ์ธ์ง€ ๊ฒ€์ฆ์„ ํ•˜๊ณ ,
  • DB์˜ Review ํ…Œ์ด๋ธ”์˜ comment ์นผ๋Ÿผ์— ๊ฐ’์„ ์ฑ„์›Œ์ฃผ๋Š” ๋™์ž‘์„ ์ˆ˜ํ–‰ํ•จ,

4. [POST] /jat/review/report

๋ฆฌ๋ทฐ ์‹ ๊ณ 

  • ๋ฆฌ๋ทฐ ์กฐํšŒ์‹œ ์‘๋‹ต์œผ๋กœ ๋ณด๋‚ด์คฌ๋˜ reviewIdx์™€ ํŒ๋งค์ž๊ฐ€ ๋‹จ ๋‹ต๊ธ€์„ ๋ฐ”๋””๋กœ ๋ฐ›์•„์„œ,
  • DB Reviewํ…Œ์ด๋ธ”์˜ ํ•ด๋‹น ํ–‰์˜ ์ƒํƒœ๊ฐ’์„ 'R'๋กœ ๋ฐ”๊ฟ”์คŒ
    ํ›„์— ๊ด€๋ฆฌ์ž์—์„œ, ์‹ ๊ณ ๋œ ๋ฆฌ๋ทฐ๋ฅผ ์‹๋ณ„ํ•˜๊ธฐ ์œ„ํ•œ ์ƒํƒœ๊ฐ’
profile
๊ฐœ๋ฐœ์ž๊ฐ€ ๊ฟˆ์ธ 25์‚ด ๋Œ€ํ•™์ƒ์ž…๋‹ˆ๋‹ค.

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