Najah7 / Pokemon-Stats-Checker

For December Hackathon
1 stars 0 forks source link

[Add] リクエストの処理追加 (#12, #13) #48

Closed yudaisugiyama closed 10 months ago

yudaisugiyama commented 10 months ago

get.tsで書いてた処理だけどコンフリクトしそうなのでapiRequest.tsを新しく作りました。get.tsのgetUrl()とpost.ts消して大丈夫です。

AWSのリージョン変更に伴ってAPI_KEYも変更しました。slackで再度共有いたします。

↓動作確認用コード

import { getRequest, postRequest } from "./apiRequests";

  // GET
  const userName = "sugiyama";
  var response = getRequest(userName);
  console.log(response);

  // POST
  const data = {
  "baseStats": {
    "hp": 100,
    "attack": 100,
    "defense": 100,
    "specialAttack": 100,
    "specialDefense": 100,
    "speed": 100
  },
  "userName": "sugiyama",
  "pokemonID": 1,
  "color": {
    "fillColor": "gold",
    "lineColor": "yellow"
  }
}
  response = postRequest(data);
  // Add a 20-second delay
  setTimeout(() => {
    console.log(response);
  }, 20000);
yudaisugiyama commented 10 months ago

@umaidashi postの方のdataのtype. これでわかるかな..準備できてなくてすみません.

{
  “type”: “object”,
  “properties”: {
    “baseStats”: {
      “type”: “object”,
      “properties”: {
        “hp”: { “type”: “integer” },
        “attack”: { “type”: “integer” },
        “defense”: { “type”: “integer” },
        “specialAttack”: { “type”: “integer” },
        “specialDefense”: { “type”: “integer” },
        “speed”: { “type”: “integer” }
      },
      “required”: [“hp”, “attack”, “defense”, “specialAttack”, “specialDefense”, “speed”]
    },
    “userName”: { “type”: “string” },
    “pokemonID”: { “type”: “integer” },
    “color”: {
      “type”: “object”,
      “properties”: {
        “fillColor”: { “type”: “string” },
        “lineColor”: { “type”: “string” }
      },
      “required”: [“fillColor”, “lineColor”]
    }
  },
  “required”: [“baseStats”, “userName”, “pokemonID”, “color”]
}
umaidashi commented 10 months ago

@yudaisugiyama 型情報ありがとうございます!! pythonのオブジェクトですよね?

bodyの形に直したら↓になりますか??

const body = {
  "baseStats": {
    “hp”: 100,
    “attack”: 100,
    “defense”: 100,
    “specialAttack”: 100,
    “specialDefense”: 100,
    “speed”: 100,
  },
  "useName": "umaidashi",
  "pokemonID": 1,
}

colorはmongoDBに持ってないって話でしたっけ??