-
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.
Refactor PrecipitationController to WeatherDataController
Renamed PrecipitationController to WeatherDataController to accommodate broader weather data handling. Introduced ManualWeatherDataService and ManualWeatherDataEvent for managing various types of weather data. Modified BaseMappings and related DTOs to support the new weather data features.
- Loading branch information
1 parent
8e7effc
commit 87a20a7
Showing
7 changed files
with
260 additions
and
67 deletions.
There are no files selected for viewing
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
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
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
60 changes: 60 additions & 0 deletions
60
src/main/java/de/app/fivegla/controller/dto/request/WeatherDataRequest.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,60 @@ | ||
package de.app.fivegla.controller.dto.request; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import jakarta.validation.constraints.NotNull; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import java.util.Date; | ||
|
||
/** | ||
* Represents a request to add a weather data. | ||
*/ | ||
@Getter | ||
@Setter | ||
@Schema(description = "Represents a request to add a weather data.") | ||
public class WeatherDataRequest { | ||
|
||
@Schema(description = "The group id.") | ||
private String groupId; | ||
|
||
@NotNull | ||
@Schema(description = "The date the precipitation was created.") | ||
private Date dateCreated; | ||
|
||
@Schema(description = "The latitude.") | ||
private double latitude; | ||
|
||
@Schema(description = "The longitude.") | ||
private double longitude; | ||
|
||
@Schema(description = "The temperature.") | ||
private double temp; | ||
|
||
@Schema(description = "The humidity.") | ||
private double humidity; | ||
|
||
@Schema(description = "The precipitation.") | ||
private double precipitation; | ||
|
||
@Schema(description = "The air pressure.") | ||
private double airPressure; | ||
|
||
@Schema(description = "The UV index.") | ||
private double uvIndex; | ||
|
||
@Schema(description = "The solar radiation.") | ||
private double solarRadiation; | ||
|
||
@Schema(description = "The visibility.") | ||
private double visibility; | ||
|
||
@Schema(description = "The dew point.") | ||
private double dewPoint; | ||
|
||
@Schema(description = "The feels like.") | ||
private double feelsLike; | ||
|
||
@Schema(description = "The heat index.") | ||
private double heatIndex; | ||
} |
63 changes: 0 additions & 63 deletions
63
src/main/java/de/app/fivegla/controller/tenant/PrecipitationController.java
This file was deleted.
Oops, something went wrong.
92 changes: 92 additions & 0 deletions
92
src/main/java/de/app/fivegla/controller/tenant/WeatherDataController.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,92 @@ | ||
package de.app.fivegla.controller.tenant; | ||
|
||
import de.app.fivegla.api.Response; | ||
import de.app.fivegla.business.ManualWeatherDataService; | ||
import de.app.fivegla.business.TenantService; | ||
import de.app.fivegla.config.security.marker.TenantCredentialApiAccess; | ||
import de.app.fivegla.controller.api.BaseMappings; | ||
import de.app.fivegla.controller.dto.request.PrecipitationRequest; | ||
import de.app.fivegla.controller.dto.request.WeatherDataRequest; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.media.Content; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.security.Principal; | ||
|
||
@Slf4j | ||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping(BaseMappings.WEATHER_DATA) | ||
public class WeatherDataController implements TenantCredentialApiAccess { | ||
|
||
private final TenantService tenantService; | ||
private final ManualWeatherDataService manualWeatherDataService; | ||
|
||
@Operation( | ||
operationId = "weather-data.add-manual", | ||
description = "Add a manual precipitation measurement.", | ||
tags = BaseMappings.WEATHER_DATA | ||
) | ||
@ApiResponse( | ||
responseCode = "200", | ||
description = "The precipitation measurement was added.", | ||
content = @Content( | ||
mediaType = MediaType.APPLICATION_JSON_VALUE, | ||
schema = @Schema(implementation = Response.class) | ||
) | ||
) | ||
@ApiResponse( | ||
responseCode = "400", | ||
description = "The request is invalid.", | ||
content = @Content( | ||
mediaType = MediaType.APPLICATION_JSON_VALUE, | ||
schema = @Schema(implementation = Response.class) | ||
) | ||
) | ||
@PostMapping(value = "/precipitation/manual", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) | ||
public ResponseEntity<? extends Response> addManualPrecipitation(@Parameter(description = "The request to add a precipitation measurement.") @Valid @RequestBody PrecipitationRequest request, Principal principal) { | ||
var tenant = validateTenant(tenantService, principal); | ||
manualWeatherDataService.addPrecipitationEvent(tenant, request); | ||
return ResponseEntity.ok(new Response()); | ||
} | ||
|
||
@Operation( | ||
operationId = "weather-data.add-manual", | ||
description = "Add a manual weather data measurement.", | ||
tags = BaseMappings.WEATHER_DATA | ||
) | ||
@ApiResponse( | ||
responseCode = "200", | ||
description = "The weather data measurement was added.", | ||
content = @Content( | ||
mediaType = MediaType.APPLICATION_JSON_VALUE, | ||
schema = @Schema(implementation = Response.class) | ||
) | ||
) | ||
@ApiResponse( | ||
responseCode = "400", | ||
description = "The request is invalid.", | ||
content = @Content( | ||
mediaType = MediaType.APPLICATION_JSON_VALUE, | ||
schema = @Schema(implementation = Response.class) | ||
) | ||
) | ||
@PostMapping(value = "/weather-data/manual", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) | ||
public ResponseEntity<? extends Response> addManualWeatherData(@Parameter(description = "The request to add a weather data measurement.") @Valid @RequestBody WeatherDataRequest request, Principal principal) { | ||
var tenant = validateTenant(tenantService, principal); | ||
manualWeatherDataService.addManualWeatherData(tenant, request); | ||
return ResponseEntity.ok(new Response()); | ||
} | ||
|
||
} |
73 changes: 73 additions & 0 deletions
73
src/main/java/de/app/fivegla/integration/fiware/model/ManualWeatherDataEvent.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,73 @@ | ||
package de.app.fivegla.integration.fiware.model; | ||
|
||
import de.app.fivegla.integration.fiware.model.api.FiwareEntity; | ||
import de.app.fivegla.integration.fiware.model.api.Validatable; | ||
import de.app.fivegla.integration.fiware.model.internal.Attribute; | ||
import de.app.fivegla.integration.fiware.model.internal.NumberAttribute; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
@Slf4j | ||
public record ManualWeatherDataEvent( | ||
String id, | ||
String type, | ||
Attribute group, | ||
Attribute dateCreated, | ||
double latitude, | ||
double longitude, | ||
NumberAttribute temp, | ||
NumberAttribute humidity, | ||
NumberAttribute precipitation, | ||
NumberAttribute airPressure, | ||
NumberAttribute uvIndex, | ||
NumberAttribute solarRadiation, | ||
NumberAttribute visibility, | ||
NumberAttribute dewPoint, | ||
NumberAttribute feelsLike, | ||
NumberAttribute heatIndex | ||
) implements FiwareEntity, Validatable { | ||
|
||
@Override | ||
public String asJson() { | ||
validate(); | ||
var json = "{" + | ||
" \"id\":\"" + id.trim() + "\"," + | ||
" \"type\":\"" + type.trim() + "\"," + | ||
" \"customGroup\":" + group.asJson().trim() + "," + | ||
" \"dateCreated\":" + dateCreated.asJson().trim() + "," + | ||
" \"location\":" + locationAsJson(latitude, longitude).trim() + | ||
" \"temperature\":" + temp.asJson().trim() + "," + | ||
" \"humidity\":" + humidity.asJson().trim() + "," + | ||
" \"precipitation\":" + precipitation.asJson().trim() + | ||
" \"airPressure\":" + airPressure.asJson().trim() + | ||
" \"uvIndex\":" + uvIndex.asJson().trim() + | ||
" \"solarRadiation\":" + solarRadiation.asJson().trim() + | ||
" \"visibility\":" + visibility.asJson().trim() + | ||
" \"dewPoint\":" + dewPoint.asJson().trim() + | ||
" \"feelsLike\":" + feelsLike.asJson().trim() + | ||
" \"heatIndex\":" + heatIndex.asJson().trim() + | ||
"}"; | ||
log.debug("{} as JSON: {}", this.getClass().getSimpleName(), json); | ||
return json; | ||
} | ||
|
||
@Override | ||
public void validate() { | ||
if (StringUtils.isBlank(id)) { | ||
throw new IllegalArgumentException("The id of the entity must not be null or blank."); | ||
} | ||
if (StringUtils.isBlank(type)) { | ||
throw new IllegalArgumentException("The type of the entity must not be null or blank."); | ||
} | ||
} | ||
|
||
@Override | ||
public String getId() { | ||
return id; | ||
} | ||
|
||
@Override | ||
public String getType() { | ||
return type; | ||
} | ||
} |