|
|
|
@ -3,7 +3,7 @@ |
|
|
|
|
* バックエンドAPIとの通信を担当するモジュール |
|
|
|
|
* 認証、タスク管理などの機能を提供 |
|
|
|
|
*/ |
|
|
|
|
import { LoginCredentials, RegisterCredentials, AuthResponse, Task, ToBuy } from '../types/types'; |
|
|
|
|
import { LoginCredentials, RegisterCredentials, AuthResponse, Task, ToBuy, Stuff } from '../types/types'; |
|
|
|
|
import { AUTH_ERRORS, TASK_ERRORS } from '../constants/errorMessages'; |
|
|
|
|
|
|
|
|
|
// APIのベースURL - 環境変数から取得するか、デフォルト値を使用
|
|
|
|
@ -171,6 +171,48 @@ export const toBuyApi = { |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export const stuffApi = { |
|
|
|
|
getStuffs: async (category: string): Promise<{ stuff_array: Stuff[] }> => { |
|
|
|
|
const data = [ |
|
|
|
|
{ "stuff_id": 1, "stuff_name": "牛乳", "category": "乳製品" }, |
|
|
|
|
{ "stuff_id": 2, "stuff_name": "ヨーグルト", "category": "乳製品" }, |
|
|
|
|
{ "stuff_id": 3, "stuff_name": "チーズ", "category": "乳製品" }, |
|
|
|
|
{ "stuff_id": 4, "stuff_name": "バター", "category": "乳製品" }, |
|
|
|
|
{ "stuff_id": 5, "stuff_name": "生クリーム", "category": "乳製品" }, |
|
|
|
|
|
|
|
|
|
{ "stuff_id": 6, "stuff_name": "鮭", "category": "魚・肉" }, |
|
|
|
|
{ "stuff_id": 7, "stuff_name": "鶏むね肉", "category": "魚・肉" }, |
|
|
|
|
{ "stuff_id": 8, "stuff_name": "豚バラ肉", "category": "魚・肉" }, |
|
|
|
|
{ "stuff_id": 9, "stuff_name": "牛ひき肉", "category": "魚・肉" }, |
|
|
|
|
{ "stuff_id": 10, "stuff_name": "まぐろ", "category": "魚・肉" }, |
|
|
|
|
|
|
|
|
|
{ "stuff_id": 11, "stuff_name": "にんじん", "category": "野菜" }, |
|
|
|
|
{ "stuff_id": 12, "stuff_name": "キャベツ", "category": "野菜" }, |
|
|
|
|
{ "stuff_id": 13, "stuff_name": "ほうれん草", "category": "野菜" }, |
|
|
|
|
{ "stuff_id": 14, "stuff_name": "玉ねぎ", "category": "野菜" }, |
|
|
|
|
{ "stuff_id": 15, "stuff_name": "ピーマン", "category": "野菜" }, |
|
|
|
|
|
|
|
|
|
{ "stuff_id": 16, "stuff_name": "醤油", "category": "調味料" }, |
|
|
|
|
{ "stuff_id": 17, "stuff_name": "味噌", "category": "調味料" }, |
|
|
|
|
{ "stuff_id": 18, "stuff_name": "塩", "category": "調味料" }, |
|
|
|
|
{ "stuff_id": 19, "stuff_name": "砂糖", "category": "調味料" }, |
|
|
|
|
{ "stuff_id": 20, "stuff_name": "酢", "category": "調味料" }, |
|
|
|
|
|
|
|
|
|
{ "stuff_id": 21, "stuff_name": "米", "category": "その他" }, |
|
|
|
|
{ "stuff_id": 22, "stuff_name": "パスタ", "category": "その他" }, |
|
|
|
|
{ "stuff_id": 23, "stuff_name": "小麦粉", "category": "その他" }, |
|
|
|
|
{ "stuff_id": 24, "stuff_name": "卵", "category": "その他" }, |
|
|
|
|
{ "stuff_id": 25, "stuff_name": "豆腐", "category": "その他" } |
|
|
|
|
] |
|
|
|
|
|
|
|
|
|
const filtered = data.filter(stuff => stuff.category == category) |
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
"stuff_array": filtered |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* (サンプル,実際には不要) |
|
|
|
@ -216,7 +258,7 @@ export const taskApi = { |
|
|
|
|
* @param task 作成するタスク情報(価格,作成日時、更新日時は除外) |
|
|
|
|
* @returns 作成されたタスク情報 |
|
|
|
|
*/ |
|
|
|
|
addStuff: async (task: Omit<Task, 'userId'|'createdAt'|'price'|'buyDate'|'expirationDate'|'newAddition' >): Promise<Task> => { |
|
|
|
|
addStuff: async (task: Omit<Task, 'userId' | 'createdAt' | 'price' | 'buyDate' | 'expirationDate' | 'newAddition'>): Promise<Task> => { |
|
|
|
|
const response = await fetch(`${API_BASE_URL}/api/tubuy/add`, { |
|
|
|
|
method: 'POST', |
|
|
|
|
headers: getHeaders(), |
|
|
|
|