From 5693b5d2d92432d2be697e2943185afef50b9687 Mon Sep 17 00:00:00 2001 From: Jon Sundin Date: Wed, 31 Jan 2024 02:42:34 +0000 Subject: [PATCH] get all messages by account id endpoint --- src/main/java/Controller/SocialMediaController.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/Controller/SocialMediaController.java b/src/main/java/Controller/SocialMediaController.java index 9aa9b84..2c8586e 100644 --- a/src/main/java/Controller/SocialMediaController.java +++ b/src/main/java/Controller/SocialMediaController.java @@ -50,6 +50,8 @@ public Javalin startAPI() { app.patch("/messages/{message_id}", this::updateMessageById); app.delete("/messages/{message_id}", this::deleteMessageById); + app.get("/accounts/{account_id}/messages", this::getAllMessagesByAccountId); + return app; } @@ -153,6 +155,12 @@ private void updateMessageById(Context context) { } } + private void getAllMessagesByAccountId(Context context) { + int account_id = Integer.parseInt(context.pathParam("account_id")); + List messages = messageService.getAllMessagesByAccountId(account_id); + context.json(messages); + } + private void getAccountTable(Context context) { List accounts = accountService.getAllAccounts(); context.json(accounts);