Fix data format of AirGradient API JSON
This commit is contained in:
parent
ff3d4341c2
commit
f96dafe8c9
|
@ -11,8 +11,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|||
namespace AirGradientWebApi.Migrations
|
||||
{
|
||||
[DbContext(typeof(AirGradientWebApiContext))]
|
||||
[Migration("20221111050337_InitialCreate")]
|
||||
partial class InitialCreate
|
||||
[Migration("20221111235923_InitialCreation")]
|
||||
partial class InitialCreation
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
|
@ -44,25 +44,23 @@ namespace AirGradientWebApi.Migrations
|
|||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Co2")
|
||||
.HasColumnType("TEXT");
|
||||
b.Property<int?>("Co2")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime>("Created")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Humidity")
|
||||
b.Property<int?>("Humidity")
|
||||
.HasColumnType("decimal(18, 2)");
|
||||
|
||||
b.Property<int?>("Pm02")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<decimal>("Temperature")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Pm02")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Temperature")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Wifi")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
b.Property<int>("Wifi")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
|
@ -5,7 +5,7 @@ using Microsoft.EntityFrameworkCore.Migrations;
|
|||
|
||||
namespace AirGradientWebApi.Migrations
|
||||
{
|
||||
public partial class InitialCreate : Migration
|
||||
public partial class InitialCreation : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
|
@ -29,11 +29,11 @@ namespace AirGradientWebApi.Migrations
|
|||
{
|
||||
Id = table.Column<int>(type: "INTEGER", nullable: false)
|
||||
.Annotation("Sqlite:Autoincrement", true),
|
||||
Wifi = table.Column<string>(type: "TEXT", nullable: false),
|
||||
Co2 = table.Column<string>(type: "TEXT", nullable: true),
|
||||
Pm02 = table.Column<string>(type: "TEXT", nullable: true),
|
||||
Temperature = table.Column<string>(type: "TEXT", nullable: false),
|
||||
Humidity = table.Column<string>(type: "TEXT", nullable: true),
|
||||
Wifi = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
Co2 = table.Column<int>(type: "INTEGER", nullable: true),
|
||||
Pm02 = table.Column<int>(type: "INTEGER", nullable: true),
|
||||
Temperature = table.Column<decimal>(type: "TEXT", nullable: false),
|
||||
Humidity = table.Column<int>(type: "decimal(18, 2)", nullable: true),
|
||||
Created = table.Column<DateTime>(type: "TEXT", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
|
@ -42,25 +42,23 @@ namespace AirGradientWebApi.Migrations
|
|||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Co2")
|
||||
.HasColumnType("TEXT");
|
||||
b.Property<int?>("Co2")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime>("Created")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Humidity")
|
||||
b.Property<int?>("Humidity")
|
||||
.HasColumnType("decimal(18, 2)");
|
||||
|
||||
b.Property<int?>("Pm02")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<decimal>("Temperature")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Pm02")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Temperature")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Wifi")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
b.Property<int>("Wifi")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
|
|
|
@ -1,13 +1,16 @@
|
|||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace AirGradientWebApi.Models
|
||||
{
|
||||
public class Measurement
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Wifi { get; set; } = string.Empty;
|
||||
public string? Co2 { get; set; }
|
||||
public string? Pm02 { get; set; }
|
||||
public string Temperature { get; set; } = string.Empty;
|
||||
public string? Humidity { get; set; }
|
||||
public int Wifi { get; set; }
|
||||
public int? Co2 { get; set; }
|
||||
public int? Pm02 { get; set; }
|
||||
public decimal Temperature { get; set; }
|
||||
[Column(TypeName = "decimal(18, 2)")]
|
||||
public int? Humidity { get; set; }
|
||||
public DateTime Created { get; set; } = DateTime.UtcNow;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using AirGradientWebApi;
|
||||
using Microsoft.AspNetCore.HttpOverrides;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
@ -29,11 +31,19 @@ if (app.Environment.IsDevelopment())
|
|||
}
|
||||
app.UseRouting();
|
||||
|
||||
app.MapGet("/test", () => {
|
||||
app.MapGet("/test", ([FromServices]ILogger<Program> logger) => {
|
||||
logger.LogInformation("Test accessed");
|
||||
return Results.Ok("Test looks good.");
|
||||
});
|
||||
|
||||
app.MapPost("/sensors/airgradient:{chipId}/measures", async (string chipId, AirGradientData data) => {
|
||||
app.MapPost("/sensors/airgradient:{chipId}/measures", async (string chipId, AirGradientData data, [FromServices]ILogger<Program> logger) => {
|
||||
logger.LogInformation(chipId + " = " + JsonSerializer.Serialize(data));
|
||||
|
||||
return Results.Ok();
|
||||
});
|
||||
app.MapPost("/asdf/sensors/airgradient:{chipId}/measures", async (string chipId, object data, [FromServices]ILogger<Program> logger) => {
|
||||
logger.LogInformation(JsonSerializer.Serialize(data));
|
||||
|
||||
return Results.Ok();
|
||||
});
|
||||
|
||||
|
@ -41,14 +51,14 @@ app.Run();
|
|||
|
||||
record AirGradientData(
|
||||
[property: JsonPropertyName("wifi")]
|
||||
string Wifi,
|
||||
[property: JsonPropertyName("rc02")]
|
||||
string? Co2,
|
||||
int Wifi,
|
||||
[property: JsonPropertyName("rco2")]
|
||||
int? Co2,
|
||||
[property: JsonPropertyName("pm02")]
|
||||
string? Pm02,
|
||||
int? Pm02,
|
||||
[property: JsonPropertyName("atmp")]
|
||||
string Temperature,
|
||||
decimal Temperature,
|
||||
[property: JsonPropertyName("rhum")]
|
||||
string? Humidity
|
||||
int? Humidity
|
||||
) {
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue