Skip to content

Commit

Permalink
Merge pull request #312 from pagopa/PPANTT-39-add-list-maintenance-api
Browse files Browse the repository at this point in the history
[PPANTT-39] feat: Add list maintenance API
  • Loading branch information
alessio-cialini authored Jul 29, 2024
2 parents 9fb3301 + 0044383 commit cfb91e8
Show file tree
Hide file tree
Showing 12 changed files with 13,876 additions and 14,878 deletions.
28,403 changes: 13,582 additions & 14,821 deletions openapi/openapi.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions openapi/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -14767,7 +14767,7 @@
"type": "string"
},
"config_description": {
"example": " default millisecondi validità token",
"example": " default millisecondi validità token",
"type": "string"
},
"config_key": {
Expand All @@ -14789,7 +14789,7 @@
"ConfigurationKeyBase": {
"properties": {
"config_description": {
"example": " default millisecondi validità token",
"example": " default millisecondi validità token",
"type": "string"
},
"config_value": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package it.gov.pagopa.apiconfig.core.config;

import it.gov.pagopa.apiconfig.core.mapper.*;
import it.gov.pagopa.apiconfig.core.model.stationmaintenance.StationMaintenanceResource;
import it.gov.pagopa.apiconfig.starter.entity.*;
import org.modelmapper.Converter;
import org.modelmapper.ModelMapper;
Expand Down Expand Up @@ -268,7 +269,10 @@ ModelMapper modelMapper() {

mapper.createTypeMap(Cache.class, it.gov.pagopa.apiconfig.core.model.configuration.Cache.class)
.setConverter(convertCacheToCacheModel);


mapper.createTypeMap(StationMaintenance.class, StationMaintenanceResource.class)
.setConverter(new ConvertStationMaintenanceToStationMaintenanceResource());

return mapper;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,32 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import it.gov.pagopa.apiconfig.core.model.ProblemJson;
import it.gov.pagopa.apiconfig.core.model.stationmaintenance.CreateStationMaintenance;
import it.gov.pagopa.apiconfig.core.model.stationmaintenance.StationMaintenanceListResource;
import it.gov.pagopa.apiconfig.core.model.stationmaintenance.StationMaintenanceResource;
import it.gov.pagopa.apiconfig.core.model.stationmaintenance.UpdateStationMaintenance;
import it.gov.pagopa.apiconfig.core.service.StationMaintenanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Positive;
import javax.validation.constraints.PositiveOrZero;
import java.time.OffsetDateTime;

@RestController
@RequestMapping(path = "/brokers")
Expand All @@ -41,22 +50,61 @@ public StationMaintenanceController(StationMaintenanceService stationMaintenance
this.stationMaintenanceService = stationMaintenanceService;
}

@Operation(summary = "Get a paginated list of station's maintenance for the specified broker",
security = {@SecurityRequirement(name = "ApiKey"), @SecurityRequirement(name = "Authorization")})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Created",
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = StationMaintenanceListResource.class))),
@ApiResponse(responseCode = "400", description = "Bad Request",
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = ProblemJson.class))),
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(schema = @Schema())),
@ApiResponse(responseCode = "403", description = "Forbidden", content = @Content(schema = @Schema())),
@ApiResponse(responseCode = "429", description = "Too many requests", content = @Content(schema = @Schema())),
@ApiResponse(responseCode = "500", description = "Service unavailable",
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = ProblemJson.class)))
})
@GetMapping(value = "/{brokercode}/station-maintenances", produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<StationMaintenanceListResource> getStationMaintenances(
@Parameter(description = "Broker's tax code") @PathVariable("brokercode") String brokerCode,
@Parameter(description = "Station's code") @RequestParam(required = false) String stationCode,
@Parameter(description = "Start date of maintenance, used to retrieve all maintenance that start before the provided date (yyyy-MM-dd'T'HH:mm:ss.SSS'Z')", example = "2024-04-01T10:00:00.000Z")
@RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) OffsetDateTime startDateTimeBefore,
@Parameter(description = "Start date of maintenance, used to retrieve all maintenance that start after the provided date (yyyy-MM-dd'T'HH:mm:ss.SSS'Z')", example = "2024-04-01T10:00:00.000Z")
@RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) OffsetDateTime startDateTimeAfter,
@Parameter(description = "End date of maintenance, used to retrieve all maintenance that start before the provided date (yyyy-MM-dd'T'HH:mm:ss.SSS'Z')", example = "2024-04-01T13:00:00.000Z")
@RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) OffsetDateTime endDateTimeBefore,
@Parameter(description = "End date of maintenance, used to retrieve all maintenance that start after the provided date (yyyy-MM-dd'T'HH:mm:ss.SSS'Z')", example = "2024-04-01T13:00:00.000Z")
@RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) OffsetDateTime endDateTimeAfter,
@Parameter(description = "Number of items for page") @RequestParam(required = false, defaultValue = "50") @Positive Integer limit,
@Parameter(description = "Page number") @RequestParam(required = false, defaultValue = "0") @Min(0) @PositiveOrZero Integer page
) {
return ResponseEntity.ok(
this.stationMaintenanceService.getStationMaintenances(
brokerCode,
stationCode,
startDateTimeBefore,
startDateTimeAfter,
endDateTimeBefore,
endDateTimeAfter,
PageRequest.of(page, limit)
));
}

