Skip to content

Commit

Permalink
Added get
Browse files Browse the repository at this point in the history
  • Loading branch information
niccholasw committed Aug 26, 2024
1 parent 775b5a2 commit 1f81709
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion backend/controllers/DonutController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,17 @@ import { Request, Response } from "express";
import { DonutModel } from "../models/donutSchema";

const getDonut = async (req: Request, res: Response) => {
res.send("Hello from the user controller!");
try {
const donuts = await DonutModel.find({});

if (donuts.length === 0) {
return res.status(404).send("No donuts found!");
}
res.status(200).json(donuts);
} catch (error: any) {
console.error("Error:", error);
res.status(500).send("Internal server error");
}
};

const createDonut = async (req: Request, res: Response) => {
Expand Down

0 comments on commit 1f81709

Please sign in to comment.