Compare commits
3 Commits
36a78a8284
...
7b779463bb
Author | SHA1 | Date | |
---|---|---|---|
7b779463bb | |||
baedc667b7 | |||
0e9bb04b96 |
22
ApiDto/Common/PairPeriodTime.cs
Normal file
22
ApiDto/Common/PairPeriodTime.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Mirea.Api.Dto.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a pair of time periods.
|
||||
/// </summary>
|
||||
public class PairPeriodTime
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the start time of the period.
|
||||
/// </summary>
|
||||
[Required]
|
||||
public TimeOnly Start { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the end time of the period.
|
||||
/// </summary>
|
||||
[Required]
|
||||
public TimeOnly End { get; set; }
|
||||
}
|
9
Endpoint/Common/Interfaces/ISetupToken.cs
Normal file
9
Endpoint/Common/Interfaces/ISetupToken.cs
Normal file
@ -0,0 +1,9 @@
|
||||
using System;
|
||||
|
||||
namespace Mirea.Api.Endpoint.Common.Interfaces;
|
||||
|
||||
public interface ISetupToken
|
||||
{
|
||||
bool MatchToken(ReadOnlySpan<byte> token);
|
||||
void SetToken(ReadOnlySpan<byte> token);
|
||||
}
|
13
Endpoint/Common/Services/PairPeriodTimeConverter.cs
Normal file
13
Endpoint/Common/Services/PairPeriodTimeConverter.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using Mirea.Api.Endpoint.Configuration.General.Settings;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Mirea.Api.Endpoint.Common.Services;
|
||||
|
||||
public static class PairPeriodTimeConverter
|
||||
{
|
||||
public static Dictionary<int, Dto.Common.PairPeriodTime> ConvertToDto(this IDictionary<int, ScheduleSettings.PairPeriodTime> pairPeriod) =>
|
||||
pairPeriod.ToDictionary(kvp => kvp.Key, kvp => new Dto.Common.PairPeriodTime { Start = kvp.Value.Start, End = kvp.Value.End });
|
||||
|
||||
public static Dictionary<int, ScheduleSettings.PairPeriodTime> ConvertFromDto(this IDictionary<int, Dto.Common.PairPeriodTime> pairPeriod) => pairPeriod.ToDictionary(kvp => kvp.Key, kvp => new ScheduleSettings.PairPeriodTime(kvp.Value.Start, kvp.Value.End));
|
||||
}
|
28
Endpoint/Configuration/General/SetupTokenService.cs
Normal file
28
Endpoint/Configuration/General/SetupTokenService.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using Mirea.Api.Endpoint.Common.Interfaces;
|
||||
using System;
|
||||
|
||||
namespace Mirea.Api.Endpoint.Configuration.General;
|
||||
|
||||
public class SetupTokenService : ISetupToken
|
||||
{
|
||||
public ReadOnlyMemory<byte>? Token { get; private set; }
|
||||
|
||||
public bool MatchToken(ReadOnlySpan<byte> token)
|
||||
{
|
||||
if (Token == null || token.Length != Token.Value.Length)
|
||||
return false;
|
||||
|
||||
var token2 = Token.Value.Span;
|
||||
|
||||
int result = 0;
|
||||
for (int i = 0; i < Token.Value.Length; i++)
|
||||
result |= token2[i] ^ token[i];
|
||||
|
||||
return result == 0;
|
||||
}
|
||||
|
||||
public void SetToken(ReadOnlySpan<byte> token)
|
||||
{
|
||||
Token = token.ToArray();
|
||||
}
|
||||
}
|
@ -8,6 +8,7 @@ using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Mirea.Api.DataAccess.Application;
|
||||
using Mirea.Api.DataAccess.Persistence;
|
||||
using Mirea.Api.Endpoint.Common.Interfaces;
|
||||
using Mirea.Api.Endpoint.Common.Services;
|
||||
using Mirea.Api.Endpoint.Configuration;
|
||||
using Mirea.Api.Endpoint.Configuration.General;
|
||||
@ -50,6 +51,7 @@ public class Program
|
||||
builder.Services.AddPersistence(builder.Configuration.Get<GeneralConfig>()?.DbSettings?.ConnectionStringSql ?? string.Empty);
|
||||
builder.Services.AddControllers();
|
||||
|
||||
builder.Services.AddSingleton<ISetupToken, SetupTokenService>();
|
||||
builder.Services.AddCors(options =>
|
||||
{
|
||||
options.AddPolicy("AllowAll", policy =>
|
||||
|
Loading…
Reference in New Issue
Block a user