Skip to content

Commit 621e92d

Browse files
committed
Add rate limiting, download meta data tracking, more admin metrics, csv download functionality and more tests
1 parent 475a4ca commit 621e92d

20 files changed

Lines changed: 1517 additions & 43 deletions
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System.ComponentModel.DataAnnotations;
2+
3+
namespace RegistrationWebAPI.Data;
4+
5+
public class DownloadAuditEntity
6+
{
7+
public Guid Id { get; set; }
8+
9+
public DateTime DownloadedAtUtc { get; set; } = DateTime.UtcNow;
10+
11+
[Required]
12+
public string UserEmail { get; set; } = string.Empty;
13+
14+
public Guid? UserId { get; set; }
15+
16+
[Required]
17+
public string DownloadType { get; set; } = string.Empty;
18+
19+
[Required]
20+
public string Version { get; set; } = string.Empty;
21+
22+
public string? Platform { get; set; }
23+
24+
public string? DownloadUrl { get; set; }
25+
}

RegistrationWebAPI/Data/RegistrationDbContext.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ public class RegistrationDbContext(DbContextOptions<RegistrationDbContext> optio
99

1010
public DbSet<OrganisationEntity> Organisations => Set<OrganisationEntity>();
1111

12+
public DbSet<DownloadAuditEntity> DownloadAudits => Set<DownloadAuditEntity>();
13+
1214
protected override void OnModelCreating(ModelBuilder modelBuilder)
1315
{
1416
modelBuilder.Entity<UserEntity>(entity =>
@@ -30,5 +32,15 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
3032
entity.Property(e => e.Name).IsRequired();
3133
entity.HasIndex(e => e.Name).IsUnique();
3234
});
35+
36+
modelBuilder.Entity<DownloadAuditEntity>(entity =>
37+
{
38+
entity.HasKey(e => e.Id);
39+
entity.Property(e => e.UserEmail).IsRequired();
40+
entity.Property(e => e.DownloadType).IsRequired();
41+
entity.Property(e => e.Version).IsRequired();
42+
entity.HasIndex(e => e.DownloadedAtUtc);
43+
entity.HasIndex(e => e.UserEmail);
44+
});
3345
}
3446
}

RegistrationWebAPI/Migrations/20260527223413_AddDownloadAudits.Designer.cs

Lines changed: 170 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using System;
2+
using Microsoft.EntityFrameworkCore.Migrations;
3+
4+
#nullable disable
5+
6+
namespace RegistrationWebAPI.Migrations
7+
{
8+
/// <inheritdoc />
9+
public partial class AddDownloadAudits : Migration
10+
{
11+
/// <inheritdoc />
12+
protected override void Up(MigrationBuilder migrationBuilder)
13+
{
14+
migrationBuilder.CreateTable(
15+
name: "DownloadAudits",
16+
columns: table => new
17+
{
18+
Id = table.Column<Guid>(type: "TEXT", nullable: false),
19+
DownloadedAtUtc = table.Column<DateTime>(type: "TEXT", nullable: false),
20+
UserEmail = table.Column<string>(type: "TEXT", nullable: false),
21+
UserId = table.Column<Guid>(type: "TEXT", nullable: true),
22+
DownloadType = table.Column<string>(type: "TEXT", nullable: false),
23+
Version = table.Column<string>(type: "TEXT", nullable: false),
24+
Platform = table.Column<string>(type: "TEXT", nullable: true),
25+
DownloadUrl = table.Column<string>(type: "TEXT", nullable: true)
26+
},
27+
constraints: table =>
28+
{
29+
table.PrimaryKey("PK_DownloadAudits", x => x.Id);
30+
});
31+
32+
migrationBuilder.CreateIndex(
33+
name: "IX_DownloadAudits_DownloadedAtUtc",
34+
table: "DownloadAudits",
35+
column: "DownloadedAtUtc");
36+
37+
migrationBuilder.CreateIndex(
38+
name: "IX_DownloadAudits_UserEmail",
39+
table: "DownloadAudits",
40+
column: "UserEmail");
41+
}
42+
43+
/// <inheritdoc />
44+
protected override void Down(MigrationBuilder migrationBuilder)
45+
{
46+
migrationBuilder.DropTable(
47+
name: "DownloadAudits");
48+
}
49+
}
50+
}

RegistrationWebAPI/Migrations/RegistrationDbContextModelSnapshot.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,45 @@ protected override void BuildModel(ModelBuilder modelBuilder)
1717
#pragma warning disable 612, 618
1818
modelBuilder.HasAnnotation("ProductVersion", "10.0.5");
1919

20+
modelBuilder.Entity("RegistrationWebAPI.Data.DownloadAuditEntity", b =>
21+
{
22+
b.Property<Guid>("Id")
23+
.ValueGeneratedOnAdd()
24+
.HasColumnType("TEXT");
25+
26+
b.Property<string>("DownloadType")
27+
.IsRequired()
28+
.HasColumnType("TEXT");
29+
30+
b.Property<string>("DownloadUrl")
31+
.HasColumnType("TEXT");
32+
33+
b.Property<DateTime>("DownloadedAtUtc")
34+
.HasColumnType("TEXT");
35+
36+
b.Property<string>("Platform")
37+
.HasColumnType("TEXT");
38+
39+
b.Property<string>("UserEmail")
40+
.IsRequired()
41+
.HasColumnType("TEXT");
42+
43+
b.Property<Guid?>("UserId")
44+
.HasColumnType("TEXT");
45+
46+
b.Property<string>("Version")
47+
.IsRequired()
48+
.HasColumnType("TEXT");
49+
50+
b.HasKey("Id");
51+
52+
b.HasIndex("DownloadedAtUtc");
53+
54+
b.HasIndex("UserEmail");
55+
56+
b.ToTable("DownloadAudits");
57+
});
58+
2059
modelBuilder.Entity("RegistrationWebAPI.Data.OrganisationEntity", b =>
2160
{
2261
b.Property<Guid>("Id")
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
namespace RegistrationWebAPI.Models;
2+
3+
public class DownloadAuditResponse
4+
{
5+
public Guid Id { get; set; }
6+
7+
public DateTime DownloadedAtUtc { get; set; }
8+
9+
public string UserEmail { get; set; } = string.Empty;
10+
11+
public Guid? UserId { get; set; }
12+
13+
public string DownloadType { get; set; } = string.Empty;
14+
15+
public string Version { get; set; } = string.Empty;
16+
17+
public string? Platform { get; set; }
18+
19+
public string? DownloadUrl { get; set; }
20+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace RegistrationWebAPI.Models;
2+
3+
public class DownloadEventRequest
4+
{
5+
public string Token { get; set; } = string.Empty;
6+
7+
public string DownloadType { get; set; } = string.Empty;
8+
9+
public string Version { get; set; } = string.Empty;
10+
11+
public string? Platform { get; set; }
12+
13+
public string? DownloadUrl { get; set; }
14+
}

0 commit comments

Comments
 (0)