Skip to content

Commit

Permalink
Add a super simple controller for listing and storing new registrations
Browse files Browse the repository at this point in the history
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 fa22a87
Showing 1 changed file with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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.