|
@Validated |
|
@RestController |
|
@RequestMapping("/api/v1/author") |
|
public class AuthorController |
|
{ |
|
|
|
@Autowired |
|
private AuthorService authorMainService; |
|
|
|
@GetMapping(value = "/{id}") |
|
public ResponseWrapper<Author> getAuthorById( |
|
@Valid @Pattern(regexp = REGEX_FOR_NUMBERS, message = MESSAGE_FOR_REGEX_NUMBER_MISMATCH) @PathVariable(value = "id") String id ) |
|
{ |
|
return new ResponseWrapper<>( authorMainService.getById( Integer.parseInt( id ) ), HttpStatus.OK ); |
|
} |
|
|
|
@GetMapping() |
|
public ResponseWrapper<Page<Author>> getAuthorAll( Pageable pageable ) |
|
{ |
|
return new ResponseWrapper<>( authorMainService.getAll( pageable ), HttpStatus.OK ); |
|
} |
|
|
|
@PostMapping |
|
public ResponseWrapper<Author> createAuthor( @Valid @RequestBody Author author ) |
|
{ |
|
return new ResponseWrapper<>( authorMainService.add( author ), HttpStatus.OK ); |
|
} |
|
|
|
@DeleteMapping(value = "/{id}") |
|
public ResponseWrapper<Author> deleteAuthor( |
|
@Valid @Pattern(regexp = REGEX_FOR_NUMBERS, message = MESSAGE_FOR_REGEX_NUMBER_MISMATCH) @PathVariable(value = "id") String id ) |
|
{ |
|
return new ResponseWrapper<>( authorMainService.deleteById( Integer.parseInt( id ) ), HttpStatus.OK ); |
|
} |
|
|
|
@PatchMapping(value = "/{id}") |
|
public ResponseWrapper<Author> UpdateAuthor( @Valid @RequestBody Author author, |
|
@Valid @Pattern(regexp = REGEX_FOR_NUMBERS, message = MESSAGE_FOR_REGEX_NUMBER_MISMATCH) @PathVariable(value = "id") String id ) |
|
{ |
|
return new ResponseWrapper<>( authorMainService.update( author, Integer.parseInt( id ) ), HttpStatus.OK ); |
|
} |
|
|
|
@GetMapping(value = "/{id}/books") |
|
public ResponseWrapper<List<Book>> getAuthorBooksById( |
|
@Valid @Pattern(regexp = REGEX_FOR_NUMBERS, message = MESSAGE_FOR_REGEX_NUMBER_MISMATCH) @PathVariable(value = "id") String id ) |
|
{ |
|
return new ResponseWrapper<>( authorMainService.getBooksById( Integer.parseInt( id ) ), HttpStatus.OK ); |
|
} |
|
|
|
} |