Fixed endpoints for /users and /messages.
This commit is contained in:
@ -14,11 +14,11 @@ namespace MessengerBroker.Configuration.Parsers
|
||||
|
||||
if (type == MessengerApi.Configuration.Enums.PersistenceTypes.Sql)
|
||||
{
|
||||
return new SqlPersistenceConfiguration(config);
|
||||
return new SqlPersistenceConfiguration(config.GetValue<string>(Constants.EnvironmentVariables.API_SQL_CONNECTIONSTRING));
|
||||
}
|
||||
else if (type == MessengerApi.Configuration.Enums.PersistenceTypes.PostgreSql)
|
||||
{
|
||||
return new NpgPersistenceConfiguration(config);
|
||||
return new NpgPersistenceConfiguration(config.GetValue<string>(Constants.EnvironmentVariables.API_NPG_CONNECTIONSTRING));
|
||||
}
|
||||
|
||||
throw new InvalidOperationException("Unrecognized persistence type.");
|
||||
|
||||
@ -0,0 +1,12 @@
|
||||
using Microsoft.EntityFrameworkCore.Design;
|
||||
|
||||
namespace MessengerBroker.Db.Sql.Migrator
|
||||
{
|
||||
public partial class DesignTimeDbContextFactory : IDesignTimeDbContextFactory<BrokerSqlDbContext>
|
||||
{
|
||||
public BrokerSqlDbContext CreateDbContext(string[] args)
|
||||
{
|
||||
return new BrokerSqlDbContext(CONNECTION_STRING);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<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>
|
||||
<ProjectReference Include="..\MessengerBroker.Db.Sql\MessengerBroker.Db.Sql.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
11
code/MessengerBroker.Db.Sql.Migrator/Program.cs
Normal file
11
code/MessengerBroker.Db.Sql.Migrator/Program.cs
Normal file
@ -0,0 +1,11 @@
|
||||
namespace MessengerBroker.Db.Sql.Migrator
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
// Add-Migration Initial -Project MessengerBroker.Db.Sql -StartupProject MessengerBroker.Db.Sql.Migrator -Verbose -Context BrokerSqlDbContext
|
||||
// Update-Database -Project MessengerBroker.Db.Sql -StartupProject MessengerBroker.Db.Sql.Migrator -Verbose -Context BrokerSqlDbContext
|
||||
}
|
||||
}
|
||||
}
|
||||
83
code/MessengerBroker.Db.Sql/Migrations/20250705074809_Initial.Designer.cs
generated
Normal file
83
code/MessengerBroker.Db.Sql/Migrations/20250705074809_Initial.Designer.cs
generated
Normal file
@ -0,0 +1,83 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using MessengerBroker.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 MessengerBroker.Db.Sql.Migrations
|
||||
{
|
||||
[DbContext(typeof(BrokerSqlDbContext))]
|
||||
[Migration("20250705074809_Initial")]
|
||||
partial class Initial
|
||||
{
|
||||
/// <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("MessengerBroker.Db.Model.Message", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<Guid>("BrokerId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Messages");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MessengerBroker.Db.Model.Sync", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<Guid>("BrokerId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<long?>("Changes")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<DateTime?>("FinishedUtc")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<DateTime>("StartedUtc")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Syncs");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MessengerBroker.Db.Model.User", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<Guid>("BrokerId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Users");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,68 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace MessengerBroker.Db.Sql.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class Initial : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Messages",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
|
||||
BrokerId = table.Column<Guid>(type: "uniqueidentifier", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Messages", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Syncs",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
BrokerId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
|
||||
StartedUtc = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
FinishedUtc = table.Column<DateTime>(type: "datetime2", nullable: true),
|
||||
Changes = table.Column<long>(type: "bigint", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Syncs", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Users",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
|
||||
BrokerId = table.Column<Guid>(type: "uniqueidentifier", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Users", x => x.Id);
|
||||
});
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "Messages");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Syncs");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Users");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,80 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using MessengerBroker.Db.Sql;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace MessengerBroker.Db.Sql.Migrations
|
||||
{
|
||||
[DbContext(typeof(BrokerSqlDbContext))]
|
||||
partial class BrokerSqlDbContextModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "9.0.6")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("MessengerBroker.Db.Model.Message", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<Guid>("BrokerId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Messages");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MessengerBroker.Db.Model.Sync", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<Guid>("BrokerId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<long?>("Changes")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<DateTime?>("FinishedUtc")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<DateTime>("StartedUtc")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Syncs");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MessengerBroker.Db.Model.User", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<Guid>("BrokerId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Users");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -5,10 +5,10 @@ namespace MessengerBroker.Db
|
||||
{
|
||||
public class BrokerDbContext : DbContext
|
||||
{
|
||||
public DbSet<Sync> Syncs { get; }
|
||||
public DbSet<Sync> Syncs { get; set; }
|
||||
|
||||
public DbSet<User> Users { get; }
|
||||
public DbSet<User> Users { get; set; }
|
||||
|
||||
public DbSet<Message> Messages { get; }
|
||||
public DbSet<Message> Messages { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@ -27,6 +27,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MessengerApi.Db.Sql", "..\s
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MessengerApi.Db.Npg", "..\subm\messengerapi\code\MessengerApi.Db.Npg\MessengerApi.Db.Npg.csproj", "{2A08099B-1A1E-FE40-9220-43F26AF852EC}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MessengerBroker.Db.Sql.Migrator", "MessengerBroker.Db.Sql.Migrator\MessengerBroker.Db.Sql.Migrator.csproj", "{B6AC564C-F5D0-4A6E-B1A2-A6942B9B2E5C}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -73,6 +75,10 @@ Global
|
||||
{2A08099B-1A1E-FE40-9220-43F26AF852EC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{2A08099B-1A1E-FE40-9220-43F26AF852EC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{2A08099B-1A1E-FE40-9220-43F26AF852EC}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{B6AC564C-F5D0-4A6E-B1A2-A6942B9B2E5C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{B6AC564C-F5D0-4A6E-B1A2-A6942B9B2E5C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B6AC564C-F5D0-4A6E-B1A2-A6942B9B2E5C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{B6AC564C-F5D0-4A6E-B1A2-A6942B9B2E5C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@ -86,6 +92,7 @@ Global
|
||||
{FCE9214C-CDCB-4D79-B7AB-2BCBAD41AC35} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
|
||||
{5F0E1A67-056B-E6B9-1940-5F31587C05CE} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
|
||||
{2A08099B-1A1E-FE40-9220-43F26AF852EC} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
|
||||
{B6AC564C-F5D0-4A6E-B1A2-A6942B9B2E5C} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {F0F93DDE-2CDC-4A7D-9D70-A7A12B3AF9CE}
|
||||
|
||||
@ -37,10 +37,14 @@ namespace MessengerBroker.Handlers.Endpoint
|
||||
.Where(x => !foreignUserIds.Any(f => f == x.Id))
|
||||
.ToArray();
|
||||
|
||||
var localUserIds = localUsers
|
||||
.Select(x => x.Id)
|
||||
.ToArray();
|
||||
|
||||
var localRoutes = apiCtx.UserRoutes
|
||||
.Include(x => x.From)
|
||||
.Include(x => x.To)
|
||||
.Where(x => localUsers.Any(l => l.Id == x.From.Id) && localUsers.Any(l => l.Id == x.To.Id))
|
||||
.Where(x => localUserIds.Contains(x.From.Id) || localUserIds.Contains(x.To.Id))
|
||||
.ToArray();
|
||||
|
||||
return Task.FromResult(new Users.UsersResponse
|
||||
|
||||
@ -7,6 +7,7 @@ using MessengerBroker.Model.Http;
|
||||
using MessengerBroker.Models.Scoped;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.HttpOverrides;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Net;
|
||||
|
||||
@ -123,9 +124,13 @@ namespace MessengerBroker
|
||||
|
||||
app.MapGet("/messages", async (
|
||||
MessagesEndpointHandler handler,
|
||||
[AsParameters] Messages.MessagesRequest request) =>
|
||||
[FromQuery] Guid ownerBrokerId, DateTime fromUtc) =>
|
||||
{
|
||||
var response = await handler.GetMessages(request);
|
||||
var response = await handler.GetMessages(new Messages.MessagesRequest
|
||||
{
|
||||
OwnerBrokerId = ownerBrokerId,
|
||||
SinceUtc = DateTime.MinValue
|
||||
});
|
||||
return Results.Json(response);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user