Compare commits
1 Commits
85c462a614
...
a44912ac87
| Author | SHA1 | Date | |
|---|---|---|---|
| a44912ac87 |
@ -3,9 +3,10 @@
|
||||
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="9.0.6" />
|
||||
<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.6" />
|
||||
<PackageVersion Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.6" />
|
||||
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.6" />
|
||||
<PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" />
|
||||
<PackageVersion Include="portaloggy" Version="1.0.2" />
|
||||
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="9.0.0" />
|
||||
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.6" />
|
||||
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageVersion Include="Swashbuckle.AspNetCore" Version="7.1.0" />
|
||||
</ItemGroup>
|
||||
|
||||
@ -49,9 +49,9 @@ Additional tunables, with their sustainable default values:
|
||||
- `QUERY_RATE_PER_MINUTE: 100`
|
||||
- Sets maximum allowed client query rate per minute for all endpoints. Anonymous users share same limit pool.
|
||||
- If send rate is exceeded, client receives a `HTTP 429` with explanation.
|
||||
- `DEFAULT_MESSAGE_LIFETIME_IN_MINUTES: 1`
|
||||
- `DEFAULT_MESSAGE_TIME_TO_LIVE_IN_SECONDS: 60`
|
||||
- Message will wait for delivery for set amount of time. After the time passes, a call to `/receive` will not consider it for delivery anymore.
|
||||
- Override this in message content by setting _optional_ `lifespanInSeconds` value inside the request.
|
||||
- Override this in message content by setting _optional_ `timeToLiveInSeconds` value inside the request.
|
||||
- There will be no indication to the sender or to client that there was a missed message. Once it's gone, it's gone.
|
||||
- `HOUSEKEEPING_ENABLED: true`
|
||||
- Turns on housekeeping job that periodically removes stale, delivered and/or acknowledged messages. You can tune this further, see below. By default, it only removes messages that are 2 hours old, regardless of their delivery or acknowledgement state.
|
||||
@ -106,7 +106,7 @@ Request:
|
||||
"payloadType": "STATUS",
|
||||
"payload": "{\n \"system\": \"OK\",\n}",
|
||||
"toUserId": "46b882b7-4b96-4fa2-ba1b-4955a9500c36",
|
||||
"lifespanInSeconds": "3600"
|
||||
"timeToLiveInSeconds": "3600"
|
||||
}
|
||||
|
||||
Response:
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>disable</Nullable>
|
||||
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@ -31,7 +31,7 @@ namespace MessengerApi.Configuration.Model
|
||||
/// <summary>
|
||||
/// Message lifetime unless set differently in message body.
|
||||
/// </summary>
|
||||
public int DefaultMessageLifetimeInMinutes { get; set; }
|
||||
public int DefaultMessageTimeToLiveInSeconds { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// If true, messages are periodically wiped to free up space.
|
||||
@ -72,7 +72,7 @@ namespace MessengerApi.Configuration.Model
|
||||
this.Origins = origins ?? [];
|
||||
this.Proxies = [];
|
||||
this.RateLimitPerMinute = 120;
|
||||
this.DefaultMessageLifetimeInMinutes = 1;
|
||||
this.DefaultMessageTimeToLiveInSeconds = 60;
|
||||
this.HousekeepingEnabled = true;
|
||||
this.HousekeepingMessageAgeInMinutes = 120;
|
||||
this.HousekeepingMessageState = HousekeepingMessageStates.None;
|
||||
@ -85,7 +85,7 @@ namespace MessengerApi.Configuration.Model
|
||||
{
|
||||
Populate<string>(config, Env.PROXIES, x => this.Proxies = ProxiesParser.Parse(x));
|
||||
Populate<int>(config, Env.QUERY_RATE_PER_MINUTE, x => this.RateLimitPerMinute = x);
|
||||
Populate<int>(config, Env.DEFAULT_MESSAGE_LIFETIME_IN_MINUTES, x => this.DefaultMessageLifetimeInMinutes = x);
|
||||
Populate<int>(config, Env.DEFAULT_MESSAGE_TIME_TO_LIVE_IN_SECONDS, x => this.DefaultMessageTimeToLiveInSeconds = x);
|
||||
Populate<bool>(config, Env.HOUSEKEEPING_ENABLED, x => this.HousekeepingEnabled = x);
|
||||
Populate<int>(config, Env.HOUSEKEEPING_MESSAGE_AGE_IN_MINUTES, x => this.HousekeepingMessageAgeInMinutes = x);
|
||||
Populate<string>(config, Env.HOUSEKEEPING_MESSAGE_STATE, x => this.HousekeepingMessageState = HousekeepingMessageStateParser.Parse(x));
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
public const string CORS_ORIGINS = nameof(CORS_ORIGINS);
|
||||
public const string PROXIES = nameof(PROXIES);
|
||||
public const string QUERY_RATE_PER_MINUTE = nameof(QUERY_RATE_PER_MINUTE);
|
||||
public const string DEFAULT_MESSAGE_LIFETIME_IN_MINUTES = nameof(DEFAULT_MESSAGE_LIFETIME_IN_MINUTES);
|
||||
public const string DEFAULT_MESSAGE_TIME_TO_LIVE_IN_SECONDS = nameof(DEFAULT_MESSAGE_TIME_TO_LIVE_IN_SECONDS);
|
||||
public const string HOUSEKEEPING_ENABLED = nameof(HOUSEKEEPING_ENABLED);
|
||||
public const string HOUSEKEEPING_MESSAGE_AGE_IN_MINUTES = nameof(HOUSEKEEPING_MESSAGE_AGE_IN_MINUTES);
|
||||
public const string HOUSEKEEPING_MESSAGE_STATE = nameof(HOUSEKEEPING_MESSAGE_STATE);
|
||||
|
||||
@ -20,6 +20,6 @@ namespace MessengerApi.Db.Entities
|
||||
|
||||
public string Payload { get; set; }
|
||||
|
||||
public int? PayloadLifespanInSeconds { get; set; }
|
||||
public int? TimeToLiveInSeconds { get; set; }
|
||||
}
|
||||
}
|
||||
@ -4,6 +4,7 @@
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>disable</Nullable>
|
||||
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@ -8,10 +8,15 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.6" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.6">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.6">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@ -3,11 +3,12 @@
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<Nullable>disable</Nullable>
|
||||
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
123
code/MessengerApi.Db.Npg/Migrations/20250705145537_RenameTtlColumn.Designer.cs
generated
Normal file
123
code/MessengerApi.Db.Npg/Migrations/20250705145537_RenameTtlColumn.Designer.cs
generated
Normal file
@ -0,0 +1,123 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using MessengerApi.Db.Npg;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace MessengerApi.Db.Npg.Migrations
|
||||
{
|
||||
[DbContext(typeof(MessengerNpgDbContext))]
|
||||
[Migration("20250705145537_RenameTtlColumn")]
|
||||
partial class RenameTtlColumn
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "9.0.6")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("MessengerApi.Db.Entities.Message", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<DateTime>("CreatedUtc")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<Guid>("FromId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<bool>("IsAcknowledged")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<bool>("IsDelivered")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("Payload")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("PayloadType")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("TimeToLiveInSeconds")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<Guid>("ToId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ToId", "IsDelivered");
|
||||
|
||||
b.ToTable("Messages");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MessengerApi.Db.Entities.User", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<Guid>("ApiKey")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<bool>("IsEnabled")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Users");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MessengerApi.Db.Entities.UserRoute", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<Guid?>("FromId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<Guid?>("ToId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("FromId");
|
||||
|
||||
b.HasIndex("ToId");
|
||||
|
||||
b.ToTable("UserRoutes");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MessengerApi.Db.Entities.UserRoute", b =>
|
||||
{
|
||||
b.HasOne("MessengerApi.Db.Entities.User", "From")
|
||||
.WithMany()
|
||||
.HasForeignKey("FromId");
|
||||
|
||||
b.HasOne("MessengerApi.Db.Entities.User", "To")
|
||||
.WithMany()
|
||||
.HasForeignKey("ToId");
|
||||
|
||||
b.Navigation("From");
|
||||
|
||||
b.Navigation("To");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace MessengerApi.Db.Npg.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class RenameTtlColumn : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.RenameColumn(
|
||||
name: "PayloadLifespanInSeconds",
|
||||
table: "Messages",
|
||||
newName: "TimeToLiveInSeconds");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.RenameColumn(
|
||||
name: "TimeToLiveInSeconds",
|
||||
table: "Messages",
|
||||
newName: "PayloadLifespanInSeconds");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -43,12 +43,12 @@ namespace MessengerApi.Db.Npg.Migrations
|
||||
b.Property<string>("Payload")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("PayloadLifespanInSeconds")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("PayloadType")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("TimeToLiveInSeconds")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<Guid>("ToId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
|
||||
@ -13,6 +13,10 @@
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.6">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@ -4,10 +4,11 @@
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.6" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
125
code/MessengerApi.Db.Sql/Migrations/20250705145221_ShortenPayloadLifespanColumnName.Designer.cs
generated
Normal file
125
code/MessengerApi.Db.Sql/Migrations/20250705145221_ShortenPayloadLifespanColumnName.Designer.cs
generated
Normal file
@ -0,0 +1,125 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using MessengerApi.Db.Sql;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace MessengerApi.Db.Sql.Migrations
|
||||
{
|
||||
[DbContext(typeof(MessengerSqlDbContext))]
|
||||
[Migration("20250705145221_ShortenPayloadLifespanColumnName")]
|
||||
partial class ShortenPayloadLifespanColumnName
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "9.0.6")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("MessengerApi.Db.Entities.Message", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<DateTime>("CreatedUtc")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<Guid>("FromId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<bool>("IsAcknowledged")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<bool>("IsDelivered")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<int>("LifespanInSeconds")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("Payload")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("PayloadType")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<Guid>("ToId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ToId", "IsDelivered");
|
||||
|
||||
SqlServerIndexBuilderExtensions.IsClustered(b.HasIndex("ToId", "IsDelivered"), false);
|
||||
|
||||
b.ToTable("Messages");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MessengerApi.Db.Entities.User", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<Guid>("ApiKey")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<bool>("IsEnabled")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Users");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MessengerApi.Db.Entities.UserRoute", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<Guid?>("FromId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<Guid?>("ToId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("FromId");
|
||||
|
||||
b.HasIndex("ToId");
|
||||
|
||||
b.ToTable("UserRoutes");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MessengerApi.Db.Entities.UserRoute", b =>
|
||||
{
|
||||
b.HasOne("MessengerApi.Db.Entities.User", "From")
|
||||
.WithMany()
|
||||
.HasForeignKey("FromId");
|
||||
|
||||
b.HasOne("MessengerApi.Db.Entities.User", "To")
|
||||
.WithMany()
|
||||
.HasForeignKey("ToId");
|
||||
|
||||
b.Navigation("From");
|
||||
|
||||
b.Navigation("To");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace MessengerApi.Db.Sql.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class ShortenPayloadLifespanColumnName : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.RenameColumn(
|
||||
name: "PayloadLifespanInSeconds",
|
||||
table: "Messages",
|
||||
newName: "LifespanInSeconds");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.RenameColumn(
|
||||
name: "LifespanInSeconds",
|
||||
table: "Messages",
|
||||
newName: "PayloadLifespanInSeconds");
|
||||
}
|
||||
}
|
||||
}
|
||||
125
code/MessengerApi.Db.Sql/Migrations/20250705145452_RenameTtlColumnName.Designer.cs
generated
Normal file
125
code/MessengerApi.Db.Sql/Migrations/20250705145452_RenameTtlColumnName.Designer.cs
generated
Normal file
@ -0,0 +1,125 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using MessengerApi.Db.Sql;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace MessengerApi.Db.Sql.Migrations
|
||||
{
|
||||
[DbContext(typeof(MessengerSqlDbContext))]
|
||||
[Migration("20250705145452_RenameTtlColumnName")]
|
||||
partial class RenameTtlColumnName
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "9.0.6")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("MessengerApi.Db.Entities.Message", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<DateTime>("CreatedUtc")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<Guid>("FromId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<bool>("IsAcknowledged")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<bool>("IsDelivered")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("Payload")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("PayloadType")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<int>("TimeToLiveInSeconds")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<Guid>("ToId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ToId", "IsDelivered");
|
||||
|
||||
SqlServerIndexBuilderExtensions.IsClustered(b.HasIndex("ToId", "IsDelivered"), false);
|
||||
|
||||
b.ToTable("Messages");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MessengerApi.Db.Entities.User", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<Guid>("ApiKey")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<bool>("IsEnabled")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Users");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MessengerApi.Db.Entities.UserRoute", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<Guid?>("FromId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<Guid?>("ToId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("FromId");
|
||||
|
||||
b.HasIndex("ToId");
|
||||
|
||||
b.ToTable("UserRoutes");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MessengerApi.Db.Entities.UserRoute", b =>
|
||||
{
|
||||
b.HasOne("MessengerApi.Db.Entities.User", "From")
|
||||
.WithMany()
|
||||
.HasForeignKey("FromId");
|
||||
|
||||
b.HasOne("MessengerApi.Db.Entities.User", "To")
|
||||
.WithMany()
|
||||
.HasForeignKey("ToId");
|
||||
|
||||
b.Navigation("From");
|
||||
|
||||
b.Navigation("To");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace MessengerApi.Db.Sql.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class RenameTtlColumnName : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.RenameColumn(
|
||||
name: "LifespanInSeconds",
|
||||
table: "Messages",
|
||||
newName: "TimeToLiveInSeconds");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.RenameColumn(
|
||||
name: "TimeToLiveInSeconds",
|
||||
table: "Messages",
|
||||
newName: "LifespanInSeconds");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -43,12 +43,12 @@ namespace MessengerApi.Db.Sql.Migrations
|
||||
b.Property<string>("Payload")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<int>("PayloadLifespanInSeconds")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("PayloadType")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<int>("TimeToLiveInSeconds")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<Guid>("ToId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
|
||||
@ -19,7 +19,7 @@ namespace MessengerApi.Db
|
||||
modelBuilder.Entity<User>().HasKey(e => e.Id);
|
||||
modelBuilder.Entity<Message>().HasKey(e => e.Id);
|
||||
modelBuilder.Entity<Message>().Property(e => e.CreatedUtc).HasConversion<DateTimeAsUtcValueConverter>();
|
||||
modelBuilder.Entity<Message>().Property(e => e.PayloadLifespanInSeconds).IsRequired();
|
||||
modelBuilder.Entity<Message>().Property(e => e.TimeToLiveInSeconds).IsRequired();
|
||||
modelBuilder.Entity<UserRoute>().HasKey(e => e.Id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,7 +16,7 @@ namespace MessengerApi.Db.Repositories
|
||||
|
||||
return this.db
|
||||
.Where(x => x.ToId == user.Id && x.IsDelivered == false)
|
||||
.Where(x => x.PayloadLifespanInSeconds == null || x.CreatedUtc.AddSeconds(x.PayloadLifespanInSeconds.Value) >= timestamp)
|
||||
.Where(x => x.TimeToLiveInSeconds == null || x.CreatedUtc.AddSeconds(x.TimeToLiveInSeconds.Value) >= timestamp)
|
||||
.OrderBy(x => x.CreatedUtc);
|
||||
}
|
||||
}
|
||||
|
||||
@ -32,7 +32,7 @@ namespace MessengerApi.Handlers.Endpoint
|
||||
Guid? toUserId,
|
||||
string payload,
|
||||
string payloadType,
|
||||
int? payloadLifespanInSeconds)
|
||||
int? timeToLiveInSeconds)
|
||||
{
|
||||
// Authorize.
|
||||
var targetRecipientId = toUserId.HasValue
|
||||
@ -50,7 +50,7 @@ namespace MessengerApi.Handlers.Endpoint
|
||||
ToId = targetRecipientId,
|
||||
Payload = payload,
|
||||
PayloadType = payloadType,
|
||||
PayloadLifespanInSeconds = payloadLifespanInSeconds ?? (this.configuration.DefaultMessageLifetimeInMinutes * 60)
|
||||
TimeToLiveInSeconds = timeToLiveInSeconds ?? (this.configuration.DefaultMessageTimeToLiveInSeconds)
|
||||
};
|
||||
|
||||
this.unitOfWork.Messages.Add(message);
|
||||
|
||||
@ -8,6 +8,6 @@
|
||||
|
||||
public string PayloadType { get; set; }
|
||||
|
||||
public int? PayloadLifetimeInSeconds { get; set; }
|
||||
public int? TimeToLiveInSeconds { get; set; }
|
||||
}
|
||||
}
|
||||
@ -184,7 +184,7 @@ namespace MessengerApi.Api
|
||||
{
|
||||
try
|
||||
{
|
||||
var response = await handler.SendMessage(request.ToUserId, request.Payload, request.PayloadType, request.PayloadLifetimeInSeconds);
|
||||
var response = await handler.SendMessage(request.ToUserId, request.Payload, request.PayloadType, request.TimeToLiveInSeconds);
|
||||
await unitOfWork.SaveChanges();
|
||||
return Results.Json(response.Id);
|
||||
}
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
"CORS_ORIGINS": "",
|
||||
"PROXIES": "",
|
||||
"QUERY_RATE_PER_MINUTE": "100",
|
||||
"DEFAULT_MESSAGE_LIFETIME_IN_MINUTES": "60",
|
||||
"DEFAULT_MESSAGE_TIME_TO_LIVE_IN_SECONDS": "60",
|
||||
"HOUSEKEEPING_ENABLED": "False",
|
||||
"LOGGING_VERBOSITY": "Trace"
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user