Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

Commit

Permalink
Modify DeviceSpecification
Browse files Browse the repository at this point in the history
  • Loading branch information
hhvrc committed Jul 6, 2023
1 parent 17e84ce commit 68b5cc2
Show file tree
Hide file tree
Showing 10 changed files with 137 additions and 103 deletions.
24 changes: 23 additions & 1 deletion Common/DTOs/DeviceDTO.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,30 @@
namespace ZapMe.DTOs;
using ZapMe.Enums.Devices;

namespace ZapMe.DTOs;

public readonly struct DeviceDto
{
public Guid Id { get; init; }

public string Name { get; init; }

public Guid ModelId { get; init; }

public string ModelName { get; init; }

public string ModelNumber { get; init; }

public string ModelWebsiteUrl { get; init; }

public Uri IconUrl { get; init; }

public RfProtocol Protocol { get; init; }

public Guid ManufacturerId { get; init; }

public string ManufacturerName { get; init; }

public string ManufacturerWebsiteUrl { get; init; }

public DateTime RegisteredAt { get; init; }
}
44 changes: 44 additions & 0 deletions Common/Database/Documents/DeviceProprietarySpecification.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using Marten.Schema;

namespace ZapMe.Database.Documents;

/// <summary>
/// The Proprietary RF Protocol specification for a device, used to configure the RF transceiver.
/// </summary>
[DocumentAlias("device_proprietary_spec")]
public sealed class DeviceProprietarySpecification
{
public Guid Id { get; init; }

// Carrier wave modulation schemes
public enum ModulationType
{
ASK, // Amplitude Shift Keying
OOK, // On-Off Keying
GFSK, // Gaussian Frequency Shift Keying
FSK, // Frequency Shift Keying
FSK2, // Frequency Shift Keying 2
FSK4, // Frequency Shift Keying 4
MSK, // Minimum Shift Keying
}

// Bit-level encoding schemes
public enum EncodingType
{
None,
Proprietary,
Manchester,
}

public ulong Frequency { get; init; }

public ModulationType Modulation { get; init; }

public ulong DataRate { get; init; }

public ulong PacketSize { get; init; }

public EncodingType Encoding { get; init; }

public bool InvertedBits { get; init; }
}
84 changes: 0 additions & 84 deletions Common/Database/Documents/DeviceSpecification.cs

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

Expand Down Expand Up @@ -50,7 +49,7 @@ protected override void Up(MigrationBuilder migrationBuilder)
IconId = table.Column<Guid>(type: "uuid", nullable: false),
ManufacturerId = table.Column<Guid>(type: "uuid", nullable: false),
FccId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true),
HasDocumentation = table.Column<bool>(type: "boolean", nullable: false),
DocumentationUrl = table.Column<string>(type: "text", nullable: true),
Protocol = table.Column<string>(type: "text", nullable: false),
SpecificationId = table.Column<Guid>(type: "uuid", nullable: true),
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()")
Expand Down
6 changes: 3 additions & 3 deletions Common/Database/Migrations/DatabaseContextModelSnapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.HasColumnType("timestamp with time zone")
.HasDefaultValueSql("now()");
b.Property<string>("DocumentationUrl")
.HasColumnType("text");
b.Property<string>("FccId")
.HasMaxLength(32)
.HasColumnType("character varying(32)");
b.Property<bool>("HasDocumentation")
.HasColumnType("boolean");
b.Property<Guid>("IconId")
.HasColumnType("uuid");
Expand Down
10 changes: 5 additions & 5 deletions Common/Database/Models/DeviceModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@ public sealed class DeviceModelEntity
public string? FccId { get; init; }

/// <summary>
/// Indicates whether this device model has documentation available.
/// <para>If <see langword="true"/>, the documentation is available at /docs/{id} where {id} is the ID of this device model.</para>
/// Optional URL to documentation for this device model. (most likely going to a a .md file in a GitHub repo)
/// </summary>
public bool HasDocumentation { get; set; }
public string? DocumentationUrl { get; set; }

/// <summary>
/// The protocol used by this device model, this might be Raw RF, Bluetooth Low Energy, WiFi, etc.
/// The protocol used by this device model, this might be Proprietary, Bluetooth Low Energy, WiFi, etc.
/// </summary>
public RfProtocol Protocol { get; set; }

/// <summary>
/// Use Marten to access highly dynamic JSONB data for device specifications stored in <see cref="Documents.DeviceSpecification"/>, the document ID is the same as this property.
/// Id of highly dynamic JSONB data for device specifications stored using MartenDB, the document ID is the same as this property.
/// <para>Use <see cref="Protocol"/> to determine which document type to use.</para>
/// <para><see cref="RfProtocol.Proprietary"/>: <see cref="Documents.DeviceProprietarySpecification"/></para>
/// </summary>
public Guid? SpecificationId { get; init; }

Expand Down
16 changes: 13 additions & 3 deletions Common/Mappers/DeviceMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,22 @@ namespace ZapMe.DTOs;

public static class DeviceMapper
{
public static DeviceDto MapToDeviceDto(DeviceEntity user)
public static DeviceDto MapToDeviceDto(DeviceEntity device)
{
return new DeviceDto
{
Id = user.Id,
RegisteredAt = user.CreatedAt
Id = device.Id,
Name = device.Name,
ModelId = device.ModelId,
ModelName = device.Model!.Name,
ModelNumber = device.Model!.ModelNumber,
ModelWebsiteUrl = device.Model!.WebsiteUrl,
IconUrl = device.Model!.Icon!.PublicUrl,
Protocol = device.Model!.Protocol,
ManufacturerId = device.Model!.ManufacturerId,
ManufacturerName = device.Model!.Manufacturer!.Name,
ManufacturerWebsiteUrl = device.Model!.Manufacturer!.WebsiteUrl,
RegisteredAt = device.CreatedAt
};
}
}
2 changes: 2 additions & 0 deletions RestAPI/Controllers/Api/V1/Device/Get.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public async Task<IActionResult> Get(Guid deviceId, CancellationToken cancellati
DeviceEntity? device = await _dbContext
.Devices
.AsNoTracking()
.Include(d => d.Model)
.ThenInclude(m => m!.Manufacturer)
.FirstOrDefaultAsync(d => d.Id == deviceId, cancellationToken);
if (device is null)
{
Expand Down
41 changes: 41 additions & 0 deletions spec/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -997,13 +997,47 @@ components:
additionalProperties: false
DeviceDto:
required:
- iconUrl
- id
- manufacturerId
- manufacturerName
- manufacturerWebsiteUrl
- modelId
- modelName
- modelNumber
- modelWebsiteUrl
- name
- protocol
- registeredAt
type: object
properties:
id:
type: string
format: uuid
name:
type: string
modelId:
type: string
format: uuid
modelName:
type: string
modelNumber:
type: string
modelWebsiteUrl:
type: string
iconUrl:
type: string
format: uri
protocol:
allOf:
- $ref: '#/components/schemas/RfProtocol'
manufacturerId:
type: string
format: uuid
manufacturerName:
type: string
manufacturerWebsiteUrl:
type: string
registeredAt:
type: string
format: date-time
Expand Down Expand Up @@ -1128,6 +1162,13 @@ components:
description: Response from cloudflare turnstile request
additionalProperties: false
description: Request sent to server to request a password reset token
RfProtocol:
enum:
- proprietary
- ble
- wiFi
- zigBee
type: string
SocialsConfig:
type: object
properties:
Expand Down

0 comments on commit 68b5cc2

Please sign in to comment.