2022

    mongoose, MonogoDB 연동

    mongoose, MonogoDB 연동

    이전글 이어서 작성 2022.07.13 - [2022/JavaScript EveryWhere] - express, apollo-server-express, graphql 연동 npm install mongoose dotenv package.json "dependencies": { "dotenv": "^16.0.1", "mongoose": "^6.4.4", } db는 몽고디비 아래주소로 설치하거나 도커로 설치하기 1. https://www.mongodb.com/try/download/community 2. 윈도우 도커로 설치 index.js // .env 파일 내용 불러오기 require('dotenv').config(); const db = require('./db'); // const models = ..

    express,  apollo-server-express, graphql 연동

    express, apollo-server-express, graphql 연동

    node -v : v16.15.1 npm -v : 8.11.0 package.json { "name": "graphql", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "dev": "nodemon node index.js" }, "keywords": [], "author": "", "license": "ISC", "dependencies": { "apollo-server-express": "^3.10.0", "express": "^4.18.1", "graphql": "^16.5.0", "nodemon": "^2.0.19" }..

    react-router

    react-router

    - 보통의 웹 서비스는 URL을 기준으로 화면을 표시한다 - 리액트는 싱글 페이지 애플리케이션의 UI를 만드는 자바스크립트 라이브러리이다. - 리액트에서 사용자가 요청한 URL을 이용하여 특정 컴포넌트를 표시하도록 하기 위해서는 react-router라는 외부 라이브러리를 사용해야 한다 npm install --save react-router-dom npm install --save-dev @types/react-router-dom - Switch -> Routes 로 변경 https://reactrouterdotcom.fly.dev/docs/en/v6/upgrading/v5#upgrade-all-switch-elements-to-routes This is the same app in v6: // Thi..

    장바구니 주문

    1) 장바구니 페이지에서 주문할 상품 데이터를 전달할 DTO 생성 package com.shop.dto; import lombok.Getter; import lombok.Setter; import java.util.List; @Getter @Setter public class CartOrderDto { private Long cartItemId; private List cartOrderDtoList; } 2) 서비스 구현 - OrderService 클래스에 장바구니에서 주문할 상품 데이터를 전달받아서 주문을 생성하는 로직 package com.shop.service; import com.shop.dto.OrderDto; import com.shop.dto.OrderHistDto; import com.sh..

    장바구니 조회

    장바구니 조회

    1) 조회 페이지에 전달할 DTO 클래스 생성 package com.shop.dto; import lombok.Getter; import lombok.Setter; @Getter @Setter public class CartDetailDto { private Long cartItemId; private String itemNm; private int price; private int count; private String imgUrl; public CartDetailDto(Long cartItemId, String itemNm, int price, int count, String imgUrl) { this.cartItemId = cartItemId; this.itemNm = itemNm; this.pri..