✨ Badges
This commit is contained in:
		@@ -18,6 +18,7 @@ public class Account : ModelBase
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    public Profile Profile { get; set; } = null!;
 | 
					    public Profile Profile { get; set; } = null!;
 | 
				
			||||||
    public ICollection<AccountContact> Contacts { get; set; } = new List<AccountContact>();
 | 
					    public ICollection<AccountContact> Contacts { get; set; } = new List<AccountContact>();
 | 
				
			||||||
 | 
					    public ICollection<Badge> Badges { get; set; } = new List<Badge>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    [JsonIgnore] public ICollection<AccountAuthFactor> AuthFactors { get; set; } = new List<AccountAuthFactor>();
 | 
					    [JsonIgnore] public ICollection<AccountAuthFactor> AuthFactors { get; set; } = new List<AccountAuthFactor>();
 | 
				
			||||||
    [JsonIgnore] public ICollection<Auth.Session> Sessions { get; set; } = new List<Auth.Session>();
 | 
					    [JsonIgnore] public ICollection<Auth.Session> Sessions { get; set; } = new List<Auth.Session>();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -27,9 +27,8 @@ public class AccountController(
 | 
				
			|||||||
    public async Task<ActionResult<Account?>> GetByName(string name)
 | 
					    public async Task<ActionResult<Account?>> GetByName(string name)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        var account = await db.Accounts
 | 
					        var account = await db.Accounts
 | 
				
			||||||
 | 
					            .Include(e => e.Badges)
 | 
				
			||||||
            .Include(e => e.Profile)
 | 
					            .Include(e => e.Profile)
 | 
				
			||||||
            .Include(e => e.Profile.Picture)
 | 
					 | 
				
			||||||
            .Include(e => e.Profile.Background)
 | 
					 | 
				
			||||||
            .Where(a => a.Name == name)
 | 
					            .Where(a => a.Name == name)
 | 
				
			||||||
            .FirstOrDefaultAsync();
 | 
					            .FirstOrDefaultAsync();
 | 
				
			||||||
        return account is null ? new NotFoundResult() : account;
 | 
					        return account is null ? new NotFoundResult() : account;
 | 
				
			||||||
@@ -116,9 +115,8 @@ public class AccountController(
 | 
				
			|||||||
        var userId = currentUser.Id;
 | 
					        var userId = currentUser.Id;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        var account = await db.Accounts
 | 
					        var account = await db.Accounts
 | 
				
			||||||
 | 
					            .Include(e => e.Badges)
 | 
				
			||||||
            .Include(e => e.Profile)
 | 
					            .Include(e => e.Profile)
 | 
				
			||||||
            .Include(e => e.Profile.Picture)
 | 
					 | 
				
			||||||
            .Include(e => e.Profile.Background)
 | 
					 | 
				
			||||||
            .Where(e => e.Id == userId)
 | 
					            .Where(e => e.Id == userId)
 | 
				
			||||||
            .FirstOrDefaultAsync();
 | 
					            .FirstOrDefaultAsync();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										19
									
								
								DysonNetwork.Sphere/Account/Badge.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								DysonNetwork.Sphere/Account/Badge.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,19 @@
 | 
				
			|||||||
 | 
					using System.ComponentModel.DataAnnotations;
 | 
				
			||||||
 | 
					using System.ComponentModel.DataAnnotations.Schema;
 | 
				
			||||||
 | 
					using System.Text.Json.Serialization;
 | 
				
			||||||
 | 
					using NodaTime;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace DysonNetwork.Sphere.Account;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class Badge : ModelBase
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    public Guid Id { get; set; } = Guid.NewGuid();
 | 
				
			||||||
 | 
					    [MaxLength(1024)] public string Type { get; set; } = null!;
 | 
				
			||||||
 | 
					    [MaxLength(1024)] public string? Label { get; set; }
 | 
				
			||||||
 | 
					    [MaxLength(4096)] public string? Caption { get; set; }
 | 
				
			||||||
 | 
					    [Column(TypeName = "jsonb")] public Dictionary<string, object> Meta { get; set; } = new();
 | 
				
			||||||
 | 
					    public Instant? ExpiredAt { get; set; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public long AccountId { get; set; }
 | 
				
			||||||
 | 
					    [JsonIgnore] public Account Account { get; set; } = null!;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -34,6 +34,7 @@ public class AppDatabase(
 | 
				
			|||||||
    public DbSet<Account.CheckInResult> AccountCheckInResults { get; set; }
 | 
					    public DbSet<Account.CheckInResult> AccountCheckInResults { get; set; }
 | 
				
			||||||
    public DbSet<Account.Notification> Notifications { get; set; }
 | 
					    public DbSet<Account.Notification> Notifications { get; set; }
 | 
				
			||||||
    public DbSet<Account.NotificationPushSubscription> NotificationPushSubscriptions { get; set; }
 | 
					    public DbSet<Account.NotificationPushSubscription> NotificationPushSubscriptions { get; set; }
 | 
				
			||||||
 | 
					    public DbSet<Account.Badge> Badges { get; set; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public DbSet<Auth.Session> AuthSessions { get; set; }
 | 
					    public DbSet<Auth.Session> AuthSessions { get; set; }
 | 
				
			||||||
    public DbSet<Auth.Challenge> AuthChallenges { get; set; }
 | 
					    public DbSet<Auth.Challenge> AuthChallenges { get; set; }
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										2848
									
								
								DysonNetwork.Sphere/Migrations/20250512160008_AddAccountBadges.Designer.cs
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										2848
									
								
								DysonNetwork.Sphere/Migrations/20250512160008_AddAccountBadges.Designer.cs
									
									
									
										generated
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@@ -0,0 +1,55 @@
 | 
				
			|||||||
 | 
					using System;
 | 
				
			||||||
 | 
					using System.Collections.Generic;
 | 
				
			||||||
 | 
					using Microsoft.EntityFrameworkCore.Migrations;
 | 
				
			||||||
 | 
					using NodaTime;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#nullable disable
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace DysonNetwork.Sphere.Migrations
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    /// <inheritdoc />
 | 
				
			||||||
 | 
					    public partial class AddAccountBadges : Migration
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        /// <inheritdoc />
 | 
				
			||||||
 | 
					        protected override void Up(MigrationBuilder migrationBuilder)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            migrationBuilder.CreateTable(
 | 
				
			||||||
 | 
					                name: "badges",
 | 
				
			||||||
 | 
					                columns: table => new
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    id = table.Column<Guid>(type: "uuid", nullable: false),
 | 
				
			||||||
 | 
					                    type = table.Column<string>(type: "character varying(1024)", maxLength: 1024, nullable: false),
 | 
				
			||||||
 | 
					                    label = table.Column<string>(type: "character varying(1024)", maxLength: 1024, nullable: true),
 | 
				
			||||||
 | 
					                    caption = table.Column<string>(type: "character varying(4096)", maxLength: 4096, nullable: true),
 | 
				
			||||||
 | 
					                    meta = table.Column<Dictionary<string, object>>(type: "jsonb", nullable: false),
 | 
				
			||||||
 | 
					                    expired_at = table.Column<Instant>(type: "timestamp with time zone", nullable: true),
 | 
				
			||||||
 | 
					                    account_id = table.Column<long>(type: "bigint", nullable: false),
 | 
				
			||||||
 | 
					                    created_at = table.Column<Instant>(type: "timestamp with time zone", nullable: false),
 | 
				
			||||||
 | 
					                    updated_at = table.Column<Instant>(type: "timestamp with time zone", nullable: false),
 | 
				
			||||||
 | 
					                    deleted_at = table.Column<Instant>(type: "timestamp with time zone", nullable: true)
 | 
				
			||||||
 | 
					                },
 | 
				
			||||||
 | 
					                constraints: table =>
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    table.PrimaryKey("pk_badges", x => x.id);
 | 
				
			||||||
 | 
					                    table.ForeignKey(
 | 
				
			||||||
 | 
					                        name: "fk_badges_accounts_account_id",
 | 
				
			||||||
 | 
					                        column: x => x.account_id,
 | 
				
			||||||
 | 
					                        principalTable: "accounts",
 | 
				
			||||||
 | 
					                        principalColumn: "id",
 | 
				
			||||||
 | 
					                        onDelete: ReferentialAction.Cascade);
 | 
				
			||||||
 | 
					                });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            migrationBuilder.CreateIndex(
 | 
				
			||||||
 | 
					                name: "ix_badges_account_id",
 | 
				
			||||||
 | 
					                table: "badges",
 | 
				
			||||||
 | 
					                column: "account_id");
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /// <inheritdoc />
 | 
				
			||||||
 | 
					        protected override void Down(MigrationBuilder migrationBuilder)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            migrationBuilder.DropTable(
 | 
				
			||||||
 | 
					                name: "badges");
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -174,6 +174,63 @@ namespace DysonNetwork.Sphere.Migrations
 | 
				
			|||||||
                    b.ToTable("account_contacts", (string)null);
 | 
					                    b.ToTable("account_contacts", (string)null);
 | 
				
			||||||
                });
 | 
					                });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            modelBuilder.Entity("DysonNetwork.Sphere.Account.Badge", b =>
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    b.Property<Guid>("Id")
 | 
				
			||||||
 | 
					                        .ValueGeneratedOnAdd()
 | 
				
			||||||
 | 
					                        .HasColumnType("uuid")
 | 
				
			||||||
 | 
					                        .HasColumnName("id");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    b.Property<long>("AccountId")
 | 
				
			||||||
 | 
					                        .HasColumnType("bigint")
 | 
				
			||||||
 | 
					                        .HasColumnName("account_id");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    b.Property<string>("Caption")
 | 
				
			||||||
 | 
					                        .HasMaxLength(4096)
 | 
				
			||||||
 | 
					                        .HasColumnType("character varying(4096)")
 | 
				
			||||||
 | 
					                        .HasColumnName("caption");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    b.Property<Instant>("CreatedAt")
 | 
				
			||||||
 | 
					                        .HasColumnType("timestamp with time zone")
 | 
				
			||||||
 | 
					                        .HasColumnName("created_at");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    b.Property<Instant?>("DeletedAt")
 | 
				
			||||||
 | 
					                        .HasColumnType("timestamp with time zone")
 | 
				
			||||||
 | 
					                        .HasColumnName("deleted_at");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    b.Property<Instant?>("ExpiredAt")
 | 
				
			||||||
 | 
					                        .HasColumnType("timestamp with time zone")
 | 
				
			||||||
 | 
					                        .HasColumnName("expired_at");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    b.Property<string>("Label")
 | 
				
			||||||
 | 
					                        .HasMaxLength(1024)
 | 
				
			||||||
 | 
					                        .HasColumnType("character varying(1024)")
 | 
				
			||||||
 | 
					                        .HasColumnName("label");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    b.Property<Dictionary<string, object>>("Meta")
 | 
				
			||||||
 | 
					                        .IsRequired()
 | 
				
			||||||
 | 
					                        .HasColumnType("jsonb")
 | 
				
			||||||
 | 
					                        .HasColumnName("meta");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    b.Property<string>("Type")
 | 
				
			||||||
 | 
					                        .IsRequired()
 | 
				
			||||||
 | 
					                        .HasMaxLength(1024)
 | 
				
			||||||
 | 
					                        .HasColumnType("character varying(1024)")
 | 
				
			||||||
 | 
					                        .HasColumnName("type");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    b.Property<Instant>("UpdatedAt")
 | 
				
			||||||
 | 
					                        .HasColumnType("timestamp with time zone")
 | 
				
			||||||
 | 
					                        .HasColumnName("updated_at");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    b.HasKey("Id")
 | 
				
			||||||
 | 
					                        .HasName("pk_badges");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    b.HasIndex("AccountId")
 | 
				
			||||||
 | 
					                        .HasDatabaseName("ix_badges_account_id");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    b.ToTable("badges", (string)null);
 | 
				
			||||||
 | 
					                });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            modelBuilder.Entity("DysonNetwork.Sphere.Account.CheckInResult", b =>
 | 
					            modelBuilder.Entity("DysonNetwork.Sphere.Account.CheckInResult", b =>
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    b.Property<Guid>("Id")
 | 
					                    b.Property<Guid>("Id")
 | 
				
			||||||
@@ -2094,6 +2151,18 @@ namespace DysonNetwork.Sphere.Migrations
 | 
				
			|||||||
                    b.Navigation("Account");
 | 
					                    b.Navigation("Account");
 | 
				
			||||||
                });
 | 
					                });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            modelBuilder.Entity("DysonNetwork.Sphere.Account.Badge", b =>
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    b.HasOne("DysonNetwork.Sphere.Account.Account", "Account")
 | 
				
			||||||
 | 
					                        .WithMany("Badges")
 | 
				
			||||||
 | 
					                        .HasForeignKey("AccountId")
 | 
				
			||||||
 | 
					                        .OnDelete(DeleteBehavior.Cascade)
 | 
				
			||||||
 | 
					                        .IsRequired()
 | 
				
			||||||
 | 
					                        .HasConstraintName("fk_badges_accounts_account_id");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    b.Navigation("Account");
 | 
				
			||||||
 | 
					                });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            modelBuilder.Entity("DysonNetwork.Sphere.Account.CheckInResult", b =>
 | 
					            modelBuilder.Entity("DysonNetwork.Sphere.Account.CheckInResult", b =>
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    b.HasOne("DysonNetwork.Sphere.Account.Account", "Account")
 | 
					                    b.HasOne("DysonNetwork.Sphere.Account.Account", "Account")
 | 
				
			||||||
@@ -2709,6 +2778,8 @@ namespace DysonNetwork.Sphere.Migrations
 | 
				
			|||||||
                {
 | 
					                {
 | 
				
			||||||
                    b.Navigation("AuthFactors");
 | 
					                    b.Navigation("AuthFactors");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    b.Navigation("Badges");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    b.Navigation("Challenges");
 | 
					                    b.Navigation("Challenges");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    b.Navigation("Contacts");
 | 
					                    b.Navigation("Contacts");
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user