@Operation(summary = "Create a maintenance for the specified station",
security = {@SecurityRequirement(name = "ApiKey"), @SecurityRequirement(name = "Authorization")})
@ApiResponses(
value = {
@ApiResponse(responseCode = "201", description = "Created",
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = StationMaintenanceResource.class))),
@ApiResponse(responseCode = "400", description = "Bad Request",
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = ProblemJson.class))),
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(schema = @Schema())),
@ApiResponse(responseCode = "403", description = "Forbidden", content = @Content(schema = @Schema())),
@ApiResponse(responseCode = "409", description = "Conflict",
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = ProblemJson.class))),
@ApiResponse(responseCode = "429", description = "Too many requests", content = @Content(schema = @Schema())),
@ApiResponse(responseCode = "500", description = "Service unavailable",
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = ProblemJson.class)))
})
@ApiResponses(value = {
@ApiResponse(responseCode = "201", description = "Created",
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = StationMaintenanceResource.class))),
@ApiResponse(responseCode = "400", description = "Bad Request",
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = ProblemJson.class))),
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(schema = @Schema())),
@ApiResponse(responseCode = "403", description = "Forbidden", content = @Content(schema = @Schema())),
@ApiResponse(responseCode = "409", description = "Conflict",
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = ProblemJson.class))),
@ApiResponse(responseCode = "429", description = "Too many requests", content = @Content(schema = @Schema())),
@ApiResponse(responseCode = "500", description = "Service unavailable",
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = ProblemJson.class)))
})
@PostMapping(value = "/{brokercode}/station-maintenances", produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<StationMaintenanceResource> createStationMaintenance(
@Parameter(description = "Broker's tax code") @PathVariable("brokercode") String brokerCode,
Expand All @@ -69,20 +117,19 @@ public ResponseEntity<StationMaintenanceResource> createStationMaintenance(

@Operation(summary = "Update a maintenance for the specified station",
security = {@SecurityRequirement(name = "ApiKey"), @SecurityRequirement(name = "Authorization")})
@ApiResponses(
value = {
@ApiResponse(responseCode = "200", description = "Created",
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = StationMaintenanceResource.class))),
@ApiResponse(responseCode = "400", description = "Bad Request",
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = ProblemJson.class))),
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(schema = @Schema())),
@ApiResponse(responseCode = "403", description = "Forbidden", content = @Content(schema = @Schema())),
@ApiResponse(responseCode = "409", description = "Conflict",
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = ProblemJson.class))),
@ApiResponse(responseCode = "429", description = "Too many requests", content = @Content(schema = @Schema())),
@ApiResponse(responseCode = "500", description = "Service unavailable",
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = ProblemJson.class)))
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Created",
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = StationMaintenanceResource.class))),
@ApiResponse(responseCode = "400", description = "Bad Request",
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = ProblemJson.class))),
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(schema = @Schema())),
@ApiResponse(responseCode = "403", description = "Forbidden", content = @Content(schema = @Schema())),
@ApiResponse(responseCode = "409", description = "Conflict",
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = ProblemJson.class))),
@ApiResponse(responseCode = "429", description = "Too many requests", content = @Content(schema = @Schema())),
@ApiResponse(responseCode = "500", description = "Service unavailable",
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = ProblemJson.class)))
})
@PutMapping(value = "/{brokercode}/station-maintenances/{maintenanceid}", produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<StationMaintenanceResource> updateStationMaintenance(
@Parameter(description = "Broker's tax code") @PathVariable("brokercode") String brokerCode,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package it.gov.pagopa.apiconfig.core.mapper;

import it.gov.pagopa.apiconfig.core.model.stationmaintenance.StationMaintenanceResource;
import it.gov.pagopa.apiconfig.starter.entity.StationMaintenance;
import org.modelmapper.Converter;
import org.modelmapper.spi.MappingContext;

/**
* Converter class that specify how to convert a {@link StationMaintenance} instance to a {@link StationMaintenanceResource} instance
*/
public class ConvertStationMaintenanceToStationMaintenanceResource implements Converter<StationMaintenance, StationMaintenanceResource> {

@Override
public StationMaintenanceResource convert(MappingContext<StationMaintenance, StationMaintenanceResource> context) {
StationMaintenance model = context.getSource();

return StationMaintenanceResource.builder()
.maintenanceId(model.getObjId())
.brokerCode(model.getStation().getIntermediarioPa().getIdIntermediarioPa())
.stationCode(model.getStation().getIdStazione())
.startDateTime(model.getStartDateTime())
.endDateTime(model.getEndDateTime())
.standIn(model.getStandIn())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class CreateStationMaintenance {
@JsonSerialize(using = OffsetDateTimeSerializer.class)
@JsonDeserialize(using = OffsetDateTimeDeserializer.class)
@Schema(
example = "2024-04-01T13:00:00.000Z",
example = "2024-04-01T10:00:00.000Z",
required = true,
description = "The start date time of the station maintenance")
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package it.gov.pagopa.apiconfig.core.model.stationmaintenance;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import it.gov.pagopa.apiconfig.core.model.PageInfo;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
* Model class the response for station's maintenance APIs
*/
@Getter
@Setter
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class StationMaintenanceListResource {

@JsonProperty("station_maintenance_list")
@Schema(description = "List of station's maintenance", required = true)
@NotNull
@Valid
private List<StationMaintenanceResource> maintenanceList;

@JsonProperty("page_info")
@Schema(required = true)
@NotNull
@Valid
private PageInfo pageInfo;
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class StationMaintenanceResource {
@JsonFormat(pattern = Constants.DateTimeFormat.DATE_TIME_FORMAT)
@JsonSerialize(using = OffsetDateTimeSerializer.class)
@Schema(
example = "2024-04-01T13:00:00.000Z",
example = "2024-04-01T10:00:00.000Z",
required = true,
description = "The start date time of the station maintenance")
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class UpdateStationMaintenance {
@JsonSerialize(using = OffsetDateTimeSerializer.class)
@JsonDeserialize(using = OffsetDateTimeDeserializer.class)
@Schema(
example = "2024-04-01T13:00:00.000Z",
example = "2024-04-01T10:00:00.000Z",
description = "The start date time of the station maintenance")
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
private OffsetDateTime startDateTime;
Expand All @@ -53,4 +53,4 @@ public class UpdateStationMaintenance {
@JsonProperty("stand_in")
@Schema(description = "StandIn flag")
private Boolean standIn;
}
}
Loading

0 comments on commit cfb91e8

Please sign in to comment.