package com.authid.web.controller;

import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.oauth2.provider.ClientDetails;
import org.springframework.security.oauth2.provider.client.BaseClientDetails;
import org.springframework.security.oauth2.provider.client.JdbcClientDetailsService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;

import java.net.URI;
import java.util.List;

/**
 * @author Chris Campo
 */
@RestController
@RequestMapping(path = "/api")
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/{clientId}", method = RequestMethod.GET)
    public ClientDetails getClientById(@NotNull @PathVariable final String clientId) {
        return clientDetailsService.loadClientByClientId(clientId);
    }

    @RequestMapping(path = "/clients", method = RequestMethod.POST)
    public ResponseEntity<ClientDetails> addClientDetails(@NotNull @RequestBody final BaseClientDetails clientDetails) {
        clientDetailsService.addClientDetails(clientDetails);
        final ClientDetails newClientDetails = clientDetailsService.loadClientByClientId(clientDetails.getClientId());
        // Set the location header to point towards our new resource URI
        final URI location = ServletUriComponentsBuilder.fromCurrentRequest()
                .path("/api/clients")
                .buildAndExpand(newClientDetails.getClientId())
                .toUri();
        final HttpHeaders headers = new HttpHeaders();
        headers.setLocation(location);
        return new ResponseEntity<>(newClientDetails, headers, HttpStatus.CREATED);
    }
}

@@ -2271,11 +2271,1025 @@
 );%0A    %7D
+%0A%0A    @RequestMapping(path = %22/clients/%7BclientId%7D%22, method = RequestMethod.PUT)%0A    public ResponseEntity%3CVoid%3E updateClientDetails(@NotNull @RequestBody final BaseClientDetails clientDetails) %7B%0A        clientDetailsService.updateClientDetails(clientDetails);%0A        return new ResponseEntity%3C%3E(HttpStatus.NO_CONTENT);%0A    %7D%0A%0A    @RequestMapping(path = %22/clients/%7BclientId%7D/client_secret%22, method = RequestMethod.PUT)%0A    public ResponseEntity%3CVoid%3E updateClientDetails(@NotNull @PathVariable final String clientId,%0A            @NotNull @RequestBody final String secret) %7B%0A        clientDetailsService.updateClientSecret(clientId, secret);%0A        return new ResponseEntity%3C%3E(HttpStatus.NO_CONTENT);%0A    %7D%0A%0A    @RequestMapping(path = %22/clients/%7BclientId%7D%22, method = RequestMethod.DELETE)%0A    public ResponseEntity%3CVoid%3E removeClientDetails(@NotNull @PathVariable final String clientId) %7B%0A        clientDetailsService.removeClientDetails(clientId);%0A        return new ResponseEntity%3C%3E(HttpStatus.NO_CONTENT);%0A    %7D
 %0A%7D%0A

Add update and delete methods for clients.