Re-clone Spring-rest-docs
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
package com.example;
|
||||
|
||||
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/crud")
|
||||
public class CRUDController {
|
||||
|
||||
@RequestMapping(method=RequestMethod.GET)
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public List<CrudInput> read(@RequestBody CrudInput crudInput) {
|
||||
List<CrudInput> returnList=new ArrayList<CrudInput>();
|
||||
returnList.add(crudInput);
|
||||
return returnList;
|
||||
}
|
||||
|
||||
@ResponseStatus(HttpStatus.CREATED)
|
||||
@RequestMapping(method=RequestMethod.POST)
|
||||
public HttpHeaders save(@RequestBody CrudInput crudInput) {
|
||||
HttpHeaders httpHeaders = new HttpHeaders();
|
||||
httpHeaders.setLocation(linkTo(CRUDController.class).slash(crudInput.getTitle()).toUri());
|
||||
return httpHeaders;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
HttpHeaders delete(@RequestBody CrudInput crudInput) {
|
||||
HttpHeaders httpHeaders = new HttpHeaders();
|
||||
return httpHeaders;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/{id}", method = RequestMethod.PUT)
|
||||
@ResponseStatus(HttpStatus.ACCEPTED)
|
||||
void put(@PathVariable("id") long id, @RequestBody CrudInput crudInput) {
|
||||
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/{id}", method = RequestMethod.PATCH)
|
||||
@ResponseStatus(HttpStatus.NO_CONTENT)
|
||||
void patch(@PathVariable("id") long id, @RequestBody CrudInput crudInput) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.example;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.validator.constraints.NotBlank;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
public class CrudInput {
|
||||
|
||||
//@NotBlank
|
||||
private final String title;
|
||||
|
||||
private final String body;
|
||||
|
||||
private final List<URI> tagUris;
|
||||
|
||||
@JsonCreator
|
||||
public CrudInput(@JsonProperty("title") String title,
|
||||
@JsonProperty("body") String body, @JsonProperty("tags") List<URI> tagUris) {
|
||||
this.title = title;
|
||||
this.body = body;
|
||||
this.tagUris = tagUris == null ? Collections.<URI>emptyList() : tagUris;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public String getBody() {
|
||||
return body;
|
||||
}
|
||||
|
||||
@JsonProperty("tags")
|
||||
public List<URI> getTagUris() {
|
||||
return this.tagUris;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,23 +1,22 @@
|
||||
package com.example;
|
||||
|
||||
|
||||
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
|
||||
|
||||
import org.springframework.hateoas.ResourceSupport;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api")
|
||||
@RequestMapping("/")
|
||||
public class IndexController {
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
public ResourceSupport index() {
|
||||
ResourceSupport index = new ResourceSupport();
|
||||
index.add(linkTo(MyRestController.class).withRel("notes"));
|
||||
index.add(linkTo(MyRestController.class).withRel("tags"));
|
||||
return index;
|
||||
}
|
||||
@RequestMapping(method=RequestMethod.GET)
|
||||
public ResourceSupport index() {
|
||||
ResourceSupport index = new ResourceSupport();
|
||||
index.add(linkTo(CRUDController.class).withRel("crud"));
|
||||
return index;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package com.example;
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/rest/api")
|
||||
public class MyRestController {
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
public String index() {
|
||||
return "Hello";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
@SpringBootApplication
|
||||
public class SpringRestDocsApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(SpringRestDocsApplication.class, args);
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(SpringRestDocsApplication.class, args);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user