Skip to content

Instantly share code, notes, and snippets.

@vavasthi
Created June 21, 2020 06:52

Revisions

  1. vavasthi created this gist Jun 21, 2020.
    32 changes: 32 additions & 0 deletions ClientEndpoint.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    package in.springframework.blog.tutorials.endpoints;

    import in.springframework.blog.tutorials.entities.OauthClientDetails;
    import in.springframework.blog.tutorials.services.ClientService;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.http.MediaType;
    import org.springframework.web.bind.annotation.*;

    import java.util.Optional;

    @RestController
    @RequestMapping("/oauth/client")
    public class ClientEndpoint {

    @Autowired
    private ClientService clientService;

    @RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    public Iterable<OauthClientDetails> getClients() {
    return clientService.findAll();
    }
    @RequestMapping(value = "/{clientId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    public Optional<OauthClientDetails> getClient(@PathVariable("clientId") String clientId) {
    return clientService.findById(clientId);
    }
    @RequestMapping(value = "/{clientId}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
    public Optional<OauthClientDetails> getClient(@PathVariable("clientId") String clientId,
    @RequestBody OauthClientDetails clientDetails) {
    return clientService.update(clientId, clientDetails);
    }

    }