package de.fau.amos.virtualledger.server.api;

import de.fau.amos.virtualledger.server.contacts.ContactsController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.lang.invoke.MethodHandles;

/**
 * Endpoints for contacts
 */
@RestController
public class ContactsApiEndpoint {
    @SuppressWarnings("unused")
    private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

    private final ContactsController contactsController;

    @Autowired
    public ContactsApiEndpoint(final ContactsController contactsController) {
        this.contactsController = contactsController;
    }

}

@@ -105,24 +105,108 @@
 Controller;%0A
+import org.keycloak.KeycloakPrincipal;%0Aimport org.keycloak.KeycloakSecurityContext;%0A
 import org.s
@@ -313,16 +313,305 @@
 owired;%0A
+import org.springframework.http.HttpStatus;%0Aimport org.springframework.http.ResponseEntity;%0Aimport org.springframework.security.core.context.SecurityContextHolder;%0Aimport org.springframework.web.bind.annotation.RequestMapping;%0Aimport org.springframework.web.bind.annotation.RequestMethod;%0A
 import o
@@ -1140,10 +1140,906 @@
 %0A    %7D%0A%0A
+    @RequestMapping(method = RequestMethod.GET, value = %22api/contacts%22, produces = %22application/json%22)%0A    public ResponseEntity%3C?%3E getContactsEndpoint() %7B%0A        final KeycloakPrincipal principal = (KeycloakPrincipal%3CKeycloakSecurityContext%3E) SecurityContextHolder.getContext().getAuthentication().getPrincipal();%0A        final String username = principal.getKeycloakSecurityContext().getToken().getEmail();%0A%0A        if (username == null %7C%7C username.isEmpty()) %7B%0A            return new ResponseEntity%3C%3E(%22Authentication failed! Your username wasn't found.%22, HttpStatus.FORBIDDEN);%0A        %7D%0A        LOGGER.info(%22getContactsEndpoint of %22 + username + %22 was requested%22);%0A%0A        return this.getContacts(username);%0A    %7D%0A%0A    private ResponseEntity%3C?%3E getContacts(final String username) %7B%0A        return new ResponseEntity%3C%3E(contactsController.getContactsByEmail(username), HttpStatus.OK);%0A    %7D%0A%0A
 %7D%0A

Add getContacts Endpoint