From 63a55481d70600f9745e8c5a776a8a1c2f028059 Mon Sep 17 00:00:00 2001 From: MurakawaTakuya Date: Sun, 29 Dec 2024 19:24:40 +0900 Subject: [PATCH] =?UTF-8?q?storedURL=E3=82=92storedId=E3=81=AB=E5=A4=89?= =?UTF-8?q?=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Documents/API.md | 10 +++++----- functions/src/routers/postRouter.ts | 22 +++++++++++----------- functions/src/routers/resultRouter.ts | 2 +- functions/src/types.ts | 2 +- src/Components/PostModal/PostModal.tsx | 2 +- src/Components/Progress/Progress.tsx | 2 +- src/types/types.ts | 2 +- src/utils/API/User/fetchUser.ts | 2 +- 8 files changed, 22 insertions(+), 22 deletions(-) diff --git a/Documents/API.md b/Documents/API.md index 61e5a63..a8491f5 100644 --- a/Documents/API.md +++ b/Documents/API.md @@ -108,7 +108,7 @@ API is provided by Firebase Cloud Functions. Database is provided by Firestore. "text": "hoge fuga", "post": { "userId": "Vlx6GCtq90ag3lxgh0pcCKGp5ba0", - "storedURL": "0f9a84ed-8ae8-44b0-a6f5-5ac5ca517948", + "storedId": "0f9a84ed-8ae8-44b0-a6f5-5ac5ca517948", "text": "数学の勉強したよ^^", "submittedAt": { "_seconds": 1735603199, @@ -151,14 +151,14 @@ API is provided by Firebase Cloud Functions. Database is provided by Firestore. - Body (form-data) - goalId: string - text: string - - storedURL: string (画像のストレージパス、/post/{storedURL}/image) + - storedId: string (画像のストレージパス、/post/{storedId}/image) - submittedAt: Date - Example ```json { "goalId": "RXlHJiv3GtpzSDHhfljS", "text": "今日は勉強をがんばった", - "storedURL": "0f9a84ed-8ae8-44b0-a6f5-5ac5ca517948", + "storedId": "0f9a84ed-8ae8-44b0-a6f5-5ac5ca517948", "submittedAt": "2024-12-31T23:59:59.000Z" } ``` @@ -182,7 +182,7 @@ API is provided by Firebase Cloud Functions. Database is provided by Firestore. "goalId": "9fgWJA6wMN54EkxIC2WD", "userId": "IK0Zc2hoUYaYjXoqzmCl", "text": "今日は勉強をがんばった", - "storedURL": "0f9a84ed-8ae8-44b0-a6f5-5ac5ca517948", + "storedId": "0f9a84ed-8ae8-44b0-a6f5-5ac5ca517948", "goalId": "RXlHJiv3GtpzSDHhfljS", "submittedAt": "2024-12-31T23:59:59.000Z" } @@ -215,7 +215,7 @@ Use Create Post API to update post. "text": "Duolingoやる", "post": { "text": "フランス語したよ", - "storedURL": "0f9a84ed-8ae8-44b0-a6f5-5ac5ca517948", + "storedId": "0f9a84ed-8ae8-44b0-a6f5-5ac5ca517948", "submittedAt": "2024-12-28T09:45:10.718Z" }, "userData": { diff --git a/functions/src/routers/postRouter.ts b/functions/src/routers/postRouter.ts index 0d83d81..9586677 100644 --- a/functions/src/routers/postRouter.ts +++ b/functions/src/routers/postRouter.ts @@ -25,7 +25,7 @@ router.get("/", async (req: Request, res: Response) => { goalId: goalDoc.id, userId: goalData.userId, text: goalData.post.text, - storedURL: goalData.post.storedURL, + storedId: goalData.post.storedId, submittedAt: goalData.post.submittedAt.toDate(), }); } @@ -69,7 +69,7 @@ router.get("/:userId", async (req: Request, res: Response) => { goalId: goalDoc.id, userId: goalData.userId, text: goalData.post.text, - storedURL: goalData.post.storedURL, + storedId: goalData.post.storedId, submittedAt: goalData.post.submittedAt.toDate(), }); } @@ -86,19 +86,19 @@ router.get("/:userId", async (req: Request, res: Response) => { router.post("/", async (req: Request, res: Response) => { let goalId: PostWithGoalId["goalId"]; let text: PostWithGoalId["text"]; - let storedURL: PostWithGoalId["storedURL"]; + let storedId: PostWithGoalId["storedId"]; let submittedAt: PostWithGoalId["submittedAt"]; try { - ({ goalId, text = "", storedURL, submittedAt } = req.body); + ({ goalId, text = "", storedId, submittedAt } = req.body); } catch (error) { logger.error(error); return res.status(400).json({ message: "Invalid request body" }); } - if (!goalId || !storedURL || !submittedAt) { + if (!goalId || !storedId || !submittedAt) { return res.status(400).json({ - message: "userId, storedURL, goalId, and submittedAt are required", + message: "userId, storedId, goalId, and submittedAt are required", }); } @@ -119,7 +119,7 @@ router.post("/", async (req: Request, res: Response) => { await goalRef.update({ post: { text, - storedURL, + storedId, submittedAt: new Date(submittedAt), }, }); @@ -146,14 +146,14 @@ router.delete("/:goalId", async (req: Request, res: Response) => { } // Storageから画像を削除 - const storedURL = goalDoc.data()?.post?.storedURL; - if (storedURL) { + const storedId = goalDoc.data()?.post?.storedId; + if (storedId) { try { // Firebase Admin SDKのStorageを使用 const bucket = admin.storage().bucket(); - const file = bucket.file(`post/${storedURL}`); + const file = bucket.file(`post/${storedId}`); await file.delete(); - logger.info("Image deleted successfully:", storedURL); + logger.info("Image deleted successfully:", storedId); } catch (error) { logger.error("Error deleting image:", error); return res.status(500).json({ message: "Error deleting image" }); diff --git a/functions/src/routers/resultRouter.ts b/functions/src/routers/resultRouter.ts index fec7661..4d2bfd5 100644 --- a/functions/src/routers/resultRouter.ts +++ b/functions/src/routers/resultRouter.ts @@ -49,7 +49,7 @@ const getResults = async ( text: data.text, post: post && { text: post.text, - storedURL: post.storedURL, + storedId: post.storedId, submittedAt: post.submittedAt.toDate(), }, }; diff --git a/functions/src/types.ts b/functions/src/types.ts index bdd99b8..c067b2c 100644 --- a/functions/src/types.ts +++ b/functions/src/types.ts @@ -24,7 +24,7 @@ export interface GoalWithIdAndUserData extends Goal { export interface Post { userId?: string; - storedURL: string; + storedId: string; text: string; submittedAt: Date; } diff --git a/src/Components/PostModal/PostModal.tsx b/src/Components/PostModal/PostModal.tsx index 59eaa76..eaae85b 100644 --- a/src/Components/PostModal/PostModal.tsx +++ b/src/Components/PostModal/PostModal.tsx @@ -95,7 +95,7 @@ export default function PostModal({ async (url, id) => { const postData: PostWithGoalId = { userId: user?.userId as string, - storedURL: id, + storedId: id, text: text, goalId: goalId, submittedAt: new Date(), diff --git a/src/Components/Progress/Progress.tsx b/src/Components/Progress/Progress.tsx index 1b86486..e83a1f3 100644 --- a/src/Components/Progress/Progress.tsx +++ b/src/Components/Progress/Progress.tsx @@ -126,7 +126,7 @@ const SuccessStep = ({ } const storage = getStorage(); - const imageRef = ref(storage, `post/${post.storedURL}`); + const imageRef = ref(storage, `post/${post.storedId}`); getDownloadURL(imageRef) .then((url) => { diff --git a/src/types/types.ts b/src/types/types.ts index a78304f..c7fe0df 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -25,7 +25,7 @@ export interface GoalWithIdAndUserData extends Goal { export interface Post { userId: string; - storedURL: string; + storedId: string; text: string; submittedAt: Date | string; } diff --git a/src/utils/API/User/fetchUser.ts b/src/utils/API/User/fetchUser.ts index 5a9c832..2416897 100644 --- a/src/utils/API/User/fetchUser.ts +++ b/src/utils/API/User/fetchUser.ts @@ -30,7 +30,7 @@ export const fetchUserById = async (userId: string): Promise => { * @return {*} */ export const handleFetchUserError = (error: unknown) => { - let snackBarMessage = "ユーザー情報の取得に失敗しました"; + let snackBarMessage = "初回ログインかユーザーデータが見つかりません"; if (error instanceof Error) { console.error("Fetch error:", error.message);