Skip to content

Commit

Permalink
implement get messages endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
jmsundin committed Jan 30, 2024
1 parent 96af2d0 commit 5acc6e8
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/main/java/Controller/SocialMediaController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -107,6 +109,11 @@ private void messages(Context context) {
}
}

private void getAllMessages(Context context) {
List<Message> messages = messageService.getAllMessages();
context.json(messages).status(200);
}

private void getAccountTable(Context context) {
List<Account> accounts = accountService.getAllAccounts();
context.json(accounts).status(200);
Expand Down

0 comments on commit 5acc6e8

Please sign in to comment.