package com.authid.web.controller;

import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.oauth2.provider.ClientDetails;
import org.springframework.security.oauth2.provider.client.JdbcClientDetailsService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Chris Campo
 */
@RestController("/apiw")
public class ClientController {

    private final JdbcClientDetailsService clientDetailsService;

    @Autowired
    public ClientController(@NotNull final JdbcClientDetailsService clientDetailsService) {
        this.clientDetailsService = clientDetailsService;
    }

    @RequestMapping(path = "/clients", method = RequestMethod.GET)
    public List<ClientDetails> getClients() {
        return clientDetailsService.listClientDetails();
    }

    @RequestMapping(path = "/clients", method = RequestMethod.POST)
    public ClientDetails addClientDetails(@NotNull final ClientDetails clientDetails) {
        clientDetailsService.addClientDetails(clientDetails);
        return clientDetailsService.loadClientByClientId(clientDetails.getClientId());
    }
}

@@ -134,16 +134,153 @@
 owired;%0A
+import org.springframework.http.HttpHeaders;%0Aimport org.springframework.http.HttpStatus;%0Aimport org.springframework.http.ResponseEntity;%0A
 import o
@@ -397,20 +397,20 @@
 .client.
-Jdbc
+Base
 ClientDe
@@ -414,23 +414,16 @@
 tDetails
-Service
 ;%0Aimport
@@ -447,42 +447,64 @@
 ork.
-web.bind.annotation.RequestMapping
+security.oauth2.provider.client.JdbcClientDetailsService
 ;%0Aim
@@ -548,29 +548,17 @@
 otation.
-RequestMethod
+*
 ;%0Aimport
@@ -586,40 +586,74 @@
 web.
-bind.annotation.RestController;%0A
+servlet.support.ServletUriComponentsBuilder;%0A%0Aimport java.net.URI;
 %0Aimp
@@ -723,15 +723,37 @@
 ller
-(
+%0A@RequestMapping(path = 
 %22/api
-w
 %22)%0Ap
@@ -1191,32 +1191,272 @@
 tails();%0A    %7D%0A%0A
+    @RequestMapping(path = %22/clients/%7BclientId%7D%22, method = RequestMethod.GET)%0A    public ClientDetails getClientById(@NotNull @PathVariable final String clientId) %7B%0A        return clientDetailsService.loadClientByClientId(clientId);%0A    %7D%0A%0A
     @RequestMapp
@@ -1510,32 +1510,47 @@
 OST)%0A    public 
+ResponseEntity%3C
 ClientDetails ad
@@ -1546,16 +1546,17 @@
 tDetails
+%3E
  addClie
@@ -1574,22 +1574,39 @@
 NotNull 
+@RequestBody 
 final 
+Base
 ClientDe
@@ -1690,38 +1690,70 @@
 tails);%0A        
-return
+final ClientDetails newClientDetails =
  clientDetailsSe
@@ -1809,16 +1809,473 @@
 tId());%0A
+        // Set the location header to point towards our new resource URI%0A        final URI location = ServletUriComponentsBuilder.fromCurrentRequest()%0A                .path(%22/api/clients%22)%0A                .buildAndExpand(newClientDetails.getClientId())%0A                .toUri();%0A        final HttpHeaders headers = new HttpHeaders();%0A        headers.setLocation(location);%0A        return new ResponseEntity%3C%3E(newClientDetails, headers, HttpStatus.CREATED);%0A
     %7D%0A%7D%0A

Add get client by ID method