示例#1
0
 @RequestMapping(value = "/{id}", method = RequestMethod.PUT)
 @ResponseStatus(HttpStatus.OK)
 public void update(@PathVariable("id") final Long id, @RequestBody final Foo resource) {
   Preconditions.checkNotNull(resource);
   RestPreconditions.checkFound(service.findOne(resource.getId()));
   service.update(resource);
 }
示例#2
0
  @RequestMapping(value = "/{id}", method = RequestMethod.GET)
  @ResponseBody
  public Foo findById(@PathVariable("id") final Long id, final HttpServletResponse response) {
    final Foo resourceById = RestPreconditions.checkFound(service.findOne(id));

    eventPublisher.publishEvent(new SingleResourceRetrievedEvent(this, response));
    return resourceById;
  }
示例#3
0
  @RequestMapping(method = RequestMethod.POST)
  @ResponseStatus(HttpStatus.CREATED)
  @ResponseBody
  public Foo create(@RequestBody final Foo resource, final HttpServletResponse response) {
    Preconditions.checkNotNull(resource);
    Foo foo = service.create(resource);
    final Long idOfCreatedResource = foo.getId();

    eventPublisher.publishEvent(new ResourceCreatedEvent(this, response, idOfCreatedResource));

    return foo;
  }
示例#4
0
  @RequestMapping(
      params = {"page", "size"},
      method = RequestMethod.GET)
  @ResponseBody
  public List<Foo> findPaginated(
      @RequestParam("page") final int page,
      @RequestParam("size") final int size,
      final UriComponentsBuilder uriBuilder,
      final HttpServletResponse response) {
    final Page<Foo> resultPage = service.findPaginated(page, size);
    if (page > resultPage.getTotalPages()) {
      throw new MyResourceNotFoundException();
    }
    eventPublisher.publishEvent(
        new PaginatedResultsRetrievedEvent<Foo>(
            Foo.class, uriBuilder, response, page, resultPage.getTotalPages(), size));

    return resultPage.getContent();
  }
示例#5
0
 @RequestMapping(method = RequestMethod.GET)
 @ResponseBody
 public List<Foo> findAll() {
   return service.findAll();
 }
示例#6
0
 @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
 @ResponseStatus(HttpStatus.OK)
 public void delete(@PathVariable("id") final Long id) {
   service.deleteById(id);
 }