Skip to content

Commit

Permalink
Merge branch 'main' into feat/124-merge-goal-post
Browse files Browse the repository at this point in the history
  • Loading branch information
MurakawaTakuya committed Dec 28, 2024
2 parents 83ac316 + 5842019 commit ab91af8
Show file tree
Hide file tree
Showing 15 changed files with 897 additions and 782 deletions.
2 changes: 1 addition & 1 deletion functions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import cors from "cors";
import express from "express";
import { rateLimit } from "express-rate-limit";
import admin from "firebase-admin";
import * as logger from "firebase-functions/logger";
import { logger } from "firebase-functions";
import { onRequest } from "firebase-functions/v2/https";
import helmet from "helmet";
import serviceAccount from "./serviceAccountKey.json";
Expand Down
7 changes: 7 additions & 0 deletions functions/src/routers/goalRouter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import express, { Request, Response } from "express";
import admin from "firebase-admin";
import { logger } from "firebase-functions";
import { Goal, GoalWithId } from "./types";

const router = express.Router();
Expand Down Expand Up @@ -27,6 +28,7 @@ router.get("/", async (req: Request, res: Response) => {

return res.json(goalData);
} catch (error) {
logger.error(error);
return res.status(500).json({ message: "Error fetching goals" });
}
});
Expand Down Expand Up @@ -62,6 +64,7 @@ router.get("/:userId", async (req: Request, res: Response) => {

return res.json(goalData);
} catch (error) {
logger.error(error);
return res.status(500).json({ message: "Error fetching goals" });
}
});
Expand All @@ -75,6 +78,7 @@ router.post("/", async (req: Request, res: Response) => {
try {
({ userId, deadline, text } = req.body as Goal);
} catch (error) {
logger.error(error);
return res.status(400).json({ message: "Invalid request body" });
}

Expand All @@ -100,6 +104,7 @@ router.post("/", async (req: Request, res: Response) => {
.status(201)
.json({ message: "Goal created successfully", goalId });
} catch (error) {
logger.error(error);
return res.status(500).json({ message: "Error creating goal" });
}
});
Expand Down Expand Up @@ -134,6 +139,7 @@ router.put("/:goalId", async (req: Request, res: Response) => {
await db.collection("goal").doc(goalId).update(updateData);
return res.json({ message: "Goal updated successfully", goalId });
} catch (error) {
logger.error(error);
return res.status(500).json({ message: "Error updating goal" });
}
});
Expand All @@ -150,6 +156,7 @@ router.delete("/:goalId", async (req: Request, res: Response) => {
await db.collection("goal").doc(goalId).delete();
return res.json({ message: "Goal deleted successfully", goalId });
} catch (error) {
logger.error(error);
return res.status(500).json({ message: "Error deleting goal" });
}
});
Expand Down
8 changes: 7 additions & 1 deletion functions/src/routers/postRouter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import express, { Request, Response } from "express";
import admin from "firebase-admin";
import { logger } from "firebase-functions";
import { PostWithGoalId } from "./types";

const router = express.Router();
Expand Down Expand Up @@ -35,6 +36,7 @@ router.get("/", async (req: Request, res: Response) => {

return res.json(postData);
} catch (error) {
logger.error(error);
return res.status(500).json({ message: "Error fetching posts" });
}
});
Expand Down Expand Up @@ -74,7 +76,8 @@ router.get("/:userId", async (req: Request, res: Response) => {

return res.json(postData);
} catch (error) {
return res.status(500).json({ message: "Error fetching posts" });
logger.error(error);
return res.status(500).json({ message: "Error fetching user's posts" });
}
});

Expand All @@ -89,6 +92,7 @@ router.post("/", async (req: Request, res: Response) => {
try {
({ userId, storedURL, text = "", goalId, submittedAt } = req.body);
} catch (error) {
logger.error(error);
return res.status(400).json({ message: "Invalid request body" });
}

Expand Down Expand Up @@ -119,6 +123,7 @@ router.post("/", async (req: Request, res: Response) => {
.status(201)
.json({ message: "Post created successfully", goalId });
} catch (error) {
logger.error(error);
return res.status(500).json({ message: "Error creating post" });
}
});
Expand All @@ -141,6 +146,7 @@ router.delete("/:goalId", async (req: Request, res: Response) => {

return res.json({ message: "Post deleted successfully" });
} catch (error) {
logger.error(error);
return res.status(500).json({ message: "Error deleting post" });
}
});
Expand Down
2 changes: 2 additions & 0 deletions functions/src/routers/resultRouter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import express, { Request, Response } from "express";
import admin from "firebase-admin";
import { logger } from "firebase-functions";
import { GoalWithIdAndUserData, User } from "./types";

const router = express.Router();
Expand Down Expand Up @@ -131,6 +132,7 @@ router.get("/:userId?", async (req: Request, res: Response) => {
);
return res.json(results);
} catch (error) {
logger.info(error);
return res.status(500).json({ message: "Error fetching results" });
}
});
Expand Down
8 changes: 8 additions & 0 deletions functions/src/routers/userRouter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import express, { Request, Response } from "express";
import admin from "firebase-admin";
import { logger } from "firebase-functions";
import { User } from "./types";

const router = express.Router();
Expand All @@ -25,6 +26,7 @@ router.get("/", async (req: Request, res: Response) => {

return res.json(userData);
} catch (error) {
logger.error(error);
return res.status(500).json({ message: "Error fetching user data" });
}
});
Expand Down Expand Up @@ -54,6 +56,7 @@ router.get("/id/:userId", async (req: Request, res: Response) => {

return res.json(userData);
} catch (error) {
logger.error(error);
return res.status(500).json({ message: "Error fetching user data" });
}
});
Expand Down Expand Up @@ -84,6 +87,7 @@ router.get("/name/:userName", async (req: Request, res: Response) => {

return res.json(userData);
} catch (error) {
logger.error(error);
return res.status(500).json({ message: "Error fetching user data" });
}
});
Expand All @@ -97,6 +101,7 @@ router.post("/", async (req: Request, res: Response) => {
try {
({ name, userId, fcmToken = "" } = req.body);
} catch (error) {
logger.error(error);
return res.status(400).json({ message: "Invalid request body" });
}

Expand All @@ -115,6 +120,7 @@ router.post("/", async (req: Request, res: Response) => {
.status(201)
.json({ message: "User created successfully", userId });
} catch (error) {
logger.error(error);
return res.status(500).json({ message: "Error creating user" });
}
});
Expand Down Expand Up @@ -142,6 +148,7 @@ router.put("/:userId", async (req: Request, res: Response) => {
await db.collection("user").doc(userId).update(updateData);
return res.json({ message: "User updated successfully", userId });
} catch (error) {
logger.error(error);
return res.status(500).json({ message: "Error updating user" });
}
});
Expand All @@ -158,6 +165,7 @@ router.delete("/:userId", async (req: Request, res: Response) => {
await db.collection("user").doc(userId).delete();
return res.json({ message: "User deleted successfully", userId });
} catch (error) {
logger.error(error);
return res.status(500).json({ message: "Error deleting user" });
}
});
Expand Down
4 changes: 2 additions & 2 deletions functions/src/tasks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CloudTasksClient } from "@google-cloud/tasks";
import * as admin from "firebase-admin";
import * as logger from "firebase-functions/logger";
import { logger } from "firebase-functions";
import {
onDocumentCreated,
onDocumentDeleted,
Expand Down Expand Up @@ -72,7 +72,7 @@ export const createTasksOnGoalCreate = onDocumentCreated(
});
logger.info("Task created for goalId:", goalId);
} catch (error) {
logger.info("Error scheduling task:", error);
logger.error("Error scheduling task:", error);
}
}
);
Expand Down
Loading

0 comments on commit ab91af8

Please sign in to comment.