diff --git a/frontend/src/constants/errorMessages.ts b/frontend/src/constants/errorMessages.ts
index 3e7179d..909bbfa 100644
--- a/frontend/src/constants/errorMessages.ts
+++ b/frontend/src/constants/errorMessages.ts
@@ -21,3 +21,11 @@ export const TASK_ERRORS = {
UPDATE_FAILED: 'タスクの更新に失敗しました',
DELETE_FAILED: 'タスクの削除に失敗しました',
};
+
+// 買うものリスト関連のエラーメッセージ
+export const TOBUY_ERRORS = {
+ FETCH_FAILED: '買うものリストの取得に失敗しました',
+ CREATE_FAILED: '買うものリストの作成に失敗しました',
+ UPDATE_FAILED: '買うものリストの更新に失敗しました',
+ DELETE_FAILED: '買うものリストの削除に失敗しました',
+};
diff --git a/frontend/src/pages/TaskListPage.tsx b/frontend/src/pages/TaskListPage.tsx
index 975f836..5ec6c38 100644
--- a/frontend/src/pages/TaskListPage.tsx
+++ b/frontend/src/pages/TaskListPage.tsx
@@ -146,7 +146,7 @@ const TaskListPage: React.FC = () => {
{/* タスク一覧をマップして各タスクをリストアイテムとして表示 */}
- {tobuys.map((tobuy) => (
+ {tobuys && tobuys.map((tobuy) => (
=> {
- // const response = await fetch(`${API_BASE_URL}/api/tobuy/get`, {
- // headers: getHeaders(), // 認証トークンを含むヘッダー
- // });
-
- // if (!response.ok) {
- // throw new Error(TASK_ERRORS.FETCH_FAILED);
- // }
-
- // return response.json();
+ const response = await fetch(`${API_BASE_URL}/api/tobuy/get`, {
+ headers: getHeaders(), // 認証トークンを含むヘッダー
+ });
- return {
- "tobuy_array": [
- {
- "tobuy_id": 1,
- "stuff_id": 2,
- "stuff_name": "じゃがいも",
- "amount": 3,
- "shop": "shopXXX"
- },
- {
- "tobuy_id": 2,
- "stuff_id": 5,
- "stuff_name": "にんじん",
- "amount": 1
- }
- ]
+ if (!response.ok) {
+ throw new Error(TOBUY_ERRORS.FETCH_FAILED);
}
+ const tobuy_array = await response.json();
+ return {tobuy_array};
+
+ // return {
+ // "tobuy_array": [
+ // {
+ // "tobuy_id": 1,
+ // "stuff_id": 2,
+ // "stuff_name": "じゃがいも",
+ // "amount": 3,
+ // "shop": "shopXXX"
+ // },
+ // {
+ // "tobuy_id": 2,
+ // "stuff_id": 5,
+ // "stuff_name": "にんじん",
+ // "amount": 1
+ // }
+ // ]
+ // }
+
},
/**
@@ -129,24 +130,25 @@ export const toBuyApi = {
* @returns 作成された材料情報
*/
addToBuy: async (tobuy: Omit & { stuff_id: number | null, category: string }): Promise => {
- // const response = await fetch(`${API_BASE_URL}/api/tasks`, {
- // method: 'POST',
- // headers: getHeaders(),
- // body: JSON.stringify(tobuy),
- // });
+ const response = await fetch(`${API_BASE_URL}/api/tobuy/add`, {
+ method: 'POST',
+ headers: getHeaders(),
+ body: JSON.stringify(tobuy),
+ });
- // if (!response.ok) {
- // throw new Error(TASK_ERRORS.CREATE_FAILED);
- // }
+ if (!response.ok) {
+ throw new Error(TOBUY_ERRORS.CREATE_FAILED);
+ }
// return response.json();
+ return {result: true}
- return {
- "result": true,
- "tobuy_id": 1,
- "stuff_id": 6,
- "message": "追加に成功しました",
- }
+ // return {
+ // "result": true,
+ // "tobuy_id": 1,
+ // "stuff_id": 6,
+ // "message": "追加に成功しました",
+ // }
},
@@ -155,19 +157,21 @@ export const toBuyApi = {
* @param id 削除対象の買うものリストID
*/
deleteToBuy: async (tobuy_id: number): Promise<{ result: boolean }> => {
- // const response = await fetch(`${API_BASE_URL}/api/tobuy/delete`, {
- // method: 'DELETE',
- // headers: getHeaders(),
- // body: JSON.stringify({tobuy_id}),
- // });
-
- // if (!response.ok) {
- // throw new Error(TASK_ERRORS.DELETE_FAILED);
- // }
+ const response = await fetch(`${API_BASE_URL}/api/tobuy/delete`, {
+ method: 'DELETE',
+ headers: getHeaders(),
+ body: JSON.stringify({tobuy_id}),
+ });
- return {
- "result": true
+ if (!response.ok) {
+ throw new Error(TOBUY_ERRORS.DELETE_FAILED);
}
+
+ return response.json()
+
+ // return {
+ // "result": true
+ // }
},
}