Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Services/Devices/Devices.API/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

app.UseCors();

app.UseHealthChecks("/health", new HealthCheckOptions
app.MapHealthChecks("/devices/health", new HealthCheckOptions
{
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ public void AddRoutes(IEndpointRouteBuilder app)
return Results.Ok(dtos);
});

app.MapGet("/devices/locations/monitored", async (ISender sender) =>
{
var response = await sender.Send(new GetMonitoredLocationsCommand());
var dtos = response.Locations;

return Results.Ok(dtos);
});

app.MapGet("/devices/timestamps/all", async (ISender sender) =>
{
var response = await sender.Send(new GetAllTimestampsCommand());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Devices.Application.Devices.GetDevice;

public record GetMonitoredLocationsCommand() : IRequest<GetMonitoredLocationsResponse>;
public record GetMonitoredLocationsResponse(IEnumerable<LocationDTO> Locations);

public class GetMonitoredLocationsCommandValidator : AbstractValidator<GetMonitoredLocationsCommand>
{
public GetMonitoredLocationsCommandValidator()
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace Devices.Application.Devices.GetDevice;

public class GetMonitoredLocationsHandler(DevicesDBContext context) : IRequestHandler<GetMonitoredLocationsCommand, GetMonitoredLocationsResponse>
{
public async Task<GetMonitoredLocationsResponse> Handle(GetMonitoredLocationsCommand request, CancellationToken cancellationToken)
{
var monitoredLocations = await context.Devices
.Include(d => d.Location)
.Include(d => d.Status)
.Where(d => d.Status.Type == "Online")
.Select(d => d.Location)
.Distinct()
.OrderBy(l => l.Name)
.ToListAsync(cancellationToken);

var dtos = monitoredLocations.Adapt<List<LocationDTO>>();

var response = new GetMonitoredLocationsResponse(dtos);

return response;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,27 @@ public async Task Consume(ConsumeContext<DeviceGenerateMeasurement> context)
.OrderByDescending(s => s.Time)
.FirstOrDefault();

if (previousSample is null)
{
// Get last one
previousSample = chart.Samples
.OrderByDescending(x => x.Time)
.FirstOrDefault();
}

var nextSample = chart.Samples
.Where(s => s.Time > targetTime)
.OrderBy(s => s.Time)
.FirstOrDefault();

// It is the 00:00
if (nextSample is null)
{
nextSample = chart.Samples
.OrderBy(x => x.Time)
.FirstOrDefault();
}

var seconds = targetTime.Minute * 60 + targetTime.Second;
var deltaValue = nextSample.Value - previousSample.Value;
var deltaValuePerSec = deltaValue / (60 * 60);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="9.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.11">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
4 changes: 3 additions & 1 deletion Services/Emulators/Emulators.WebApp/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
global using Emulators.Application;
global using Emulators.Infrastructure;
global using Emulators.Infrastructure;
global using HealthChecks.UI.Client;
global using Microsoft.AspNetCore.Diagnostics.HealthChecks;
21 changes: 21 additions & 0 deletions Services/Emulators/Emulators.WebApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,33 @@

builder.Services.AddInfrastructureServices(builder.Configuration, builder.Environment);
builder.Services.AddApplicationServices(builder.Configuration, builder.Environment);
builder.Services.AddHealthChecks();

builder.Services.AddCors(options =>
{
options.AddDefaultPolicy(policy =>
{
policy.WithOrigins("http://localhost:5173")
.AllowAnyHeader()
.AllowCredentials()
.AllowAnyMethod();
});
});

builder.Configuration.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
builder.Configuration.AddUserSecrets<Program>();

var app = builder.Build();

app.UseRouting();

app.UseCors();

app.MapGet("/", () => "Hello World!");

app.MapHealthChecks("/emulators/health", new HealthCheckOptions
{
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse,
});

app.Run();
14 changes: 14 additions & 0 deletions Services/Gateways/Gateways.Main/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
"Path": "/raports-service/{**catch-all}"
},
"Transforms": [ { "PathPattern": "{**catch-all}" } ]
},
"emulators-route": {
"ClusterId": "emulators-cluster",
"Match": {
"Path": "/emulators-service/{**catch-all}"
},
"Transforms": [ { "PathPattern": "{**catch-all}" } ]
}
},
"Clusters": {
Expand All @@ -51,6 +58,13 @@
"Address": "http://raports.api:8080/"
}
}
},
"emulators-cluster": {
"Destinations": {
"destination1": {
"Address": "http://emulators.webapp:8080/"
}
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Services/Measurements/Measurements.API/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

app.UseCors();

app.UseHealthChecks("/health", new HealthCheckOptions
app.MapHealthChecks("/measurements/health", new HealthCheckOptions
{
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,54 @@ public void Register(TypeAdapterConfig config)
.Map(x => x.Illuminance, y => y.Illuminance)
.Map(x => x.SoundLevel, y => y.SoundLevel);

TypeAdapterConfig<DefaultMeasurementDTO, MeasurementsMessage_CreateMeasurement>
.NewConfig()
.Map(x => x.ID, y => y.ID)
.Map(x => x.DeviceNumber, y => y.DeviceNumber)
.Map(x => x.MeasurementCaptureDate, y => y.MeasurementCaptureDate)
.Map(x => x.LocationHash, y => y.LocationHash)
.Map(x => x.Temperature, y => y.Temperature)
.Map(x => x.Humidity, y => y.Humidity)
.Map(x => x.CarbonDioxide, y => y.CarbonDioxide)
.Map(x => x.VolatileOrganicCompounds, y => y.VolatileOrganicCompounds)
.Map(x => x.ParticulateMatter1, y => y.ParticulateMatter1)
.Map(x => x.ParticulateMatter2v5, y => y.ParticulateMatter2v5)
.Map(x => x.ParticulateMatter10, y => y.ParticulateMatter10)
.Map(x => x.Formaldehyde, y => y.Formaldehyde)
.Map(x => x.CarbonMonoxide, y => y.CarbonMonoxide)
.Map(x => x.Ozone, y => y.Ozone)
.Map(x => x.Ammonia, y => y.Ammonia)
.Map(x => x.Airflow, y => y.Airflow)
.Map(x => x.AirIonizationLevel, y => y.AirIonizationLevel)
.Map(x => x.Oxygen, y => y.Oxygen)
.Map(x => x.Radon, y => y.Radon)
.Map(x => x.Illuminance, y => y.Illuminance)
.Map(x => x.SoundLevel, y => y.SoundLevel);

TypeAdapterConfig<MeasurementsMessage_CreateMeasurement, DefaultMeasurementDTO>
.NewConfig()
.Map(x => x.ID, y => y.ID)
.Map(x => x.DeviceNumber, y => y.DeviceNumber)
.Map(x => x.MeasurementCaptureDate, y => y.MeasurementCaptureDate)
.Map(x => x.LocationHash, y => y.LocationHash)
.Map(x => x.Temperature, y => y.Temperature)
.Map(x => x.Humidity, y => y.Humidity)
.Map(x => x.CarbonDioxide, y => y.CarbonDioxide)
.Map(x => x.VolatileOrganicCompounds, y => y.VolatileOrganicCompounds)
.Map(x => x.ParticulateMatter1, y => y.ParticulateMatter1)
.Map(x => x.ParticulateMatter2v5, y => y.ParticulateMatter2v5)
.Map(x => x.ParticulateMatter10, y => y.ParticulateMatter10)
.Map(x => x.Formaldehyde, y => y.Formaldehyde)
.Map(x => x.CarbonMonoxide, y => y.CarbonMonoxide)
.Map(x => x.Ozone, y => y.Ozone)
.Map(x => x.Ammonia, y => y.Ammonia)
.Map(x => x.Airflow, y => y.Airflow)
.Map(x => x.AirIonizationLevel, y => y.AirIonizationLevel)
.Map(x => x.Oxygen, y => y.Oxygen)
.Map(x => x.Radon, y => y.Radon)
.Map(x => x.Illuminance, y => y.Illuminance)
.Map(x => x.SoundLevel, y => y.SoundLevel);

// --------------- Mappings with dtos types ---------------
TypeAdapterConfig<DefaultMeasurementDTO, Measurement>
.NewConfig()
Expand Down
4 changes: 3 additions & 1 deletion Services/Raports/Raports.API/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@

app.UseApplicationServices();

app.UseRouting();

app.UseCors();

app.UseHealthChecks("/health", new HealthCheckOptions
app.MapHealthChecks("/raports/health", new HealthCheckOptions
{
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse,
});
Expand Down
Loading