|
| 1 | +/** |
| 2 | + * |
| 3 | + */ |
| 4 | +package com.sippulse.pet.controller; |
| 5 | + |
| 6 | +import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo; |
| 7 | +import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn; |
| 8 | + |
| 9 | +import org.springframework.beans.factory.annotation.Autowired; |
| 10 | +import org.springframework.http.ResponseEntity; |
| 11 | +import org.springframework.web.bind.annotation.PathVariable; |
| 12 | +import org.springframework.web.bind.annotation.RequestBody; |
| 13 | +import org.springframework.web.bind.annotation.RequestMapping; |
| 14 | +import org.springframework.web.bind.annotation.RequestMethod; |
| 15 | +import org.springframework.web.bind.annotation.RestController; |
| 16 | + |
| 17 | +import com.sippulse.pet.data.vo.v1.OwnerVO; |
| 18 | +import com.sippulse.pet.service.OwnerService; |
| 19 | + |
| 20 | +import io.swagger.annotations.Api; |
| 21 | +import io.swagger.annotations.ApiOperation; |
| 22 | + |
| 23 | +/** |
| 24 | + * @author Fábio Figueiredo da Silva |
| 25 | + * |
| 26 | + */ |
| 27 | +@Api(value = "Pet-Shedule_Endpoints", description = "REST API for Owner", tags = { "OwnerEndpoint" }) |
| 28 | +@RestController |
| 29 | +@RequestMapping("/api/owner/v1") |
| 30 | +public class OwnerController { |
| 31 | + |
| 32 | + @Autowired |
| 33 | + private OwnerService service; |
| 34 | + |
| 35 | +// @Autowired |
| 36 | +// private PagedResourcesAssembler<OwnerVO> assembler; |
| 37 | + |
| 38 | + |
| 39 | + @ApiOperation(value = "Create a new Owner") |
| 40 | + @RequestMapping(method = RequestMethod.POST, |
| 41 | + consumes = { "application/json", "application/xml", "application/x-yaml" }, |
| 42 | + produces = { "application/json", "application/xml", "application/x-yaml" }) |
| 43 | + public OwnerVO create(@RequestBody OwnerVO owner){ |
| 44 | + OwnerVO ownerVO = service.create(owner); |
| 45 | + ownerVO.add(linkTo(methodOn(OwnerController.class).get(ownerVO.getKey())).withSelfRel()); |
| 46 | + return ownerVO; |
| 47 | + } |
| 48 | + |
| 49 | + @ApiOperation(value = "Update a specific Owner") |
| 50 | + @RequestMapping(method = RequestMethod.PUT, |
| 51 | + consumes = { "application/json", "application/xml", "application/x-yaml" }) |
| 52 | + public OwnerVO update(@RequestBody OwnerVO owner){ |
| 53 | + OwnerVO ownerVO = service.update(owner); |
| 54 | + ownerVO.add(linkTo(methodOn(OwnerController.class).get(ownerVO.getKey())).withSelfRel()); |
| 55 | + return ownerVO; |
| 56 | + } |
| 57 | + |
| 58 | + @ApiOperation(value = "Find a specific Owner by your ID" ) |
| 59 | + @RequestMapping(value = "/{id}", |
| 60 | + method = RequestMethod.GET, |
| 61 | + produces = { "application/json", "application/xml", "application/x-yaml" }) |
| 62 | + public OwnerVO get(@PathVariable(value = "id") Long id){ |
| 63 | + OwnerVO ownerVO = service.findById(id); |
| 64 | + ownerVO.add(linkTo(methodOn(OwnerController.class).get(id)).withSelfRel()); |
| 65 | + return ownerVO; |
| 66 | + } |
| 67 | + |
| 68 | + @ApiOperation(value = "Find a specific Owner by your CPF" ) |
| 69 | + @RequestMapping(value = "/{cpf}", |
| 70 | + method = RequestMethod.GET, |
| 71 | + produces = { "application/json", "application/xml", "application/x-yaml" }) |
| 72 | + public OwnerVO getByCpf(@PathVariable(value = "cpf") String cpf){ |
| 73 | + OwnerVO ownerVO = service.findByCpf(cpf); |
| 74 | + ownerVO.add(linkTo(methodOn(OwnerController.class).getByCpf(cpf)).withSelfRel()); |
| 75 | + return ownerVO; |
| 76 | + } |
| 77 | + |
| 78 | + |
| 79 | + @ApiOperation(value = "Set a specific Owner by to disabled") |
| 80 | + @RequestMapping(value = "/{id}", |
| 81 | + method = RequestMethod.PATCH) |
| 82 | + public OwnerVO disable(@PathVariable(value = "id") Long id){ |
| 83 | + OwnerVO ownerVO = service.disableOwner(id); |
| 84 | + ownerVO.add(linkTo(methodOn(OwnerController.class).get(ownerVO.getKey())).withSelfRel()); |
| 85 | + return ownerVO; |
| 86 | + } |
| 87 | + |
| 88 | + @ApiOperation(value = "Delete a specific Owner by your ID") |
| 89 | + @RequestMapping(value = "/{id}", |
| 90 | + method = RequestMethod.DELETE) |
| 91 | + public ResponseEntity<?> delete(@PathVariable(value = "id") Long id){ |
| 92 | + service.delete(id); |
| 93 | + return ResponseEntity.ok().build(); |
| 94 | + } |
| 95 | + |
| 96 | +} |
0 commit comments