Permalink
Browse files

Add a super simple controller for listing and storing new registrations

Be aware: This is a HTTP/JSON based API but not a REST api ;) Use Spring Data REST for easy creation of such apis.
  • Loading branch information...
michael-simons committed Aug 24, 2016
1 parent d40a48a commit fa22a8726dac1ec1e4138826a83c3b44a9aaa6cc
Showing with 37 additions and 0 deletions.
  1. +37 −0 src/main/java/ac/simons/netbeansevening/RegistrationController.java
@@ -0,0 +1,37 @@
package ac.simons.netbeansevening;
import javax.validation.Valid;
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.RestController;
import static org.springframework.web.bind.annotation.RequestMethod.GET;
import static org.springframework.web.bind.annotation.RequestMethod.POST;
@RestController
@RequestMapping("/registrations")
public class RegistrationController {
private final RegistrationRepository registrationRepository;
public RegistrationController(RegistrationRepository registrationRepository) {
this.registrationRepository = registrationRepository;
}
@RequestMapping(method = GET)
public Iterable<RegistrationEntity> list() {
return this.registrationRepository.findAll();
}
@RequestMapping(value = "/{id}", method = GET)
public RegistrationEntity get(@PathVariable Integer id) {
return this.registrationRepository.findOne(id);
}
@RequestMapping(method = POST)
public RegistrationEntity create(@Valid @RequestBody RegistrationEntity newRegistration) {
return this.registrationRepository.save(newRegistration);
}
}

0 comments on commit fa22a87

Please sign in to comment.