fix: correct API route and table mapping for custom ASNs

- Rename API route from `/api/asns/{asn}/prefixes` to `/api/as/{asn}/prefixes` for consistency.
- Map `PeerCustomAsn` entity to the `PeerCustomAsns` database table.
This commit is contained in:
Mikhail Movchan 2026-06-11 20:40:19 +03:00
parent f2e9d82083
commit cba7a3cdf6
2 changed files with 4 additions and 3 deletions

View file

@ -53,6 +53,7 @@ public class BgpDbContext : DbContext
model.Entity<PeerCustomAsn>(e =>
{
e.ToTable("PeerCustomAsns");
e.HasKey(c => new { c.PeerId, c.Asn });
e.HasOne(c => c.Peer).WithMany(p => p.CustomAsns)
.HasForeignKey(c => c.PeerId).OnDelete(DeleteBehavior.Cascade);

View file

@ -151,8 +151,8 @@ public sealed class ManagementApi : IHostedService, IDisposable
if (IsGet(method, segments, "api", "routes"))
return HandleGetRoutes();
// /api/asns/{asn}/prefixes
if (segments.Length == 4 && segments[0] == "api" && segments[1] == "asns" && segments[3] == "prefixes" && method == "GET")
// /api/as/{asn}/prefixes
if (segments.Length == 4 && segments[0] == "api" && segments[1] == "as" && segments[3] == "prefixes" && method == "GET")
return HandleGetAsnPrefixes(segments[2], ctx);
return ApiResponse.Error("Not found", 404);
@ -554,7 +554,7 @@ public sealed class ManagementApi : IHostedService, IDisposable
#endregion
#region GET /api/asns/{asn}/prefixes
#region GET /api/as/{asn}/prefixes
private ApiResponse HandleGetAsnPrefixes(string asnStr, HttpListenerContext ctx)
{