9oj0e / pathorder_server

3 stars 4 forks source link

refactor: menu, order, store (style: comment, lines) (docs: todos) #18

Closed 9oj0e closed 2 months ago

9oj0e commented 2 months ago

업데이트

구조 변경

스크린샷 2024-04-28 오후 3 38 20 스크린샷 2024-04-28 오후 3 31 07

설명

  1. menu controller 삭제
    • 메뉴가 독단적으로 url요청을 받아서 처리하는 로직이 말이 안된다고 생각.
  2. menu service -> store service (매장 메뉴보기, 매장 메뉴 옵션보기)
    • 메뉴가 독단적으로 비즈니스 로직을 처리하지 않음 -> 삭제.
    • 메뉴와 옵션을 보여주는 로직은 주체인 매장에 의해 처리됨. 매장의 서비스로 이동.
    • 객체를 담는 별도의 패키지 menu의 존재 이유: 1) store에서도 참조하지만, order에서도 참조. 2) 별도의 레파지토리.
  3. order controller -> store controller (매장 메뉴보기, 매장 메뉴 옵션보기)
    • 메뉴와 메뉴 옵션은 매장에 종속된 객체.
    • Q: 주문하는 단계라, 주문 컨트롤러에 있어야 하지 않나?
    • A: 주문하기 전 단계, 즉 장바구니에 담기기 직전의 단계라 생각함.
  4. order controller -> user controller (주문내역 목록보기, 주문내역 상세보기)
    • 비즈니스 처리 주체는 user와 store.
    • user controller, store owner controller로 할당. 각각 서비스, DTO로 처리
    • Q: 그렇다면 order controller에서 처리하는 비즈니스는?
    • A: 주문 등록, 주문 수정(주문 update)

기타

리펙토링 (과정)

스크린샷 2024-04-28 오후 4 02 11 스크린샷 2024-04-28 오후 3 25 24 스크린샷 2024-04-28 오후 3 26 52

리펙토링 (코드)

@Data // 매장 메뉴 목록보기
    public static class MenuListDTO {
        // 매장 정보
        private int storeId;
        private String storeName;
        // 메뉴 정보
        private List<MenuDTO> menuList;

        public MenuListDTO(Store store, List<Menu> menus) {
            this.storeId = store.getId();
            this.storeName = store.getName();
            this.menuList = menus.stream().map(MenuDTO::new).toList();
        }

        @Data
        private class MenuDTO {
            private int id;
            private String category;
            private String name;
            private String imgFilename;
            private String description;
            private int price;

            public MenuDTO(Menu menu) {
                this.id = menu.getId();
                this.category = menu.getCategory();
                this.name = menu.getName();
                this.imgFilename = menu.getImgFilename();
                this.description = menu.getDescription();
                this.price = menu.getPrice();
            }
        }
    }

문제가 될 수 있는 코드

스크린샷 2024-04-28 오후 7 29 40