From 9348b4f366c144f123976b6275bdf9b952cbf922 Mon Sep 17 00:00:00 2001 From: Jon Sundin Date: Tue, 30 Jan 2024 01:50:42 +0000 Subject: [PATCH] delete message by id endpoint --- src/main/java/Controller/SocialMediaController.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/Controller/SocialMediaController.java b/src/main/java/Controller/SocialMediaController.java index 865bdff..9a594c2 100644 --- a/src/main/java/Controller/SocialMediaController.java +++ b/src/main/java/Controller/SocialMediaController.java @@ -47,6 +47,7 @@ public Javalin startAPI() { app.get("/messages", this::getAllMessages); app.get("/messages/{message_id}", this::getMessageById); app.post("/messages", this::messages); + app.delete("/messages/{message_id}", this::deleteMessageById); return app; } @@ -125,6 +126,17 @@ private void getMessageById(Context context) { } } + private void deleteMessageById(Context context) { + int message_id = Integer.parseInt(context.pathParam("message_id")); + Message message = messageService.deleteMessageById(message_id); + if (message == null) { + context.status(200); + } + else { + context.json(message); + } + } + private void getAccountTable(Context context) { List accounts = accountService.getAllAccounts(); context.json(accounts);