-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
1 parent
d40a48a
commit fa22a87
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
src/main/java/ac/simons/netbeansevening/RegistrationController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |