|
| 1 | +package bio.overture.ego.controller; |
| 2 | + |
| 3 | +import static bio.overture.ego.controller.resolver.PageableResolver.*; |
| 4 | +import static org.springframework.web.bind.annotation.RequestMethod.*; |
| 5 | + |
| 6 | +import bio.overture.ego.model.dto.*; |
| 7 | +import bio.overture.ego.model.entity.*; |
| 8 | +import bio.overture.ego.security.AdminScoped; |
| 9 | +import bio.overture.ego.service.*; |
| 10 | +import bio.overture.ego.view.Views; |
| 11 | +import com.fasterxml.jackson.annotation.JsonView; |
| 12 | +import io.swagger.annotations.*; |
| 13 | +import java.util.UUID; |
| 14 | +import lombok.NonNull; |
| 15 | +import lombok.extern.slf4j.Slf4j; |
| 16 | +import org.springframework.beans.factory.annotation.Autowired; |
| 17 | +import org.springframework.data.domain.Pageable; |
| 18 | +import org.springframework.http.HttpStatus; |
| 19 | +import org.springframework.web.bind.annotation.*; |
| 20 | +import springfox.documentation.annotations.ApiIgnore; |
| 21 | + |
| 22 | +@Slf4j |
| 23 | +@RestController |
| 24 | +@RequestMapping("/visa") |
| 25 | +@Api(tags = "Visa") |
| 26 | +public class VisaController { |
| 27 | + |
| 28 | + /** Dependencies */ |
| 29 | + private final VisaService visaService; |
| 30 | + |
| 31 | + private final UserPermissionService userPermissionService; |
| 32 | + private final GroupPermissionService groupPermissionService; |
| 33 | + private final ApplicationPermissionService applicationPermissionService; |
| 34 | + |
| 35 | + @Autowired |
| 36 | + public VisaController( |
| 37 | + @NonNull VisaService visaService, |
| 38 | + @NonNull UserPermissionService userPermissionService, |
| 39 | + @NonNull GroupPermissionService groupPermissionService, |
| 40 | + @NonNull ApplicationPermissionService applicationPermissionService) { |
| 41 | + this.visaService = visaService; |
| 42 | + this.groupPermissionService = groupPermissionService; |
| 43 | + this.userPermissionService = userPermissionService; |
| 44 | + this.applicationPermissionService = applicationPermissionService; |
| 45 | + } |
| 46 | + |
| 47 | + @AdminScoped |
| 48 | + @RequestMapping(method = GET, value = "/{id}") |
| 49 | + @ApiResponses( |
| 50 | + value = {@ApiResponse(code = 200, message = "Get Visa by id", response = Visa.class)}) |
| 51 | + @JsonView(Views.REST.class) |
| 52 | + public @ResponseBody Visa getVisa( |
| 53 | + @ApiIgnore @RequestHeader(value = "Authorization", required = true) |
| 54 | + final String authorization, |
| 55 | + @PathVariable(value = "id", required = true) UUID id) { |
| 56 | + return visaService.getById(id); |
| 57 | + } |
| 58 | + |
| 59 | + @AdminScoped |
| 60 | + @RequestMapping(method = GET, value = "") |
| 61 | + @ApiResponses(value = {@ApiResponse(code = 200, message = "All Visas")}) |
| 62 | + @JsonView(Views.REST.class) |
| 63 | + public @ResponseBody PageDTO<Visa> listVisa( |
| 64 | + @ApiIgnore @RequestHeader(value = "Authorization", required = true) |
| 65 | + final String authorization, |
| 66 | + @ApiIgnore Pageable pageable) { |
| 67 | + return new PageDTO<>(visaService.listVisa(pageable)); |
| 68 | + } |
| 69 | + |
| 70 | + @AdminScoped |
| 71 | + @RequestMapping(method = POST, value = "") |
| 72 | + @ApiResponses( |
| 73 | + value = { |
| 74 | + @ApiResponse(code = 200, message = "New Visa", response = Visa.class), |
| 75 | + }) |
| 76 | + public @ResponseBody Visa createVisa( |
| 77 | + @ApiIgnore @RequestHeader(value = "Authorization", required = true) |
| 78 | + final String authorization, |
| 79 | + @RequestBody(required = true) VisaRequest visaRequest) { |
| 80 | + return visaService.create(visaRequest); |
| 81 | + } |
| 82 | + |
| 83 | + @AdminScoped |
| 84 | + @RequestMapping(method = PUT, value = "/{id}") |
| 85 | + @ApiResponses(value = {@ApiResponse(code = 200, message = "Update Visa", response = Visa.class)}) |
| 86 | + public @ResponseBody Visa updateVisa( |
| 87 | + @ApiIgnore @RequestHeader(value = "Authorization", required = true) |
| 88 | + final String authorization, |
| 89 | + @PathVariable(value = "id", required = true) UUID id, |
| 90 | + @RequestBody(required = true) VisaRequest visaRequest) { |
| 91 | + return visaService.partialUpdate(id, visaRequest); |
| 92 | + } |
| 93 | + |
| 94 | + @AdminScoped |
| 95 | + @RequestMapping(method = DELETE, value = "/{id}") |
| 96 | + @ResponseStatus(value = HttpStatus.OK) |
| 97 | + public void deleteVisa( |
| 98 | + @ApiIgnore @RequestHeader(value = "Authorization", required = true) |
| 99 | + final String authorization, |
| 100 | + @PathVariable(value = "id", required = true) UUID id) { |
| 101 | + visaService.delete(id); |
| 102 | + } |
| 103 | +} |
0 commit comments