Skip to content

Commit

Permalink
Merge pull request #86 from tomilola-oluwafemi/TMP_TOMI
Browse files Browse the repository at this point in the history
ADDED CONTROLLER AND ROUTES PATH TO PROVIDE ENDPOINT FOR GETTING AL TESTIMONIALS AND DELETING SINGLE TESTIMONIAL
  • Loading branch information
Idimmusix authored Jul 22, 2024
2 parents 7290bba + 6b434b8 commit 49a76e7
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/controllers/TestimonialsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,43 @@ export default class TestimonialsController {
res.status(500).send({ message: error.message });
}
}

// CODE BY TOMILLA OLUWAFEMI
public async getAllTestimonials(req: Request, res: Response) {
try {
const testimonials = await AppDataSource.getRepository(Testimonial).find();
res.status(200).json({
message: "Testimonials retrieved successfully",
status_code: 200,
data: testimonials,
});
} catch (error) {
res.status(500).send({ message: error.message });
}
}

public async deleteTestimonial(req: Request, res: Response) {
try {
const { testimonial_id } = req.params;

const testimonialToDelete = await AppDataSource.getRepository(Testimonial).findOne({
where: { id: testimonial_id },
});

if (!testimonialToDelete) {
return res
.status(404)
.send({ message: "Testimonial not found", status_code: 404 });
}

await AppDataSource.getRepository(Testimonial).remove(testimonialToDelete);

res.status(200).json({
message: "Testimonial deleted successfully",
status_code: 200,
});
} catch (error) {
res.status(500).send({ message: error.message });
}
}
}
12 changes: 12 additions & 0 deletions src/routes/testimonial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,16 @@ testimonialRoute.get(
testimonialController.getTestimonial.bind(testimonialController)
);

// CODE BY TOMILOLA OLUWAFEMI
testimonialRoute.get(
"/testimonials",
authMiddleware,
testimonialController.getAllTestimonials.bind(testimonialController)
);
testimonialRoute.delete(
"/testimonials/:testimonial_id",
authMiddleware,
testimonialController.deleteTestimonial.bind(testimonialController)
);

export { testimonialRoute };

0 comments on commit 49a76e7

Please sign in to comment.