From 5acc6e8c824dbaeed5de19332189b5d290ac49de Mon Sep 17 00:00:00 2001 From: Jon Sundin Date: Tue, 30 Jan 2024 01:03:19 +0000 Subject: [PATCH] implement get messages endpoint --- src/main/java/Controller/SocialMediaController.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/Controller/SocialMediaController.java b/src/main/java/Controller/SocialMediaController.java index 4e208d9..6ee30ed 100644 --- a/src/main/java/Controller/SocialMediaController.java +++ b/src/main/java/Controller/SocialMediaController.java @@ -43,6 +43,8 @@ public Javalin startAPI() { app.get("/getAccountTable", this::getAccountTable); app.post("/register", this::register); app.post("/login", this::login); + + app.get("/messages", this::getAllMessages); app.post("/messages", this::messages); return app; @@ -61,7 +63,7 @@ private void exampleHandler(Context context) { private void register(Context context) throws JsonProcessingException { Account accountFromBody = context.bodyAsClass(Account.class); - if (!accountService.isValidCredentials(accountFromBody.username, accountFromBody.password_)) { + if (!accountService.isValidCredentials(accountFromBody.username, accountFromBody.password)) { context.result("").status(400); } else { Account registeredAccount = accountService.addAccount(accountFromBody); @@ -79,7 +81,7 @@ private void login(Context context) { if (!accountService.accountIsRegistered(account.username)) { context.status(401); } else { - Account accountLoggedIn = accountService.login(account.username, account.password_); + Account accountLoggedIn = accountService.login(account.username, account.password); if (accountLoggedIn == null) { context.status(401); @@ -107,6 +109,11 @@ private void messages(Context context) { } } + private void getAllMessages(Context context) { + List messages = messageService.getAllMessages(); + context.json(messages).status(200); + } + private void getAccountTable(Context context) { List accounts = accountService.getAllAccounts(); context.json(accounts).status(200);