3 Commits
8 changed files with 100 additions and 15 deletions
+5 -1
View File
@@ -7,5 +7,9 @@ public class PersonCreateDto {
/// <summary>
/// Gets or sets the name of the person.
/// </summary>
public required string Name {get; set;}
public required string Name { get; set; }
/// <summary>
/// Gets or sets the asset ID to use as the profile picture.
/// </summary>
public Guid? ProfileAssetId { get; set; }
}
+17 -7
View File
@@ -1,23 +1,33 @@
using Butter.Dtos.Album;
namespace Butter.Dtos.Person;
/// <summary>
/// Represents the full details of a person, including associated assets and albums.
/// Represents the full details of a person, including associated albums.
/// </summary>
public class PersonDetailedDto {
/// <summary>
/// Gets or sets the unique identifier of the person.
/// </summary>
public required Guid Id { get; set; }
public required Guid Id { get; set; }
/// <summary>
/// Gets or sets the name of the person.
/// </summary>
public required string Name { get; set; }
public required string Name { get; set; }
/// <summary>
/// Gets or sets the list of asset IDs associated with this person.
/// Gets or sets the asset ID used as the profile picture.
/// </summary>
public List<Guid>? Assets { get; set; }
public Guid? ProfileAssetId { get; set; }
/// <summary>
/// Gets or sets the list of album IDs associated with this person.
/// Gets or sets the total number of non-deleted albums.
/// </summary>
public List<Guid>? Albums { get; set; }
public int TotalAlbums { get; set; }
/// <summary>
/// Gets or sets the total number of non-deleted assets across all albums.
/// </summary>
public int TotalAssets { get; set; }
/// <summary>
/// Gets or sets the list of album previews associated with this person.
/// </summary>
public List<AlbumPreviewDto>? Albums { get; set; }
}
+6 -2
View File
@@ -7,9 +7,13 @@ public class PersonPreviewDto {
/// <summary>
/// Gets or sets the unique identifier of the person.
/// </summary>
public required Guid Id { get; set; }
public required Guid Id { get; set; }
/// <summary>
/// Gets or sets the name of the person.
/// </summary>
public required string Name { get; set; }
public required string Name { get; set; }
/// <summary>
/// Gets or sets the asset ID used as the profile picture.
/// </summary>
public Guid? ProfileAssetId { get; set; }
}
+5 -2
View File
@@ -7,6 +7,9 @@ public class PersonUpdateDto {
/// <summary>
/// Gets or sets the name of the person.
/// </summary>
public required string Name { get; set; }
//TODO: add the missing properties here
public required string Name { get; set; }
/// <summary>
/// Gets or sets the asset ID to use as the profile picture.
/// </summary>
public Guid? ProfileAssetId { get; set; }
}
+1
View File
@@ -68,6 +68,7 @@ public class LactoseDbContext : DbContext {
modelBuilder.Entity<Face>().HasOne(e => e.Asset).WithMany(e => e.Faces);
modelBuilder.Entity<Face>().HasOne(e => e.Person).WithMany(e => e.Faces);
//Person Relationships
modelBuilder.Entity<Person>().HasOne(e => e.ProfileAsset).WithMany().HasForeignKey(e => e.ProfileAssetId);
modelBuilder.Entity<Person>().HasMany(e => e.Faces).WithOne(e => e.Person);
modelBuilder.Entity<Person>().HasMany(e => e.Albums).WithOne(e => e.PersonOwner);
//Tag Relationships
@@ -0,0 +1,49 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Lactose.Migrations
{
/// <inheritdoc />
public partial class AddPersonProfileAsset : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<Guid>(
name: "ProfileAssetId",
table: "People",
type: "uuid",
nullable: true);
migrationBuilder.CreateIndex(
name: "IX_People_ProfileAssetId",
table: "People",
column: "ProfileAssetId");
migrationBuilder.AddForeignKey(
name: "FK_People_Assets_ProfileAssetId",
table: "People",
column: "ProfileAssetId",
principalTable: "Assets",
principalColumn: "Id");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_People_Assets_ProfileAssetId",
table: "People");
migrationBuilder.DropIndex(
name: "IX_People_ProfileAssetId",
table: "People");
migrationBuilder.DropColumn(
name: "ProfileAssetId",
table: "People");
}
}
}
+10
View File
@@ -35,8 +35,18 @@ public class Person {
/// </summary>
public DateTime? DeletedAt { get; set; }
/// <summary>
/// Gets or sets the asset ID used as the profile picture for this person.
/// </summary>
public Guid? ProfileAssetId { get; set; }
#region Navigation Properties
/// <summary>
/// Gets or sets the profile picture asset.
/// </summary>
public Asset? ProfileAsset { get; set; }
/// <summary>
/// Gets or sets the list of faces associated with the person.
/// </summary>
+6 -2
View File
@@ -1,5 +1,6 @@
using Lactose.Context;
using Lactose.Models;
using Microsoft.EntityFrameworkCore;
namespace Lactose.Repositories;
@@ -12,11 +13,14 @@ public class PersonRepository(LactoseDbContext context) : IPersonRepository {
public void Save() => context.SaveChanges();
/// <inheritdoc />
public Person? Find(Guid id) => context.People.Find(id);
public Person? Find(Guid id) => context.People
.Include(p => p.ProfileAsset)
.Include(p => p.Albums)!.ThenInclude(a => a.CoverAsset)
.FirstOrDefault(p => p.Id == id && p.DeletedAt == null);
/// <inheritdoc />
public IEnumerable<Person> GetAll() =>
context.People.Where(p => p.DeletedAt == null);
context.People.Where(p => p.DeletedAt == null).Include(p => p.Albums);
/// <inheritdoc />
public Person? FindByName(string name) =>