inflearn logo
강의

Khóa học

Chia sẻ kiến thức

Một trại huấn luyện phát triển toàn diện thực sự dành cho những người không chuyên ngành

Thêm API Chi tiết SP

질문있습니다.

316

yami654

11 câu hỏi đã được viết

1

postman에서 http://localhost:8080/products/1 여기 id 부분을 2, 3으로 변경해도 똑같이 키보드 내용만 나옵니다.

DB에서 데이터 보기 했을 때 아래 사진처럼 나와서 제대로 실행이 안되는 건가요???

tensorflow javascript nodejs HTML/CSS express 머신러닝 배워볼래요? react-native react

Câu trả lời 3

0

yami654

server.js 소스 코드 입니다~!

const express = require("express");
const cors = require("cors");
const app = express();
const models = require("./models");
const port = 8080;

app.use(express.json());
app.use(cors());

app.get("/products", (req, res) => {
  models.Product.findAll()
    .then((result) => {
      console.log("PRODUCTS: ", result);
      res.send({
        products: result,
      });
    })
    .catch((error) => {
      console.error(error);
      res.send("에러 발생");
    });
});

app.post("/products", (req, res) => {
  const body = req.body;
  const { name, description, price, seller } = body;
  if (!name || !description || !price || !seller) {
    res.send("모든필드를 입력해주세요.");
  }
  models.Product.create({
    name,
    description,
    price,
    seller,
  })
    .then((result) => {
      console.log("상품 생성 결과 : ", result);
      res.send({
        result,
      });
    })
    .catch((error) => {
      console.error(error);
      res.send("상품 업로드에 문제가 발생했습니다.");
    });
});

app.get("/products/:id", (req, res) => {
  const params = req.params;
  const { id } = params;
  models.Product.findOne({
    vhere: {
      id: id,
    },
  })
    .then((result) => {
      console.log("PRODUCTS :", result);
      res.send({
        product: result,
      });
    })
    .catch((error) => {
      console.error(error);
      res.send("상품 조회에 에러가 발생했습니다.");
    });
});

app.listen(port, () => {
  console.log("그랩의 쇼핑몰 서버가 돌아가고 있습니다.");
  models.sequelize
    .sync()
    .then(() => {
      console.log("DB 연결 성공!");
    })
    .catch((error) => {
      console.error(err);
      console.log("DB 연결 에러");
      process.exit();
    });
});

그리고 postman에서 id를 10으로 했을 때( http://localhost:8080/products/10 )  아래 사진처럼 응답이 나옵니다.

0

grab

models.product.findOne 코드를 보면 인자로 vhere이라고 오타가 있네요! where로 바꿔주시면 정상적으로 동작할 것 같아요:)

0

yami654

와...!... 감사합니다. 해결됐어요!!

0

yami654

id 에 다른 값을 넣어도 내용이 변하질 않고 계속 키보드에 대한 내용만 나와요..

그리고 DB목록에 내용이 많아졌는데 삭제를 해도 될까요???

0

grab

넵 DB 레코드를 삭제해도 괜찮습니다.

0

grab

server.js 소스코드를 올려주시면 확인이 빠를 것 같습니다~!

0

grab

현재 id가 1,2,3인 녀석들을 보면 전부 키보드인 것을 확인할 수 있습니다.

id를 7,8로 넣으면 다른 값이 나올 것 같아요!

<div id="banner">배너 이미지</div> 관련 질문

0

91

1

[해결]그랩님 답변 주세요.

0

269

2

그랩님의 답변을 기다립니다/102강 전반적인 에러

0

239

2

[그랩님께]101강 안드로이드 에러들(Key prop)해결방법 궁금합니다.

0

199

2

[재질문][그랩님 답변 부탁드립니다]101강

0

264

2

[그랩님 답변 부탁드립니다]101강 Axios 에러와 502 Bad Gateway 질문

0

237

2

Ngrok 설치 후 forwarding Url 에러

0

216

2

[그랩님께,Ngrok 악성코드 인식 해결방법]질문 드립니다.

0

362

2

Ngrok 설치 후 forwarding Url로 연결 불가

0

207

1

그랩님,[꼭] 답변 부탁드립니다.

0

154

1

[꼭][[꼭] 그랩님, 답변 부탁드립니다], Failed to load resource: the server responded with a status of 404 (Not Found) 상품 상세 페이지 질문입니다.

0

207

1

6강/7강 수업

0

93

1

그랩님, 상품 상세 페이지 에러와 의문점 질문드립니다.

0

153

2

그랩님, 해결되지 않은 에러 메시지 [꼭] 답변 부탁 드립니다.

0

195

2

[재 질문]Cannot read properties of undefined (reading 'map') TypeError: Cannot read properties of undefined (reading 'map') 에러 해결 어떻게 하나요?

0

158

1

Cannot read properties of undefined (reading 'map') TypeError: Cannot read properties of undefined (reading 'map') 에러 해결 어떻게 하나요?

0

246

2

일반적인 css 꾸미기에서 width와 height의 값?

0

152

2

Windows에서의 업로드 후 홈화면 상품이미지 오류 해결방법

0

257

1

그랩마켓 웹화면 구현하기 -2 질문입니다.

0

168

1

react에 반영이 되지 않습니다.

0

305

1

터미널 npm install -g create-react-app 작성 후 오류

0

480

1

create-react-app my app 실행 시 에러

0

415

2

포스트맨 질문

0

141

1

<꼭 답변 부탁 드립니다>그랩선생님, [컴포넌트 사용하기] 강의에서 질문 있습니다.

0

325

2