diff --git a/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/Management/LibraryEntity.cs b/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/Management/LibraryEntity.cs
index e498b836..9c9bf2e3 100644
--- a/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/Management/LibraryEntity.cs
+++ b/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/Management/LibraryEntity.cs
@@ -13,7 +13,7 @@ namespace Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
/// Repository entity for a media library.
///
[DebuggerDisplay("Title: {Title}")]
-public class LibraryEntity : IStorageEntity
+public class LibraryEntity : IStorageEntity, IAuditableEntity
{
///
/// Gets the Id of the media library.
@@ -48,10 +48,20 @@ public class LibraryEntity : IStorageEntity
///
/// Gets or sets the time and date when the entity was added.
///
- public required DateTime Created { get; set; }
+ public required DateTime CreatedOnUtc { get; set; }
+
+ ///
+ /// Gets or sets the Id of the user that created the entity.
+ ///
+ public required Guid CreatedBy { get; set; }
///
/// Gets or sets the optional time and date when the entity was updated.
///
- public DateTime? Updated { get; set; }
+ public DateTime? UpdatedOnUtc { get; set; }
+
+ ///
+ /// Gets or sets the optional Id of the user that updated the entity.
+ ///
+ public required Guid? UpdatedBy { get; set; }
}
diff --git a/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/WrittenContentLibrary/BookLibrary/BookEntity.cs b/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/WrittenContentLibrary/BookLibrary/BookEntity.cs
index 8073dd34..101bf831 100644
--- a/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/WrittenContentLibrary/BookLibrary/BookEntity.cs
+++ b/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/WrittenContentLibrary/BookLibrary/BookEntity.cs
@@ -12,7 +12,7 @@ namespace Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenCont
/// Repository entity for a book.
///
[DebuggerDisplay("Title: {Title}")]
-public class BookEntity : IStorageEntity
+public class BookEntity : IStorageEntity, IAuditableEntity
{
///
/// Gets the Id of the media item.
@@ -198,10 +198,20 @@ public class BookEntity : IStorageEntity
///
/// Gets or sets the time and date when the entity was added.
///
- public required DateTime Created { get; set; }
+ public required DateTime CreatedOnUtc { get; set; }
+
+ ///
+ /// Gets or sets the Id of the user that created the entity.
+ ///
+ public required Guid CreatedBy { get; set; }
///
/// Gets or sets the optional time and date when the entity was updated.
///
- public DateTime? Updated { get; set; }
+ public DateTime? UpdatedOnUtc { get; set; }
+
+ ///
+ /// Gets or sets the optional Id of the user that updated the entity.
+ ///
+ public required Guid? UpdatedBy { get; set; }
}
diff --git a/src/Lumina.Application/Common/Mapping/MediaLibrary/Management/LibraryEntityMapping.cs b/src/Lumina.Application/Common/Mapping/MediaLibrary/Management/LibraryEntityMapping.cs
index 36e0d70d..89e9ae60 100644
--- a/src/Lumina.Application/Common/Mapping/MediaLibrary/Management/LibraryEntityMapping.cs
+++ b/src/Lumina.Application/Common/Mapping/MediaLibrary/Management/LibraryEntityMapping.cs
@@ -24,8 +24,8 @@ public static class LibraryEntityMapping
repositoryEntity.Title,
repositoryEntity.LibraryType,
repositoryEntity.ContentLocations.Select(location => location.Path).ToList(),
- repositoryEntity.Created,
- repositoryEntity.Updated
+ repositoryEntity.CreatedOnUtc,
+ repositoryEntity.UpdatedOnUtc
);
}
}
diff --git a/src/Lumina.Application/Common/Mapping/MediaLibrary/Management/LibraryMapping.cs b/src/Lumina.Application/Common/Mapping/MediaLibrary/Management/LibraryMapping.cs
index 4cd847a7..47fcf587 100644
--- a/src/Lumina.Application/Common/Mapping/MediaLibrary/Management/LibraryMapping.cs
+++ b/src/Lumina.Application/Common/Mapping/MediaLibrary/Management/LibraryMapping.cs
@@ -1,6 +1,7 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate;
+using System;
using System.Linq;
#endregion
@@ -25,8 +26,10 @@ public static class LibraryMapping
LibraryType = domainEntity.LibraryType,
UserId = domainEntity.UserId.Value,
ContentLocations = domainEntity.ContentLocations.Select(path => new LibraryContentLocationEntity() { Path = path.Path }).ToList(),
- Created = domainEntity.Created,
- Updated = domainEntity.Updated.HasValue ? domainEntity.Updated : null
+ CreatedOnUtc = domainEntity.CreatedOnUtc,
+ CreatedBy = Guid.Empty,
+ UpdatedOnUtc = domainEntity.UpdatedOnUtc.HasValue ? domainEntity.UpdatedOnUtc : null,
+ UpdatedBy = Guid.Empty
};
}
}
diff --git a/src/Lumina.Application/Common/Mapping/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/BookEntityMapping.cs b/src/Lumina.Application/Common/Mapping/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/BookEntityMapping.cs
index 5d543790..a1635e1a 100644
--- a/src/Lumina.Application/Common/Mapping/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/BookEntityMapping.cs
+++ b/src/Lumina.Application/Common/Mapping/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/BookEntityMapping.cs
@@ -124,8 +124,8 @@ public static class BookEntityMapping
Optional.FromNullable(repositoryEntity.GoogleBooksId),
Optional.FromNullable(repositoryEntity.BarnesAndNobleId),
Optional.FromNullable(repositoryEntity.AppleBooksId),
- repositoryEntity.Created,
- Optional.FromNullable(repositoryEntity.Updated),
+ repositoryEntity.CreatedOnUtc,
+ Optional.FromNullable(repositoryEntity.UpdatedOnUtc),
isbnsResult.Select(isbn => isbn.Value).ToList(),
[],
bookRatingsResult.Select(bookRating => bookRating.Value).ToList());
@@ -207,8 +207,8 @@ public static class BookEntityMapping
[.. repositoryEntity.ISBNs.ToResponses()],
null,
[.. repositoryEntity.Ratings.ToResponses()],
- repositoryEntity.Created,
- repositoryEntity.Updated
+ repositoryEntity.CreatedOnUtc,
+ repositoryEntity.UpdatedOnUtc
);
}
diff --git a/src/Lumina.Application/Common/Mapping/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/BookMapping.cs b/src/Lumina.Application/Common/Mapping/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/BookMapping.cs
index 52f4e4a5..04b10163 100644
--- a/src/Lumina.Application/Common/Mapping/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/BookMapping.cs
+++ b/src/Lumina.Application/Common/Mapping/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/BookMapping.cs
@@ -3,6 +3,7 @@ using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentL
using Lumina.Application.Common.Mapping.Common.Metadata;
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate;
+using System;
using System.Linq;
#endregion
@@ -56,8 +57,10 @@ public static class BookMapping
AppleBooksId = domainEntity.AppleBooksId.HasValue ? domainEntity.AppleBooksId.Value : null,
ISBNs = domainEntity.ISBNs.ToRepositoryEntities().ToList(),
Ratings = domainEntity.Ratings.ToRepositoryEntities().ToList(),
- Created = domainEntity.Created,
- Updated = domainEntity.Updated.HasValue ? domainEntity.Updated : null
+ CreatedOnUtc = domainEntity.CreatedOnUtc,
+ CreatedBy = Guid.NewGuid(),
+ UpdatedOnUtc = domainEntity.UpdatedOnUtc.HasValue ? domainEntity.UpdatedOnUtc : null,
+ UpdatedBy = domainEntity.UpdatedOnUtc.HasValue ? Guid.NewGuid() : null,
};
}
}
diff --git a/src/Lumina.Application/Core/UsersManagement/Authorization/Commands/UpdateUserRoleAndPermissions/UpdateUserRoleAndPermissionsCommandValidator.cs b/src/Lumina.Application/Core/UsersManagement/Authorization/Commands/UpdateUserRoleAndPermissions/UpdateUserRoleAndPermissionsCommandValidator.cs
index d3c2625d..6cd7fffc 100644
--- a/src/Lumina.Application/Core/UsersManagement/Authorization/Commands/UpdateUserRoleAndPermissions/UpdateUserRoleAndPermissionsCommandValidator.cs
+++ b/src/Lumina.Application/Core/UsersManagement/Authorization/Commands/UpdateUserRoleAndPermissions/UpdateUserRoleAndPermissionsCommandValidator.cs
@@ -1,7 +1,6 @@
#region ========================================================================= USING =====================================================================================
using FluentValidation;
using System;
-using System.Linq;
using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
using DomainErrors = Lumina.Domain.Common.Errors.Errors;
#endregion
diff --git a/src/Lumina.Contracts/Responses/MediaLibrary/Management/LibraryResponse.cs b/src/Lumina.Contracts/Responses/MediaLibrary/Management/LibraryResponse.cs
index fc858b28..b6e32eb9 100644
--- a/src/Lumina.Contracts/Responses/MediaLibrary/Management/LibraryResponse.cs
+++ b/src/Lumina.Contracts/Responses/MediaLibrary/Management/LibraryResponse.cs
@@ -15,8 +15,8 @@ namespace Lumina.Contracts.Responses.MediaLibrary.Management;
/// The title of the media library.
/// The type of the media library.
/// The file system paths of the directories where the media library elements are located.
-/// The date and time when the library was created.
-/// The optional date and time when the library was updated.
+/// The date and time when the library was created.
+/// The optional date and time when the library was updated.
[DebuggerDisplay("Title: {Title}")]
public record LibraryResponse(
Guid Id,
@@ -24,6 +24,6 @@ public record LibraryResponse(
string Title,
LibraryType LibraryType,
List ContentLocations,
- DateTime Created,
- DateTime? Updated
+ DateTime CreatedOnUtc,
+ DateTime? UpdatedOnUtc
);
diff --git a/src/Lumina.Contracts/Responses/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/BookResponse.cs b/src/Lumina.Contracts/Responses/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/BookResponse.cs
index a202bebd..0a67e27e 100644
--- a/src/Lumina.Contracts/Responses/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/BookResponse.cs
+++ b/src/Lumina.Contracts/Responses/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/BookResponse.cs
@@ -31,8 +31,8 @@ namespace Lumina.Contracts.Responses.MediaLibrary.WrittenContentLibrary.BookLibr
/// The list of ISBN (International Standard Book Number) of the book.
/// The list of media contributors (actors, directors, etc) starring in this book.
/// The list of ratings for this book.
-/// The date and time when the book was created.
-/// The optional date and time when the book was updated.
+/// The date and time when the book was created.
+/// The optional date and time when the book was updated.
[DebuggerDisplay("Title: {Metadata.Title}")]
public record BookResponse(
Guid Id,
@@ -53,6 +53,6 @@ public record BookResponse(
List? ISBNs,
List? Contributors,
List? Ratings,
- DateTime Created,
- DateTime? Updated
+ DateTime CreatedOnUtc,
+ DateTime? UpdatedOnUtc
);
diff --git a/src/Lumina.Contracts/Responses/UsersManagement/Users/UserResponse.cs b/src/Lumina.Contracts/Responses/UsersManagement/Users/UserResponse.cs
index 50bb8461..c8ac4a94 100644
--- a/src/Lumina.Contracts/Responses/UsersManagement/Users/UserResponse.cs
+++ b/src/Lumina.Contracts/Responses/UsersManagement/Users/UserResponse.cs
@@ -10,12 +10,12 @@ namespace Lumina.Contracts.Responses.UsersManagement.Users;
///
/// The id of the user.
/// The username of the user.
-/// The date and time when the user was created.
-/// The optional date and time when the user was updated.
+/// The date and time when the user was created.
+/// The optional date and time when the user was updated.
[DebuggerDisplay("Username: {Username}")]
public record UserResponse(
Guid Id,
string Username,
- DateTime Created,
- DateTime? Updated
+ DateTime CreatedOnUtc,
+ DateTime? UpdatedOnUtc
);
diff --git a/src/Lumina.DataAccess/Common/Configuration/BookConfiguration.cs b/src/Lumina.DataAccess/Common/Configuration/BookConfiguration.cs
index f961dc52..e3b3e0fe 100644
--- a/src/Lumina.DataAccess/Common/Configuration/BookConfiguration.cs
+++ b/src/Lumina.DataAccess/Common/Configuration/BookConfiguration.cs
@@ -130,9 +130,9 @@ public class BookConfiguration : IEntityTypeConfiguration
.HasColumnOrder(28);
builder.Property(book => book.AppleBooksId)
.HasColumnOrder(29);
- builder.Property(book => book.Created)
+ builder.Property(book => book.CreatedOnUtc)
.HasColumnOrder(30);
- builder.Property(book => book.Updated)
+ builder.Property(book => book.UpdatedOnUtc)
.HasColumnOrder(31);
//builder.HasMany()
diff --git a/src/Lumina.DataAccess/Common/Migrations/20241227113945_ImplementsAuditColumns.Designer.cs b/src/Lumina.DataAccess/Common/Migrations/20241227113945_ImplementsAuditColumns.Designer.cs
new file mode 100644
index 00000000..fc58c832
--- /dev/null
+++ b/src/Lumina.DataAccess/Common/Migrations/20241227113945_ImplementsAuditColumns.Designer.cs
@@ -0,0 +1,709 @@
+//
+using System;
+using Lumina.DataAccess.Core.UoW;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+
+#nullable disable
+
+namespace Lumina.DataAccess.Common.Migrations
+{
+ [DbContext(typeof(LuminaDbContext))]
+ [Migration("20241227113945_ImplementsAuditColumns")]
+ partial class ImplementsAuditColumns
+ {
+ ///
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder.HasAnnotation("ProductVersion", "9.0.0");
+
+ modelBuilder.Entity("BookGenres", b =>
+ {
+ b.Property("BookId")
+ .HasColumnType("TEXT");
+
+ b.Property("GenreId")
+ .HasColumnType("TEXT");
+
+ b.HasKey("BookId", "GenreId");
+
+ b.HasIndex("GenreId");
+
+ b.ToTable("BookGenres", (string)null);
+ });
+
+ modelBuilder.Entity("BookTags", b =>
+ {
+ b.Property("BookId")
+ .HasColumnType("TEXT");
+
+ b.Property("TagId")
+ .HasColumnType("TEXT");
+
+ b.HasKey("BookId", "TagId");
+
+ b.HasIndex("TagId");
+
+ b.ToTable("BookTags", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.PermissionEntity", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("TEXT")
+ .HasColumnOrder(0);
+
+ b.Property("CreatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(4);
+
+ b.Property("CreatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(3);
+
+ b.Property("PermissionName")
+ .IsRequired()
+ .HasMaxLength(100)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(1);
+
+ b.Property("UpdatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(6);
+
+ b.Property("UpdatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(5);
+
+ b.HasKey("Id");
+
+ b.ToTable("Permissions", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.RoleEntity", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("TEXT")
+ .HasColumnOrder(0);
+
+ b.Property("CreatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(4);
+
+ b.Property("CreatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(3);
+
+ b.Property("RoleName")
+ .IsRequired()
+ .HasMaxLength(100)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(1);
+
+ b.Property("UpdatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(6);
+
+ b.Property("UpdatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(5);
+
+ b.HasKey("Id");
+
+ b.ToTable("Roles", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.RolePermissionEntity", b =>
+ {
+ b.Property("RoleId")
+ .HasColumnType("TEXT");
+
+ b.Property("PermissionId")
+ .HasColumnType("TEXT");
+
+ b.Property("CreatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(2);
+
+ b.Property("CreatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(1);
+
+ b.Property("UpdatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(4);
+
+ b.Property("UpdatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(3);
+
+ b.HasKey("RoleId", "PermissionId");
+
+ b.HasIndex("PermissionId");
+
+ b.HasIndex("RoleId", "PermissionId")
+ .IsUnique();
+
+ b.ToTable("RolePermissions", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.UserPermissionEntity", b =>
+ {
+ b.Property("UserId")
+ .HasColumnType("TEXT");
+
+ b.Property("PermissionId")
+ .HasColumnType("TEXT");
+
+ b.Property("CreatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(2);
+
+ b.Property("CreatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(1);
+
+ b.Property("UpdatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(4);
+
+ b.Property("UpdatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(3);
+
+ b.HasKey("UserId", "PermissionId");
+
+ b.HasIndex("PermissionId");
+
+ b.HasIndex("UserId", "PermissionId")
+ .IsUnique();
+
+ b.ToTable("UserPermissions", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.UserRoleEntity", b =>
+ {
+ b.Property("UserId")
+ .HasColumnType("TEXT");
+
+ b.Property("CreatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(2);
+
+ b.Property("CreatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(1);
+
+ b.Property("RoleId")
+ .HasColumnType("TEXT");
+
+ b.Property("UpdatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(4);
+
+ b.Property("UpdatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(3);
+
+ b.HasKey("UserId");
+
+ b.HasIndex("RoleId");
+
+ b.HasIndex("UserId", "RoleId")
+ .IsUnique();
+
+ b.ToTable("UserRoles", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Common.GenreEntity", b =>
+ {
+ b.Property("Name")
+ .HasMaxLength(50)
+ .HasColumnType("TEXT");
+
+ b.HasKey("Name");
+
+ b.ToTable("Genres", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Common.TagEntity", b =>
+ {
+ b.Property("Name")
+ .HasMaxLength(50)
+ .HasColumnType("TEXT");
+
+ b.HasKey("Name");
+
+ b.ToTable("Tags", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryEntity", b =>
+ {
+ b.Property("Id")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(0);
+
+ b.Property("CreatedBy")
+ .HasColumnType("TEXT");
+
+ b.Property("CreatedOnUtc")
+ .HasColumnType("TEXT");
+
+ b.Property("LibraryType")
+ .IsRequired()
+ .HasColumnType("TEXT")
+ .HasColumnOrder(2);
+
+ b.Property("Title")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(1);
+
+ b.Property("UpdatedBy")
+ .HasColumnType("TEXT");
+
+ b.Property("UpdatedOnUtc")
+ .HasColumnType("TEXT");
+
+ b.Property("UserId")
+ .HasColumnType("TEXT");
+
+ b.HasKey("Id");
+
+ b.HasIndex("UserId");
+
+ b.ToTable("Libraries", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookEntity", b =>
+ {
+ b.Property("Id")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(0);
+
+ b.Property("ASIN")
+ .HasMaxLength(10)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(21);
+
+ b.Property("AppleBooksId")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(29);
+
+ b.Property("BarnesAndNobleId")
+ .HasMaxLength(10)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(28);
+
+ b.Property("CreatedBy")
+ .HasColumnType("TEXT");
+
+ b.Property("CreatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(30);
+
+ b.Property("Description")
+ .HasMaxLength(2000)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(3);
+
+ b.Property("Edition")
+ .HasMaxLength(50)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(19);
+
+ b.Property("Format")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(18);
+
+ b.Property("GoodreadsId")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(22);
+
+ b.Property("GoogleBooksId")
+ .HasMaxLength(12)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(27);
+
+ b.Property("LCCN")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(23);
+
+ b.Property("LanguageCode")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(10);
+
+ b.Property("LanguageName")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(11);
+
+ b.Property("LanguageNativeName")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(12);
+
+ b.Property("LibraryThingId")
+ .HasMaxLength(50)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(26);
+
+ b.Property("OCLCNumber")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(24);
+
+ b.Property("OpenLibraryId")
+ .HasMaxLength(50)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(25);
+
+ b.Property("OriginalLanguageCode")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(13);
+
+ b.Property("OriginalLanguageName")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(14);
+
+ b.Property("OriginalLanguageNativeName")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(15);
+
+ b.Property("OriginalReleaseDate")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(4);
+
+ b.Property("OriginalReleaseYear")
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(5);
+
+ b.Property("OriginalTitle")
+ .HasMaxLength(255)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(2);
+
+ b.Property("PageCount")
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(17);
+
+ b.Property("Publisher")
+ .HasMaxLength(100)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(16);
+
+ b.Property("ReReleaseDate")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(6);
+
+ b.Property("ReReleaseYear")
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(7);
+
+ b.Property("ReleaseCountry")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(8);
+
+ b.Property("ReleaseVersion")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(9);
+
+ b.Property("Title")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(1);
+
+ b.Property("UpdatedBy")
+ .HasColumnType("TEXT");
+
+ b.Property("UpdatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(31);
+
+ b.Property("VolumeNumber")
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(20);
+
+ b.HasKey("Id");
+
+ b.ToTable("Books", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.UsersManagement.UserEntity", b =>
+ {
+ b.Property("Id")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(0);
+
+ b.Property("CreatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(7);
+
+ b.Property("CreatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(6);
+
+ b.Property("Password")
+ .IsRequired()
+ .HasColumnType("TEXT")
+ .HasColumnOrder(2);
+
+ b.Property("TempPassword")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(3);
+
+ b.Property("TempPasswordCreated")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(5);
+
+ b.Property("TotpSecret")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(4);
+
+ b.Property("UpdatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(9);
+
+ b.Property("UpdatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(8);
+
+ b.Property("Username")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(1);
+
+ b.HasKey("Id");
+
+ b.HasIndex("Username")
+ .IsUnique();
+
+ b.ToTable("Users", (string)null);
+ });
+
+ modelBuilder.Entity("BookGenres", b =>
+ {
+ b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookEntity", null)
+ .WithMany()
+ .HasForeignKey("BookId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("Lumina.Application.Common.DataAccess.Entities.Common.GenreEntity", null)
+ .WithMany()
+ .HasForeignKey("GenreId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+ });
+
+ modelBuilder.Entity("BookTags", b =>
+ {
+ b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookEntity", null)
+ .WithMany()
+ .HasForeignKey("BookId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("Lumina.Application.Common.DataAccess.Entities.Common.TagEntity", null)
+ .WithMany()
+ .HasForeignKey("TagId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.RolePermissionEntity", b =>
+ {
+ b.HasOne("Lumina.Application.Common.DataAccess.Entities.Authorization.PermissionEntity", "Permission")
+ .WithMany("RolePermissions")
+ .HasForeignKey("PermissionId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("Lumina.Application.Common.DataAccess.Entities.Authorization.RoleEntity", "Role")
+ .WithMany("RolePermissions")
+ .HasForeignKey("RoleId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Permission");
+
+ b.Navigation("Role");
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.UserPermissionEntity", b =>
+ {
+ b.HasOne("Lumina.Application.Common.DataAccess.Entities.Authorization.PermissionEntity", "Permission")
+ .WithMany("UserPermissions")
+ .HasForeignKey("PermissionId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("Lumina.Application.Common.DataAccess.Entities.UsersManagement.UserEntity", "User")
+ .WithMany("UserPermissions")
+ .HasForeignKey("UserId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Permission");
+
+ b.Navigation("User");
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.UserRoleEntity", b =>
+ {
+ b.HasOne("Lumina.Application.Common.DataAccess.Entities.Authorization.RoleEntity", "Role")
+ .WithMany("UserRoles")
+ .HasForeignKey("RoleId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("Lumina.Application.Common.DataAccess.Entities.UsersManagement.UserEntity", "User")
+ .WithOne("UserRole")
+ .HasForeignKey("Lumina.Application.Common.DataAccess.Entities.Authorization.UserRoleEntity", "UserId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Role");
+
+ b.Navigation("User");
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryEntity", b =>
+ {
+ b.HasOne("Lumina.Application.Common.DataAccess.Entities.UsersManagement.UserEntity", "User")
+ .WithMany("Libraries")
+ .HasForeignKey("UserId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryContentLocationEntity", "ContentLocations", b1 =>
+ {
+ b1.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("TEXT");
+
+ b1.Property("LibraryId")
+ .HasColumnType("TEXT");
+
+ b1.Property("Path")
+ .IsRequired()
+ .HasMaxLength(260)
+ .HasColumnType("TEXT")
+ .HasColumnName("Path");
+
+ b1.HasKey("Id");
+
+ b1.HasIndex("LibraryId");
+
+ b1.ToTable("LibraryContentLocations", (string)null);
+
+ b1.WithOwner()
+ .HasForeignKey("LibraryId");
+ });
+
+ b.Navigation("ContentLocations");
+
+ b.Navigation("User");
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookEntity", b =>
+ {
+ b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookRatingEntity", "Ratings", b1 =>
+ {
+ b1.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("TEXT");
+
+ b1.Property("BookId")
+ .HasColumnType("TEXT");
+
+ b1.Property("MaxValue")
+ .HasColumnType("decimal(3,2)");
+
+ b1.Property("Source")
+ .IsRequired()
+ .HasMaxLength(50)
+ .HasColumnType("TEXT");
+
+ b1.Property("Value")
+ .HasColumnType("decimal(3,2)");
+
+ b1.Property("VoteCount")
+ .HasColumnType("INTEGER");
+
+ b1.HasKey("Id");
+
+ b1.HasIndex("BookId");
+
+ b1.ToTable("BookRatings", (string)null);
+
+ b1.WithOwner()
+ .HasForeignKey("BookId");
+ });
+
+ b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.IsbnEntity", "ISBNs", b1 =>
+ {
+ b1.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("TEXT");
+
+ b1.Property("BookId")
+ .HasColumnType("TEXT");
+
+ b1.Property("Format")
+ .IsRequired()
+ .HasMaxLength(6)
+ .HasColumnType("TEXT");
+
+ b1.Property("Value")
+ .IsRequired()
+ .HasMaxLength(13)
+ .HasColumnType("TEXT")
+ .HasColumnName("ISBN");
+
+ b1.HasKey("Id");
+
+ b1.HasIndex("BookId");
+
+ b1.ToTable("BookISBNs", (string)null);
+
+ b1.WithOwner()
+ .HasForeignKey("BookId");
+ });
+
+ b.Navigation("ISBNs");
+
+ b.Navigation("Ratings");
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.PermissionEntity", b =>
+ {
+ b.Navigation("RolePermissions");
+
+ b.Navigation("UserPermissions");
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.RoleEntity", b =>
+ {
+ b.Navigation("RolePermissions");
+
+ b.Navigation("UserRoles");
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.UsersManagement.UserEntity", b =>
+ {
+ b.Navigation("Libraries");
+
+ b.Navigation("UserPermissions");
+
+ b.Navigation("UserRole");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/src/Lumina.DataAccess/Common/Migrations/20241227113945_ImplementsAuditColumns.cs b/src/Lumina.DataAccess/Common/Migrations/20241227113945_ImplementsAuditColumns.cs
new file mode 100644
index 00000000..54b06b77
--- /dev/null
+++ b/src/Lumina.DataAccess/Common/Migrations/20241227113945_ImplementsAuditColumns.cs
@@ -0,0 +1,100 @@
+using System;
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+namespace Lumina.DataAccess.Common.Migrations;
+
+///
+public partial class ImplementsAuditColumns : Migration
+{
+ ///
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.RenameColumn(
+ name: "Updated",
+ table: "Libraries",
+ newName: "UpdatedOnUtc");
+
+ migrationBuilder.RenameColumn(
+ name: "Created",
+ table: "Libraries",
+ newName: "CreatedOnUtc");
+
+ migrationBuilder.RenameColumn(
+ name: "Updated",
+ table: "Books",
+ newName: "UpdatedOnUtc");
+
+ migrationBuilder.RenameColumn(
+ name: "Created",
+ table: "Books",
+ newName: "CreatedOnUtc");
+
+ migrationBuilder.AddColumn(
+ name: "CreatedBy",
+ table: "Libraries",
+ type: "TEXT",
+ nullable: false,
+ defaultValue: new Guid("00000000-0000-0000-0000-000000000000"));
+
+ migrationBuilder.AddColumn(
+ name: "UpdatedBy",
+ table: "Libraries",
+ type: "TEXT",
+ nullable: true);
+
+ migrationBuilder.AddColumn(
+ name: "CreatedBy",
+ table: "Books",
+ type: "TEXT",
+ nullable: false,
+ defaultValue: new Guid("00000000-0000-0000-0000-000000000000"));
+
+ migrationBuilder.AddColumn(
+ name: "UpdatedBy",
+ table: "Books",
+ type: "TEXT",
+ nullable: true);
+ }
+
+ ///
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropColumn(
+ name: "CreatedBy",
+ table: "Libraries");
+
+ migrationBuilder.DropColumn(
+ name: "UpdatedBy",
+ table: "Libraries");
+
+ migrationBuilder.DropColumn(
+ name: "CreatedBy",
+ table: "Books");
+
+ migrationBuilder.DropColumn(
+ name: "UpdatedBy",
+ table: "Books");
+
+ migrationBuilder.RenameColumn(
+ name: "UpdatedOnUtc",
+ table: "Libraries",
+ newName: "Updated");
+
+ migrationBuilder.RenameColumn(
+ name: "CreatedOnUtc",
+ table: "Libraries",
+ newName: "Created");
+
+ migrationBuilder.RenameColumn(
+ name: "UpdatedOnUtc",
+ table: "Books",
+ newName: "Updated");
+
+ migrationBuilder.RenameColumn(
+ name: "CreatedOnUtc",
+ table: "Books",
+ newName: "Created");
+ }
+}
diff --git a/src/Lumina.DataAccess/Common/Migrations/LuminaDbContextModelSnapshot.cs b/src/Lumina.DataAccess/Common/Migrations/LuminaDbContextModelSnapshot.cs
index 06bfe597..322f9af8 100644
--- a/src/Lumina.DataAccess/Common/Migrations/LuminaDbContextModelSnapshot.cs
+++ b/src/Lumina.DataAccess/Common/Migrations/LuminaDbContextModelSnapshot.cs
@@ -245,7 +245,10 @@ namespace Lumina.DataAccess.Common.Migrations
.HasColumnType("TEXT")
.HasColumnOrder(0);
- b.Property("Created")
+ b.Property("CreatedBy")
+ .HasColumnType("TEXT");
+
+ b.Property("CreatedOnUtc")
.HasColumnType("TEXT");
b.Property("LibraryType")
@@ -259,7 +262,10 @@ namespace Lumina.DataAccess.Common.Migrations
.HasColumnType("TEXT")
.HasColumnOrder(1);
- b.Property("Updated")
+ b.Property("UpdatedBy")
+ .HasColumnType("TEXT");
+
+ b.Property("UpdatedOnUtc")
.HasColumnType("TEXT");
b.Property("UserId")
@@ -292,7 +298,10 @@ namespace Lumina.DataAccess.Common.Migrations
.HasColumnType("TEXT")
.HasColumnOrder(28);
- b.Property("Created")
+ b.Property("CreatedBy")
+ .HasColumnType("TEXT");
+
+ b.Property("CreatedOnUtc")
.HasColumnType("TEXT")
.HasColumnOrder(30);
@@ -405,7 +414,10 @@ namespace Lumina.DataAccess.Common.Migrations
.HasColumnType("TEXT")
.HasColumnOrder(1);
- b.Property("Updated")
+ b.Property("UpdatedBy")
+ .HasColumnType("TEXT");
+
+ b.Property("UpdatedOnUtc")
.HasColumnType("TEXT")
.HasColumnOrder(31);
@@ -686,8 +698,7 @@ namespace Lumina.DataAccess.Common.Migrations
b.Navigation("UserPermissions");
- b.Navigation("UserRole")
- .IsRequired();
+ b.Navigation("UserRole");
});
#pragma warning restore 612, 618
}
diff --git a/src/Lumina.DataAccess/Core/Repositories/Users/UserRepository.cs b/src/Lumina.DataAccess/Core/Repositories/Users/UserRepository.cs
index c59cd0c0..fb061eed 100644
--- a/src/Lumina.DataAccess/Core/Repositories/Users/UserRepository.cs
+++ b/src/Lumina.DataAccess/Core/Repositories/Users/UserRepository.cs
@@ -8,7 +8,6 @@ using Lumina.Domain.Common.Errors;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
-using System.Linq;
using System.Threading;
using System.Threading.Tasks;
#endregion
@@ -131,7 +130,6 @@ internal sealed class UserRepository : IUserRepository
return Result.Updated;
}
-
///
/// Gets a identified by from the storage medium.
///
diff --git a/src/Lumina.Domain/Common/Enums/BookLibrary/BookFormat.cs b/src/Lumina.Domain/Common/Enums/BookLibrary/BookFormat.cs
index 32c98f60..7e9c5695 100644
--- a/src/Lumina.Domain/Common/Enums/BookLibrary/BookFormat.cs
+++ b/src/Lumina.Domain/Common/Enums/BookLibrary/BookFormat.cs
@@ -64,4 +64,4 @@ public enum BookFormat
/// A book with three-dimensional paper engineering, creating pop-up or movable parts.
///
PopupBook
-}
\ No newline at end of file
+}
diff --git a/src/Lumina.Domain/Common/Enums/BookLibrary/BookRatingSource.cs b/src/Lumina.Domain/Common/Enums/BookLibrary/BookRatingSource.cs
index fa3e2bca..cb2ed472 100644
--- a/src/Lumina.Domain/Common/Enums/BookLibrary/BookRatingSource.cs
+++ b/src/Lumina.Domain/Common/Enums/BookLibrary/BookRatingSource.cs
@@ -24,4 +24,4 @@ public enum BookRatingSource
/// Ratings from Google Books, a service that searches the full text of books and magazines that Google has scanned and converted to text.
///
GoogleBooks,
-}
\ No newline at end of file
+}
diff --git a/src/Lumina.Domain/Common/Enums/BookLibrary/IsbnFormat.cs b/src/Lumina.Domain/Common/Enums/BookLibrary/IsbnFormat.cs
index b0d8e48e..acfe80a5 100644
--- a/src/Lumina.Domain/Common/Enums/BookLibrary/IsbnFormat.cs
+++ b/src/Lumina.Domain/Common/Enums/BookLibrary/IsbnFormat.cs
@@ -16,4 +16,4 @@ public enum IsbnFormat
/// Example: 978-0-306-40615-7
///
Isbn13
-}
\ No newline at end of file
+}
diff --git a/src/Lumina.Domain/Common/Models/Core/Entity.cs b/src/Lumina.Domain/Common/Models/Core/Entity.cs
index 3d02e721..06699926 100644
--- a/src/Lumina.Domain/Common/Models/Core/Entity.cs
+++ b/src/Lumina.Domain/Common/Models/Core/Entity.cs
@@ -18,12 +18,12 @@ public abstract class Entity : IEquatable> where TId : notnull
///
/// Gets the date and time when the entity was created.
///
- public DateTime Created { get; set; }
+ public DateTime CreatedOnUtc { get; set; }
///
/// Gets the date and time when the entity was last updated.
///
- public DateTime? Updated { get; set; }
+ public DateTime? UpdatedOnUtc { get; set; }
///
/// Initializes a new instance of the class.
diff --git a/src/Lumina.Domain/Core/BoundedContexts/WrittenContentLibraryBoundedContext/BookLibraryAggregate/Book.cs b/src/Lumina.Domain/Core/BoundedContexts/WrittenContentLibraryBoundedContext/BookLibraryAggregate/Book.cs
index 04ccd2b2..f4297158 100644
--- a/src/Lumina.Domain/Core/BoundedContexts/WrittenContentLibraryBoundedContext/BookLibraryAggregate/Book.cs
+++ b/src/Lumina.Domain/Core/BoundedContexts/WrittenContentLibraryBoundedContext/BookLibraryAggregate/Book.cs
@@ -126,8 +126,8 @@ public sealed class Book : AggregateRoot
/// The optional Google Books ID of the book.
/// The optional Barnes & Noble ID of the book.
/// The optional Apple Books ID of the book.
- /// The date and time when the entity was created.
- /// The date and time when the entity was last updated.
+ /// The date and time when the entity was created.
+ /// The date and time when the entity was last updated.
/// The list of ISBNs of the book.
/// The list of media contributors of the book.
/// The list of ratings for the book.
@@ -147,8 +147,8 @@ public sealed class Book : AggregateRoot
Optional googleBooksId,
Optional barnesAndNobleId,
Optional appleBooksId,
- DateTime created,
- Optional updated,
+ DateTime createdOnUtc,
+ Optional updatedOnUtc,
List isbns,
List contributors,
List ratings) : base(id)
@@ -168,8 +168,8 @@ public sealed class Book : AggregateRoot
GoogleBooksId = googleBooksId;
BarnesAndNobleId = barnesAndNobleId;
AppleBooksId = appleBooksId;
- Created = created;
- Updated = updated.HasValue ? updated.Value : null;
+ CreatedOnUtc = createdOnUtc;
+ UpdatedOnUtc = updatedOnUtc.HasValue ? updatedOnUtc.Value : null;
_isbns = isbns;
_contributors = contributors;
_ratings = ratings;
@@ -270,8 +270,8 @@ public sealed class Book : AggregateRoot
/// The optional Google Books ID of the book.
/// The optional Barnes & Noble ID of the book.
/// The optional Apple Books ID of the book.
- /// The date and time when the entity was created.
- /// The date and time when the entity was last updated.
+ /// The date and time when the entity was created.
+ /// The date and time when the entity was last updated.
/// The list of ISBNs of the book.
/// The list of media contributors of the book.
/// The list of ratings for the book.
@@ -294,8 +294,8 @@ public sealed class Book : AggregateRoot
Optional googleBooksId,
Optional barnesAndNobleId,
Optional appleBooksId,
- DateTime created,
- Optional updated,
+ DateTime createdOnUtc,
+ Optional updatedOnUtc,
List isbns,
List contributors,
List ratings)
@@ -317,8 +317,8 @@ public sealed class Book : AggregateRoot
googleBooksId,
barnesAndNobleId,
appleBooksId,
- created,
- updated,
+ createdOnUtc,
+ updatedOnUtc,
isbns,
contributors,
ratings
diff --git a/src/Lumina.Presentation.Api/Core/Endpoints/Admin/Authorization/Roles/DeleteRole/DeleteRoleEndpointSummary.cs b/src/Lumina.Presentation.Api/Core/Endpoints/Admin/Authorization/Roles/DeleteRole/DeleteRoleEndpointSummary.cs
index d19571a7..fd2583ee 100644
--- a/src/Lumina.Presentation.Api/Core/Endpoints/Admin/Authorization/Roles/DeleteRole/DeleteRoleEndpointSummary.cs
+++ b/src/Lumina.Presentation.Api/Core/Endpoints/Admin/Authorization/Roles/DeleteRole/DeleteRoleEndpointSummary.cs
@@ -41,7 +41,7 @@ public class DeleteRoleEndpointSummary : Summary
{
{
diff --git a/src/Lumina.Presentation.Api/Core/Endpoints/Admin/Authorization/Roles/GetRoles/GetRolesEndpointSummary.cs b/src/Lumina.Presentation.Api/Core/Endpoints/Admin/Authorization/Roles/GetRoles/GetRolesEndpointSummary.cs
index 1418737e..af86f5b0 100644
--- a/src/Lumina.Presentation.Api/Core/Endpoints/Admin/Authorization/Roles/GetRoles/GetRolesEndpointSummary.cs
+++ b/src/Lumina.Presentation.Api/Core/Endpoints/Admin/Authorization/Roles/GetRoles/GetRolesEndpointSummary.cs
@@ -11,12 +11,12 @@ namespace Lumina.Presentation.Api.Core.Endpoints.Admin.Authorization.Roles.GetRo
/// Class used for providing a textual description for the API endpoint, for OpenAPI.
///
[ExcludeFromCodeCoverage]
-public class GetPermissionsEndpointSummary : Summary
+public class GetRolesEndpointSummary : Summary
{
///
- /// Initializes a new instance of the class.
+ /// Initializes a new instance of the class.
///
- public GetPermissionsEndpointSummary()
+ public GetRolesEndpointSummary()
{
Summary = "Gets the collection of authorization roles.";
Description = "Gets the entire list of authorization roles.";
diff --git a/src/Lumina.Presentation.Api/Core/Endpoints/Library/Management/AddLibrary/AddLibraryEndpointSummary.cs b/src/Lumina.Presentation.Api/Core/Endpoints/Library/Management/AddLibrary/AddLibraryEndpointSummary.cs
index 8d0bf41f..90d989c0 100644
--- a/src/Lumina.Presentation.Api/Core/Endpoints/Library/Management/AddLibrary/AddLibraryEndpointSummary.cs
+++ b/src/Lumina.Presentation.Api/Core/Endpoints/Library/Management/AddLibrary/AddLibraryEndpointSummary.cs
@@ -42,8 +42,8 @@ public class AddLibraryEndpointSummary : Summary(r => r.Title, "The title of the media library.");
ResponseParam(r => r.LibraryType, "The type of the media library.");
ResponseParam(r => r.ContentLocations, "The file system paths of the directories where the media library elements are located.");
- ResponseParam(r => r.Created, "The date and time when the entity was created.");
- ResponseParam(r => r.Updated, "The date and time when the entity was last updated.");
+ ResponseParam(r => r.CreatedOnUtc, "The date and time when the entity was created.");
+ ResponseParam(r => r.UpdatedOnUtc, "The date and time when the entity was last updated.");
Response(201, "The media library was successfully created.", example:
@@ -53,8 +53,8 @@ public class AddLibraryEndpointSummary : Summary(r => r.Title, "The title of the media library.");
ResponseParam(r => r.LibraryType, "The type of the media library.");
ResponseParam(r => r.ContentLocations, "The file system paths of the directories where the media library elements are located.");
- ResponseParam(r => r.Created, "The date and time when the entity was created.");
- ResponseParam(r => r.Updated, "The date and time when the entity was last updated.");
+ ResponseParam(r => r.CreatedOnUtc, "The date and time when the entity was created.");
+ ResponseParam(r => r.UpdatedOnUtc, "The date and time when the entity was last updated.");
Response(200, "The media library is returned.", example: new LibraryResponse(
Id: Guid.NewGuid(),
@@ -44,8 +44,8 @@ public class GetLibraryEndpointSummary : Summary(r => r.Title, "The title of the media library.");
ResponseParam(r => r.LibraryType, "The type of the media library.");
ResponseParam(r => r.ContentLocations, "The file system paths of the directories where the media library elements are located.");
- ResponseParam(r => r.Created, "The date and time when the entity was created.");
- ResponseParam(r => r.Updated, "The date and time when the entity was last updated.");
+ ResponseParam(r => r.CreatedOnUtc, "The date and time when the entity was created.");
+ ResponseParam(r => r.UpdatedOnUtc, "The date and time when the entity was last updated.");
Response(200, "The media library was successfully updated.", example:
@@ -57,8 +57,8 @@ public class UpdateLibraryEndpointSummary : Summary r.Ratings, "The list of ratings for this book. Required.");
ResponseParam(r => r.Id, "The unique identifier of the entity.");
- ResponseParam(r => r.Created, "The date and time when the entity was created.");
- ResponseParam(r => r.Updated, "The date and time when the entity was last updated.");
+ ResponseParam(r => r.CreatedOnUtc, "The date and time when the entity was created.");
+ ResponseParam(r => r.UpdatedOnUtc, "The date and time when the entity was last updated.");
ResponseParam(r => r.Metadata, "The written content metadata of the book.");
ResponseParam(r => r.Metadata.Title, "The title of the media item.");
ResponseParam(r => r.Metadata.OriginalTitle, "The original title of the media item.");
@@ -276,8 +276,8 @@ public class AddLibraryEndpointSummary : Summary
VoteCount: 87654
)
],
- Created: DateTime.UtcNow,
- Updated: default
+ CreatedOnUtc: DateTime.UtcNow,
+ UpdatedOnUtc: default
),
new(
Id: Guid.NewGuid(),
@@ -229,8 +229,8 @@ public class GetBooksEndpointSummary : Summary
VoteCount: 90000
)
],
- Created: DateTime.UtcNow,
- Updated: default
+ CreatedOnUtc: DateTime.UtcNow,
+ UpdatedOnUtc: default
)
}
);
diff --git a/src/Lumina.Presentation.Api/Core/Endpoints/UsersManagement/Authentication/GetUsers/GetUsersEndpoint.cs b/src/Lumina.Presentation.Api/Core/Endpoints/UsersManagement/Authentication/GetUsers/GetUsersEndpoint.cs
index dbef913b..6a1b24b5 100644
--- a/src/Lumina.Presentation.Api/Core/Endpoints/UsersManagement/Authentication/GetUsers/GetUsersEndpoint.cs
+++ b/src/Lumina.Presentation.Api/Core/Endpoints/UsersManagement/Authentication/GetUsers/GetUsersEndpoint.cs
@@ -42,7 +42,7 @@ public class GetUsersEndpoint : BaseEndpoint
}
///
- /// Gets the list of authorization roles.
+ /// Gets the list of users.
///
/// Cancellation token that can be used to stop the execution.
public override async Task ExecuteAsync(EmptyRequest _, CancellationToken cancellationToken)
diff --git a/src/Lumina.Presentation.Api/Core/Endpoints/UsersManagement/Authentication/GetUsers/GetUsersEndpointSummary.cs b/src/Lumina.Presentation.Api/Core/Endpoints/UsersManagement/Authentication/GetUsers/GetUsersEndpointSummary.cs
new file mode 100644
index 00000000..77126ad8
--- /dev/null
+++ b/src/Lumina.Presentation.Api/Core/Endpoints/UsersManagement/Authentication/GetUsers/GetUsersEndpointSummary.cs
@@ -0,0 +1,71 @@
+#region ========================================================================= USING =====================================================================================
+using FastEndpoints;
+using Lumina.Contracts.Responses.UsersManagement.Users;
+using System;
+using System.Diagnostics.CodeAnalysis;
+#endregion
+
+namespace Lumina.Presentation.Api.Core.Endpoints.UsersManagement.Authentication.GetUsers;
+
+///
+/// Class used for providing a textual description for the API endpoint, for OpenAPI.
+///
+[ExcludeFromCodeCoverage]
+public class GetUsersEndpointSummary : Summary
+{
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public GetUsersEndpointSummary()
+ {
+ Summary = "Gets the collection of users.";
+ Description = "Gets the entire list of users.";
+
+ Response(200, "The list of users is returned.",
+ example: new[] {
+ new UserResponse(Id: Guid.NewGuid(), "TestUsername", DateTime.UtcNow, null)
+ });
+
+ Response(401, "Authentication required.", "application/problem+json",
+ example: new[]
+ {
+ new
+ {
+ type = "https://tools.ietf.org/html/rfc7235#section-3.1",
+ status = 401,
+ title = "Unauthorized",
+ detail = "You are not authorized",
+ instance = "/api/v1/auth/users"
+ },
+ new
+ {
+ type = "https://tools.ietf.org/html/rfc7235#section-3.1",
+ status = 401,
+ title = "Unauthorized",
+ detail = "Invalid token: The token expired at '01/01/2024 01:00:00'",
+ instance = "/api/v1/auth/users"
+ },
+ new
+ {
+ type = "https://tools.ietf.org/html/rfc7235#section-3.1",
+ status = 401,
+ title = "Unauthorized",
+ detail = "The token is invalid",
+ instance = "/api/v1/auth/users"
+ }
+ }
+ );
+
+ Response(403, "The request failed because the current user is not an Admin.", "application/problem+json",
+ example: new
+ {
+ type = "https://tools.ietf.org/html/rfc9110#section-15.5.4",
+ title = "General.Failure",
+ status = 403,
+ detail = "NotAuthorized",
+ instance = "/api/v1/auth/users",
+ traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
+ }
+ );
+ }
+}
diff --git a/src/Lumina.Presentation.Web/Common/Filters/ActionFilters/StoreLastViewFilter.cs b/src/Lumina.Presentation.Web/Common/Filters/ActionFilters/StoreLastViewFilter.cs
index 046879ac..0f4bb8a0 100644
--- a/src/Lumina.Presentation.Web/Common/Filters/ActionFilters/StoreLastViewFilter.cs
+++ b/src/Lumina.Presentation.Web/Common/Filters/ActionFilters/StoreLastViewFilter.cs
@@ -31,6 +31,7 @@ public class StoreLastViewFilter : IActionFilter
if (context.Result is ViewResult)
{
HttpContext httpContext = context.HttpContext;
+ // ignore the login endpoint, because it is incorrect to be redirected to the login URL, with the login URL as the return URL
if (httpContext.Request.Path != "/en-us/auth/login")
httpContext.Session.SetString(HttpContextItemKeys.LAST_DISPLAYED_VIEW, $"{httpContext.Request.PathBase}{httpContext.Request.Path}{httpContext.Request.QueryString}");
}
diff --git a/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Common/Converters/BookJsonConverter.cs b/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Common/Converters/BookJsonConverter.cs
index e38f0184..ad342169 100644
--- a/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Common/Converters/BookJsonConverter.cs
+++ b/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Common/Converters/BookJsonConverter.cs
@@ -36,7 +36,7 @@ public class BookJsonConverter : JsonConverter
JsonElement root = doc.RootElement;
Guid id = root.GetProperty("id").GetGuid();
- DateTime created = root.GetProperty("created").GetDateTime();
+ DateTime createdOnUtc = root.GetProperty("createdOnUtc").GetDateTime();
WrittenContentMetadata metadata = DeserializeMetadata(root.GetProperty("metadata"));
BookFormat? format = null;
if (root.TryGetProperty("format", out JsonElement formatElement))
@@ -80,7 +80,7 @@ public class BookJsonConverter : JsonConverter
Optional.FromNullable(googleBooksId),
Optional.FromNullable(barnesAndNobleId),
Optional.FromNullable(appleBooksId),
- created,
+ createdOnUtc,
default,
isbns,
contributorIds,
diff --git a/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Common/Setup/AuthenticatedLuminaApiFactory.cs b/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Common/Setup/AuthenticatedLuminaApiFactory.cs
index 63a31438..ddf69249 100644
--- a/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Common/Setup/AuthenticatedLuminaApiFactory.cs
+++ b/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Common/Setup/AuthenticatedLuminaApiFactory.cs
@@ -1,5 +1,6 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
+using Lumina.Application.Common.DataAccess.Seed;
using Lumina.Contracts.Requests.Authentication;
using Lumina.Contracts.Responses.Authentication;
using Lumina.DataAccess.Core.UoW;
@@ -12,6 +13,7 @@ using System.Net.Http;
using System.Net.Http.Headers;
using System.Net.Http.Json;
using System.Text.Json;
+using System.Threading;
using System.Threading.Tasks;
#endregion
@@ -102,6 +104,74 @@ public class AuthenticatedLuminaApiFactory : LuminaApiFactory, IDisposable
return user;
}
+ ///
+ /// Creates an HTTP client with authentication headers and an admin test user with all permissions
+ ///
+ /// An HTTP client configured with admin auth headers
+ public async Task CreateAuthenticatedAdminClientAsync()
+ {
+ HttpClient client = CreateClient();
+ TestUsername = $"testuser_{Guid.NewGuid()}";
+
+ // add the X-Forwarded-For header
+ client.DefaultRequestHeaders.Add("X-Forwarded-For",
+ $"192.{Random.Shared.Next(0, 255)}.{Random.Shared.Next(0, 255)}.{Random.Shared.Next(0, 255)}");
+
+ // create and authenticate admin user
+ await CreateAndAuthenticateAdminUser(client);
+
+ return client;
+ }
+
+ ///
+ /// Creates and authenticates an admin test user with all permissions.
+ ///
+ /// The HTTP client to configure with auth.
+ /// The created user entity.
+ private async Task CreateAndAuthenticateAdminUser(HttpClient client)
+ {
+ using IServiceScope scope = Services.CreateScope();
+ LuminaDbContext dbContext = scope.ServiceProvider.GetRequiredService();
+ IDataSeedService dataSeedService = scope.ServiceProvider.GetRequiredService();
+
+ // create test user
+ UserEntity user = new()
+ {
+ Id = Guid.NewGuid(),
+ Username = TestUsername!,
+ Password = _hashService.HashString("TestPass123!"),
+ Libraries = [],
+ UserPermissions = [],
+ UserRole = null,
+ CreatedBy = Guid.NewGuid(),
+ CreatedOnUtc = DateTime.UtcNow
+ };
+
+ dbContext.Users.Add(user);
+ await dbContext.SaveChangesAsync();
+
+ // set up admin permissions and roles
+ await dataSeedService.SetDefaultAuthorizationPermissionsAsync(user.Id, CancellationToken.None);
+ await dataSeedService.SetDefaultAuthorizationRolesAsync(user.Id, CancellationToken.None);
+ await dataSeedService.SetAdminRolePermissionsAsync(user.Id, CancellationToken.None);
+ await dataSeedService.SetAdminRoleToAdministratorAccount(user.Id, CancellationToken.None);
+
+ // authenticate user
+ LoginRequest loginRequest = new(
+ Username: user.Username,
+ Password: "TestPass123!"
+ );
+
+ HttpResponseMessage loginResponse = await client.PostAsJsonAsync("/api/v1/auth/login", loginRequest);
+ string content = await loginResponse.Content.ReadAsStringAsync();
+ LoginResponse? result = JsonSerializer.Deserialize(content, _jsonOptions);
+
+ // set auth header for subsequent requests
+ client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", result!.Token);
+
+ return user;
+ }
+
///
/// Disposes API factory resources.
///
diff --git a/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Core/Endpoints/Admin/Authorization/Permissions/GetPermissionsEndpointTests.cs b/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Core/Endpoints/Admin/Authorization/Permissions/GetPermissionsEndpointTests.cs
new file mode 100644
index 00000000..eb03a7ea
--- /dev/null
+++ b/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Core/Endpoints/Admin/Authorization/Permissions/GetPermissionsEndpointTests.cs
@@ -0,0 +1,140 @@
+#region ========================================================================= USING =====================================================================================
+using FluentAssertions;
+using Lumina.Application.Common.DataAccess.Entities.Authorization;
+using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
+using Lumina.Contracts.Responses.Authorization;
+using Lumina.DataAccess.Core.UoW;
+using Lumina.Domain.Common.Enums.Authorization;
+using Lumina.Presentation.Api.IntegrationTests.Common.Setup;
+using Microsoft.AspNetCore.Http;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.Extensions.DependencyInjection;
+using System;
+using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
+using System.Linq;
+using System.Net;
+using System.Net.Http;
+using System.Text.Json;
+using System.Text.Json.Serialization;
+using System.Threading;
+using System.Threading.Tasks;
+#endregion
+
+namespace Lumina.Presentation.Api.IntegrationTests.Core.Endpoints.Admin.Authorization.Permissions;
+
+///
+/// Contains integration tests for the class.
+///
+[ExcludeFromCodeCoverage]
+public class GetPermissionsEndpointTests : IClassFixture, IAsyncLifetime
+{
+ private HttpClient _client;
+ private readonly AuthenticatedLuminaApiFactory _apiFactory;
+ private readonly JsonSerializerOptions _jsonOptions = new()
+ {
+ PropertyNameCaseInsensitive = true,
+ Converters = { new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) }
+ };
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Injected in-memory API factory.
+ public GetPermissionsEndpointTests(AuthenticatedLuminaApiFactory apiFactory)
+ {
+ _client = apiFactory.CreateClient();
+ _apiFactory = apiFactory;
+ }
+
+ ///
+ /// Initializes authenticated API client.
+ ///
+ public async Task InitializeAsync()
+ {
+ _client = await _apiFactory.CreateAuthenticatedAdminClientAsync();
+ }
+
+ [Fact]
+ public async Task ExecuteAsync_WhenCalledWithValidRequest_ShouldReturnPermissions()
+ {
+ // Act
+ HttpResponseMessage response = await _client.GetAsync("/api/v1/permissions");
+
+ // Assert
+ response.EnsureSuccessStatusCode();
+ response.StatusCode.Should().Be(HttpStatusCode.OK);
+
+ string content = await response.Content.ReadAsStringAsync();
+ IEnumerable? result = JsonSerializer.Deserialize>(content, _jsonOptions);
+
+ result.Should().NotBeNull();
+ result.Should().NotBeEmpty();
+ result!.Should().AllSatisfy(permission =>
+ {
+ permission.Id.Should().NotBe(Guid.Empty);
+ permission.PermissionName.Should().NotBe(AuthorizationPermission.None);
+ });
+ }
+
+ [Fact]
+ public async Task ExecuteAsync_WhenCalledWithNonAdminAccount_ShouldReturnForbiddenResult()
+ {
+ // Act
+ _client = await _apiFactory.CreateAuthenticatedClientAsync(); // authenticated user, but not admin
+ HttpResponseMessage response = await _client.GetAsync("/api/v1/permissions");
+
+ // Assert
+ response.StatusCode.Should().Be(HttpStatusCode.Forbidden);
+
+ string content = await response.Content.ReadAsStringAsync();
+
+ Dictionary? problemDetails = JsonSerializer.Deserialize>(content, _jsonOptions);
+ problemDetails.Should().NotBeNull();
+ problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status403Forbidden);
+ problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc9110#section-15.5.4");
+ problemDetails["title"].GetString().Should().Be("General.Unauthorized");
+ problemDetails["detail"].GetString().Should().Be("NotAuthorized");
+ problemDetails["instance"].GetString().Should().Be("/api/v1/permissions");
+ problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
+ }
+
+ [Fact]
+ public async Task ExecuteAsync_WhenCancellationRequested_ShouldThrowTaskCanceledException()
+ {
+ // Arrange
+ using CancellationTokenSource cts = new();
+
+ // Act
+ Func act = async () =>
+ {
+ cts.Cancel();
+ await _client.GetAsync("/api/v1/permissions", cts.Token);
+ };
+
+ // Assert
+ await act.Should().ThrowAsync();
+ }
+
+ ///
+ /// Disposes API factory resources.
+ ///
+ public async Task DisposeAsync()
+ {
+ _apiFactory.Dispose();
+
+ using IServiceScope scope = _apiFactory.Services.CreateScope();
+ LuminaDbContext dbContext = scope.ServiceProvider.GetRequiredService();
+
+ // clear junction tables first
+ await dbContext.Set().ExecuteDeleteAsync();
+ await dbContext.Set().ExecuteDeleteAsync();
+
+ // then clear main tables
+ await dbContext.Set().ExecuteDeleteAsync();
+ await dbContext.Set().ExecuteDeleteAsync();
+ await dbContext.Set().ExecuteDeleteAsync();
+
+ await dbContext.SaveChangesAsync();
+ }
+}
diff --git a/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Core/Endpoints/Admin/Authorization/Roles/AddRoleEndpointTests.cs b/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Core/Endpoints/Admin/Authorization/Roles/AddRoleEndpointTests.cs
new file mode 100644
index 00000000..5f94f28f
--- /dev/null
+++ b/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Core/Endpoints/Admin/Authorization/Roles/AddRoleEndpointTests.cs
@@ -0,0 +1,188 @@
+#region ========================================================================= USING =====================================================================================
+using FluentAssertions;
+using Lumina.Application.Common.DataAccess.Entities.Authorization;
+using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
+using Lumina.Contracts.Requests.Authorization;
+using Lumina.Contracts.Responses.Authorization;
+using Lumina.DataAccess.Core.UoW;
+using Lumina.Domain.Common.Enums.Authorization;
+using Lumina.Presentation.Api.IntegrationTests.Common.Setup;
+using Microsoft.AspNetCore.Http;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.Extensions.DependencyInjection;
+using System;
+using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
+using System.Linq;
+using System.Net;
+using System.Net.Http;
+using System.Net.Http.Json;
+using System.Text.Json;
+using System.Text.Json.Serialization;
+using System.Threading;
+using System.Threading.Tasks;
+#endregion
+
+namespace Lumina.Presentation.Api.IntegrationTests.Core.Endpoints.Admin.Authorization.Roles;
+
+///
+/// Contains integration tests for the class.
+///
+[ExcludeFromCodeCoverage]
+public class AddRoleEndpointTests : IClassFixture, IAsyncLifetime
+{
+ private HttpClient _client;
+ private readonly AuthenticatedLuminaApiFactory _apiFactory;
+ private readonly JsonSerializerOptions _jsonOptions = new()
+ {
+ PropertyNameCaseInsensitive = true,
+ Converters = { new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) }
+ };
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Injected in-memory API factory.
+ public AddRoleEndpointTests(AuthenticatedLuminaApiFactory apiFactory)
+ {
+ _client = apiFactory.CreateClient();
+ _apiFactory = apiFactory;
+ }
+
+ ///
+ /// Initializes authenticated API client.
+ ///
+ public async Task InitializeAsync()
+ {
+ _client = await _apiFactory.CreateAuthenticatedAdminClientAsync();
+ }
+
+ [Fact]
+ public async Task ExecuteAsync_WhenCalledWithValidRequest_ShouldCreateRole()
+ {
+ // Arrange
+ using IServiceScope scope = _apiFactory.Services.CreateScope();
+ LuminaDbContext dbContext = scope.ServiceProvider.GetRequiredService();
+ PermissionEntity[] permissions = [.. dbContext.Permissions.Take(2)];
+
+ AddRoleRequest request = new(
+ RoleName: "Editor",
+ Permissions: permissions.Select(p => p.Id).ToList()
+ );
+
+ // Act
+ HttpResponseMessage response = await _client.PostAsJsonAsync("/api/v1/roles", request);
+
+ // Assert
+ response.EnsureSuccessStatusCode();
+ response.StatusCode.Should().Be(HttpStatusCode.OK);
+
+ string content = await response.Content.ReadAsStringAsync();
+ RolePermissionsResponse? result = JsonSerializer.Deserialize(content, _jsonOptions);
+
+ result.Should().NotBeNull();
+ result!.Role.RoleName.Should().Be("Editor");
+ result.Permissions.Should().HaveCount(2);
+ result.Permissions.Should().AllSatisfy(permission =>
+ {
+ permission.Id.Should().NotBe(Guid.Empty);
+ permission.PermissionName.Should().NotBe(AuthorizationPermission.None);
+ });
+ }
+
+ [Fact]
+ public async Task ExecuteAsync_WhenCalledWithNonAdminAccount_ShouldReturnForbiddenResult()
+ {
+ // Arrange
+ _client = await _apiFactory.CreateAuthenticatedClientAsync();
+ AddRoleRequest request = new(
+ RoleName: "Editor",
+ Permissions: [Guid.NewGuid()]
+ );
+
+ // Act
+ HttpResponseMessage response = await _client.PostAsJsonAsync("/api/v1/roles", request);
+
+ // Assert
+ response.StatusCode.Should().Be(HttpStatusCode.Forbidden);
+ string content = await response.Content.ReadAsStringAsync();
+
+ Dictionary? problemDetails = JsonSerializer.Deserialize>(content, _jsonOptions);
+ problemDetails.Should().NotBeNull();
+ problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status403Forbidden);
+ problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc9110#section-15.5.4");
+ problemDetails["title"].GetString().Should().Be("General.Unauthorized");
+ problemDetails["detail"].GetString().Should().Be("NotAuthorized");
+ problemDetails["instance"].GetString().Should().Be("/api/v1/roles");
+ problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
+ }
+
+ [Fact]
+ public async Task ExecuteAsync_WhenRoleAlreadyExists_ShouldReturnConflict()
+ {
+ // Arrange
+ AddRoleRequest request = new(
+ RoleName: "Admin",
+ Permissions: [Guid.NewGuid()]
+ );
+
+ // Act
+ HttpResponseMessage response = await _client.PostAsJsonAsync("/api/v1/roles", request);
+
+ // Assert
+ response.StatusCode.Should().Be(HttpStatusCode.Conflict);
+ string content = await response.Content.ReadAsStringAsync();
+
+ Dictionary? problemDetails = JsonSerializer.Deserialize>(content, _jsonOptions);
+ problemDetails.Should().NotBeNull();
+ problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status409Conflict);
+ problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc9110#section-15.5.10");
+ problemDetails["title"].GetString().Should().Be("General.Conflict");
+ problemDetails["detail"].GetString().Should().Be("RoleAlreadyExists");
+ problemDetails["instance"].GetString().Should().Be("/api/v1/roles");
+ problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
+ }
+
+ [Fact]
+ public async Task ExecuteAsync_WhenCancellationRequested_ShouldThrowTaskCanceledException()
+ {
+ // Arrange
+ using CancellationTokenSource cts = new();
+ AddRoleRequest request = new(
+ RoleName: "Editor",
+ Permissions: [Guid.NewGuid()]
+ );
+
+ // Act
+ Func act = async () =>
+ {
+ cts.Cancel();
+ await _client.PostAsJsonAsync("/api/v1/roles", request, cts.Token);
+ };
+
+ // Assert
+ await act.Should().ThrowAsync();
+ }
+
+ ///
+ /// Disposes API factory resources.
+ ///
+ public async Task DisposeAsync()
+ {
+ using IServiceScope scope = _apiFactory.Services.CreateScope();
+ LuminaDbContext dbContext = scope.ServiceProvider.GetRequiredService();
+
+ // clear junction tables first
+ await dbContext.Set().ExecuteDeleteAsync();
+ await dbContext.Set().ExecuteDeleteAsync();
+
+ // then clear main tables
+ await dbContext.Set().ExecuteDeleteAsync();
+ await dbContext.Set().ExecuteDeleteAsync();
+ await dbContext.Set().ExecuteDeleteAsync();
+
+ await dbContext.SaveChangesAsync();
+
+ _apiFactory.Dispose();
+ }
+}
diff --git a/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Core/Endpoints/Admin/Authorization/Roles/DeleteRoleEndpointTests.cs b/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Core/Endpoints/Admin/Authorization/Roles/DeleteRoleEndpointTests.cs
new file mode 100644
index 00000000..32d71cd1
--- /dev/null
+++ b/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Core/Endpoints/Admin/Authorization/Roles/DeleteRoleEndpointTests.cs
@@ -0,0 +1,197 @@
+#region ========================================================================= USING =====================================================================================
+using FluentAssertions;
+using Lumina.Application.Common.DataAccess.Entities.Authorization;
+using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
+using Lumina.DataAccess.Core.UoW;
+using Lumina.Presentation.Api.IntegrationTests.Common.Setup;
+using Microsoft.AspNetCore.Http;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.Extensions.DependencyInjection;
+using System;
+using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
+using System.Linq;
+using System.Net;
+using System.Net.Http;
+using System.Text.Json;
+using System.Text.Json.Serialization;
+using System.Threading;
+using System.Threading.Tasks;
+#endregion
+
+namespace Lumina.Presentation.Api.IntegrationTests.Core.Endpoints.Admin.Authorization.Roles;
+
+///
+/// Contains integration tests for the class.
+///
+[ExcludeFromCodeCoverage]
+public class DeleteRoleEndpointTests : IClassFixture, IAsyncLifetime
+{
+ private HttpClient _client;
+ private readonly AuthenticatedLuminaApiFactory _apiFactory;
+ private readonly JsonSerializerOptions _jsonOptions = new()
+ {
+ PropertyNameCaseInsensitive = true,
+ Converters = { new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) }
+ };
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Injected in-memory API factory.
+ public DeleteRoleEndpointTests(AuthenticatedLuminaApiFactory apiFactory)
+ {
+ _client = apiFactory.CreateClient();
+ _apiFactory = apiFactory;
+ }
+
+ ///
+ /// Initializes authenticated API client.
+ ///
+ public async Task InitializeAsync()
+ {
+ _client = await _apiFactory.CreateAuthenticatedAdminClientAsync();
+ }
+
+ [Fact]
+ public async Task ExecuteAsync_WhenCalledWithValidRequest_ShouldDeleteRole()
+ {
+ // Arrange
+ using IServiceScope scope = _apiFactory.Services.CreateScope();
+ LuminaDbContext dbContext = scope.ServiceProvider.GetRequiredService();
+
+ // Create a test role first
+ RoleEntity role = new()
+ {
+ Id = Guid.NewGuid(),
+ RoleName = "TestRole",
+ CreatedBy = Guid.NewGuid(),
+ CreatedOnUtc = DateTime.UtcNow
+ };
+ dbContext.Roles.Add(role);
+ await dbContext.SaveChangesAsync();
+
+ // Act
+ HttpResponseMessage response = await _client.DeleteAsync($"/api/v1/roles/{role.Id}");
+
+ // Assert
+ response.StatusCode.Should().Be(HttpStatusCode.NoContent);
+
+ // Verify role was deleted
+ RoleEntity? deletedRole = await dbContext.Roles.FirstOrDefaultAsync(r => r.Id == role.Id);
+ deletedRole.Should().BeNull();
+ }
+
+ [Fact]
+ public async Task ExecuteAsync_WhenCalledWithNonAdminAccount_ShouldReturnForbiddenResult()
+ {
+ // Arrange
+ _client = await _apiFactory.CreateAuthenticatedClientAsync();
+ Guid roleId = Guid.NewGuid();
+
+ // Act
+ HttpResponseMessage response = await _client.DeleteAsync($"/api/v1/roles/{roleId}");
+
+ // Assert
+ response.StatusCode.Should().Be(HttpStatusCode.Forbidden);
+ string content = await response.Content.ReadAsStringAsync();
+
+ Dictionary? problemDetails = JsonSerializer.Deserialize>(content, _jsonOptions);
+ problemDetails.Should().NotBeNull();
+ problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status403Forbidden);
+ problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc9110#section-15.5.4");
+ problemDetails["title"].GetString().Should().Be("General.Unauthorized");
+ problemDetails["detail"].GetString().Should().Be("NotAuthorized");
+ problemDetails["instance"].GetString().Should().Be($"/api/v1/roles/{roleId}");
+ problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
+ }
+
+ [Fact]
+ public async Task ExecuteAsync_WhenTryingToDeleteAdminRole_ShouldReturnForbiddenResult()
+ {
+ // Arrange
+ using IServiceScope scope = _apiFactory.Services.CreateScope();
+ LuminaDbContext dbContext = scope.ServiceProvider.GetRequiredService();
+ RoleEntity? adminRole = dbContext.Roles.FirstOrDefault(r => r.RoleName == "Admin");
+ adminRole.Should().NotBeNull("Admin role should exist");
+
+ // Act
+ HttpResponseMessage response = await _client.DeleteAsync($"/api/v1/roles/{adminRole!.Id}");
+
+ // Assert
+ response.StatusCode.Should().Be(HttpStatusCode.Forbidden);
+ string content = await response.Content.ReadAsStringAsync();
+
+ Dictionary? problemDetails = JsonSerializer.Deserialize>(content, _jsonOptions);
+ problemDetails.Should().NotBeNull();
+ problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status403Forbidden);
+ problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc9110#section-15.5.4");
+ problemDetails["title"].GetString().Should().Be("General.Forbidden");
+ problemDetails["detail"].GetString().Should().Be("AdminRoleCannotBeDeleted");
+ problemDetails["instance"].GetString().Should().Be($"/api/v1/roles/{adminRole!.Id}");
+ problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
+ }
+
+ [Fact]
+ public async Task ExecuteAsync_WhenRoleDoesNotExist_ShouldReturnNotFound()
+ {
+ // Arrange
+ Guid nonExistentRoleId = Guid.NewGuid();
+
+ // Act
+ HttpResponseMessage response = await _client.DeleteAsync($"/api/v1/roles/{nonExistentRoleId}");
+
+ // Assert
+ response.StatusCode.Should().Be(HttpStatusCode.NotFound);
+ string content = await response.Content.ReadAsStringAsync();
+
+ Dictionary? problemDetails = JsonSerializer.Deserialize>(content, _jsonOptions);
+ problemDetails.Should().NotBeNull();
+ problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status404NotFound);
+ problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc9110#section-15.5.5");
+ problemDetails["title"].GetString().Should().Be("General.NotFound");
+ problemDetails["detail"].GetString().Should().Be("RoleNotFound");
+ problemDetails["instance"].GetString().Should().Be($"/api/v1/roles/{nonExistentRoleId}");
+ problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
+ }
+
+ [Fact]
+ public async Task ExecuteAsync_WhenCancellationRequested_ShouldThrowTaskCanceledException()
+ {
+ // Arrange
+ using CancellationTokenSource cts = new();
+ Guid roleId = Guid.NewGuid();
+
+ // Act
+ Func act = async () =>
+ {
+ cts.Cancel();
+ await _client.DeleteAsync($"/api/v1/roles/{roleId}", cts.Token);
+ };
+
+ // Assert
+ await act.Should().ThrowAsync();
+ }
+
+ ///
+ /// Disposes API factory resources.
+ ///
+ public async Task DisposeAsync()
+ {
+ using IServiceScope scope = _apiFactory.Services.CreateScope();
+ LuminaDbContext dbContext = scope.ServiceProvider.GetRequiredService();
+
+ // clear junction tables first
+ await dbContext.Set().ExecuteDeleteAsync();
+ await dbContext.Set().ExecuteDeleteAsync();
+
+ // then clear main tables
+ await dbContext.Set().ExecuteDeleteAsync();
+ await dbContext.Set().ExecuteDeleteAsync();
+ await dbContext.Set().ExecuteDeleteAsync();
+
+ await dbContext.SaveChangesAsync();
+
+ _apiFactory.Dispose();
+ }
+}
diff --git a/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Core/Endpoints/Admin/Authorization/Roles/GetRolePermissionsEndpointTests.cs b/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Core/Endpoints/Admin/Authorization/Roles/GetRolePermissionsEndpointTests.cs
new file mode 100644
index 00000000..7858ec5e
--- /dev/null
+++ b/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Core/Endpoints/Admin/Authorization/Roles/GetRolePermissionsEndpointTests.cs
@@ -0,0 +1,178 @@
+#region ========================================================================= USING =====================================================================================
+using FluentAssertions;
+using Lumina.Application.Common.DataAccess.Entities.Authorization;
+using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
+using Lumina.Contracts.Responses.Authorization;
+using Lumina.DataAccess.Core.UoW;
+using Lumina.Domain.Common.Enums.Authorization;
+using Lumina.Presentation.Api.IntegrationTests.Common.Setup;
+using Microsoft.AspNetCore.Http;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.Extensions.DependencyInjection;
+using System;
+using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
+using System.Linq;
+using System.Net;
+using System.Net.Http;
+using System.Text.Json;
+using System.Text.Json.Serialization;
+using System.Threading;
+using System.Threading.Tasks;
+#endregion
+
+namespace Lumina.Presentation.Api.IntegrationTests.Core.Endpoints.Admin.Authorization.Roles;
+
+///
+/// Contains integration tests for the class.
+///
+[ExcludeFromCodeCoverage]
+public class GetRolePermissionsEndpointTests : IClassFixture, IAsyncLifetime
+{
+ private HttpClient _client;
+ private readonly AuthenticatedLuminaApiFactory _apiFactory;
+ private readonly JsonSerializerOptions _jsonOptions = new()
+ {
+ PropertyNameCaseInsensitive = true,
+ Converters = { new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) }
+ };
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Injected in-memory API factory.
+ public GetRolePermissionsEndpointTests(AuthenticatedLuminaApiFactory apiFactory)
+ {
+ _client = apiFactory.CreateClient();
+ _apiFactory = apiFactory;
+ }
+
+ ///
+ /// Initializes authenticated API client.
+ ///
+ public async Task InitializeAsync()
+ {
+ _client = await _apiFactory.CreateAuthenticatedAdminClientAsync();
+ }
+
+ [Fact]
+ public async Task ExecuteAsync_WhenCalledWithValidRequest_ShouldReturnRolePermissions()
+ {
+ // Arrange
+ using IServiceScope scope = _apiFactory.Services.CreateScope();
+ LuminaDbContext dbContext = scope.ServiceProvider.GetRequiredService();
+ RoleEntity? role = dbContext.Roles.FirstOrDefault();
+ role.Should().NotBeNull("Admin role should exist");
+
+ // Act
+ HttpResponseMessage response = await _client.GetAsync($"/api/v1/roles/{role!.Id}/permissions");
+
+ // Assert
+ response.EnsureSuccessStatusCode();
+ response.StatusCode.Should().Be(HttpStatusCode.OK);
+
+ string content = await response.Content.ReadAsStringAsync();
+ RolePermissionsResponse? result = JsonSerializer.Deserialize(content, _jsonOptions);
+
+ result.Should().NotBeNull();
+ result!.Role.Id.Should().Be(role.Id);
+ result.Role.RoleName.Should().Be("Admin");
+ result.Permissions.Should().NotBeEmpty();
+ result.Permissions.Should().AllSatisfy(permission =>
+ {
+ permission.Id.Should().NotBe(Guid.Empty);
+ permission.PermissionName.Should().NotBe(AuthorizationPermission.None);
+ });
+ }
+
+ [Fact]
+ public async Task ExecuteAsync_WhenCalledWithNonAdminAccount_ShouldReturnForbiddenResult()
+ {
+ // Arrange
+ _client = await _apiFactory.CreateAuthenticatedClientAsync(); // authenticated user, but not admin
+ using IServiceScope scope = _apiFactory.Services.CreateScope();
+ LuminaDbContext dbContext = scope.ServiceProvider.GetRequiredService();
+ RoleEntity? role = dbContext.Roles.FirstOrDefault();
+ role.Should().NotBeNull("Admin role should exist");
+
+ // Act
+ HttpResponseMessage response = await _client.GetAsync($"/api/v1/roles/{role!.Id}/permissions");
+
+ // Assert
+ response.StatusCode.Should().Be(HttpStatusCode.Forbidden);
+ string content = await response.Content.ReadAsStringAsync();
+
+ Dictionary? problemDetails = JsonSerializer.Deserialize>(content, _jsonOptions);
+ problemDetails.Should().NotBeNull();
+ problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status403Forbidden);
+ problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc9110#section-15.5.4");
+ problemDetails["title"].GetString().Should().Be("General.Unauthorized");
+ problemDetails["detail"].GetString().Should().Be("NotAuthorized");
+ problemDetails["instance"].GetString().Should().Be($"/api/v1/roles/{role.Id}/permissions");
+ problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
+ }
+
+ [Fact]
+ public async Task ExecuteAsync_WhenCalledWithInvalidRoleId_ShouldReturnNotFound()
+ {
+ // Act
+ Guid invalidRoleId = Guid.NewGuid();
+ HttpResponseMessage response = await _client.GetAsync($"/api/v1/roles/{invalidRoleId}/permissions");
+
+ // Assert
+ response.StatusCode.Should().Be(HttpStatusCode.NotFound);
+ string content = await response.Content.ReadAsStringAsync();
+
+ Dictionary? problemDetails = JsonSerializer.Deserialize>(content, _jsonOptions);
+ problemDetails.Should().NotBeNull();
+ problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status404NotFound);
+ problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc9110#section-15.5.5");
+ problemDetails["title"].GetString().Should().Be("General.NotFound");
+ problemDetails["detail"].GetString().Should().Be("RoleNotFound");
+ problemDetails["instance"].GetString().Should().Be($"/api/v1/roles/{invalidRoleId}/permissions");
+ problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
+ }
+
+ [Fact]
+ public async Task ExecuteAsync_WhenCancellationRequested_ShouldThrowTaskCanceledException()
+ {
+ // Arrange
+ using CancellationTokenSource cts = new();
+ using IServiceScope scope = _apiFactory.Services.CreateScope();
+ LuminaDbContext dbContext = scope.ServiceProvider.GetRequiredService();
+ RoleEntity? role = dbContext.Roles.FirstOrDefault();
+ role.Should().NotBeNull("Admin role should exist");
+
+ // Act
+ Func act = async () =>
+ {
+ cts.Cancel();
+ await _client.GetAsync($"/api/v1/roles/{role!.Id}/permissions", cts.Token);
+ };
+
+ // Assert
+ await act.Should().ThrowAsync();
+ }
+
+ ///
+ /// Disposes API factory resources.
+ ///
+ public async Task DisposeAsync()
+ {
+ using IServiceScope scope = _apiFactory.Services.CreateScope();
+ LuminaDbContext dbContext = scope.ServiceProvider.GetRequiredService();
+
+ // clear junction tables first
+ await dbContext.Set().ExecuteDeleteAsync();
+ await dbContext.Set().ExecuteDeleteAsync();
+
+ // then clear main tables
+ await dbContext.Set().ExecuteDeleteAsync();
+ await dbContext.Set().ExecuteDeleteAsync();
+ await dbContext.Set().ExecuteDeleteAsync();
+
+ await dbContext.SaveChangesAsync();
+
+ _apiFactory.Dispose();
+ }
+}
diff --git a/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Core/Endpoints/Admin/Authorization/Roles/GetRolesEndpointTests.cs b/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Core/Endpoints/Admin/Authorization/Roles/GetRolesEndpointTests.cs
new file mode 100644
index 00000000..09e9098c
--- /dev/null
+++ b/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Core/Endpoints/Admin/Authorization/Roles/GetRolesEndpointTests.cs
@@ -0,0 +1,138 @@
+#region ========================================================================= USING =====================================================================================
+using FluentAssertions;
+using Lumina.Application.Common.DataAccess.Entities.Authorization;
+using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
+using Lumina.Contracts.Responses.Authorization;
+using Lumina.DataAccess.Core.UoW;
+using Lumina.Presentation.Api.IntegrationTests.Common.Setup;
+using Microsoft.AspNetCore.Http;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.Extensions.DependencyInjection;
+using System;
+using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
+using System.Net;
+using System.Net.Http;
+using System.Text.Json;
+using System.Text.Json.Serialization;
+using System.Threading;
+using System.Threading.Tasks;
+#endregion
+
+namespace Lumina.Presentation.Api.IntegrationTests.Core.Endpoints.Admin.Authorization.Roles;
+
+///
+/// Contains integration tests for the class.
+///
+[ExcludeFromCodeCoverage]
+public class GetRolesEndpointTests : IClassFixture, IAsyncLifetime
+{
+ private HttpClient _client;
+ private readonly AuthenticatedLuminaApiFactory _apiFactory;
+ private readonly JsonSerializerOptions _jsonOptions = new()
+ {
+ PropertyNameCaseInsensitive = true,
+ Converters = { new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) }
+ };
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Injected in-memory API factory.
+ public GetRolesEndpointTests(AuthenticatedLuminaApiFactory apiFactory)
+ {
+ _client = apiFactory.CreateClient();
+ _apiFactory = apiFactory;
+ }
+
+ ///
+ /// Initializes authenticated API client.
+ ///
+ public async Task InitializeAsync()
+ {
+ _client = await _apiFactory.CreateAuthenticatedAdminClientAsync();
+ }
+
+ [Fact]
+ public async Task ExecuteAsync_WhenCalledWithValidRequest_ShouldReturnRoles()
+ {
+ // Act
+ HttpResponseMessage response = await _client.GetAsync("/api/v1/roles");
+
+ // Assert
+ response.EnsureSuccessStatusCode();
+ response.StatusCode.Should().Be(HttpStatusCode.OK);
+
+ string content = await response.Content.ReadAsStringAsync();
+ IEnumerable? result = JsonSerializer.Deserialize>(content, _jsonOptions);
+
+ result.Should().NotBeNull();
+ result.Should().NotBeEmpty();
+ result!.Should().Contain(role =>
+ role.Id != Guid.Empty &&
+ role.RoleName == "Admin"
+ );
+ }
+
+ [Fact]
+ public async Task ExecuteAsync_WhenCalledWithNonAdminAccount_ShouldReturnForbiddenResult()
+ {
+ // Arrange
+ _client = await _apiFactory.CreateAuthenticatedClientAsync();
+
+ // Act
+ HttpResponseMessage response = await _client.GetAsync("/api/v1/roles");
+
+ // Assert
+ response.StatusCode.Should().Be(HttpStatusCode.Forbidden);
+ string content = await response.Content.ReadAsStringAsync();
+
+ Dictionary? problemDetails = JsonSerializer.Deserialize>(content, _jsonOptions);
+ problemDetails.Should().NotBeNull();
+ problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status403Forbidden);
+ problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc9110#section-15.5.4");
+ problemDetails["title"].GetString().Should().Be("General.Unauthorized");
+ problemDetails["detail"].GetString().Should().Be("NotAuthorized");
+ problemDetails["instance"].GetString().Should().Be("/api/v1/roles");
+ problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
+ }
+
+ [Fact]
+ public async Task ExecuteAsync_WhenCancellationRequested_ShouldThrowTaskCanceledException()
+ {
+ // Arrange
+ using CancellationTokenSource cts = new();
+
+ // Act
+ Func act = async () =>
+ {
+ cts.Cancel();
+ await _client.GetAsync("/api/v1/roles", cts.Token);
+ };
+
+ // Assert
+ await act.Should().ThrowAsync();
+ }
+
+ ///
+ /// Disposes API factory resources.
+ ///
+ public async Task DisposeAsync()
+ {
+ using IServiceScope scope = _apiFactory.Services.CreateScope();
+ LuminaDbContext dbContext = scope.ServiceProvider.GetRequiredService();
+
+ // clear junction tables first
+ await dbContext.Set().ExecuteDeleteAsync();
+ await dbContext.Set().ExecuteDeleteAsync();
+
+ // then clear main tables
+ await dbContext.Set().ExecuteDeleteAsync();
+ await dbContext.Set().ExecuteDeleteAsync();
+ await dbContext.Set().ExecuteDeleteAsync();
+
+ await dbContext.SaveChangesAsync();
+
+ _apiFactory.Dispose();
+ }
+}
diff --git a/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Core/Endpoints/Admin/Authorization/Roles/UpdateRoleEndpointTests.cs b/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Core/Endpoints/Admin/Authorization/Roles/UpdateRoleEndpointTests.cs
new file mode 100644
index 00000000..464f1bd6
--- /dev/null
+++ b/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Core/Endpoints/Admin/Authorization/Roles/UpdateRoleEndpointTests.cs
@@ -0,0 +1,204 @@
+#region ========================================================================= USING =====================================================================================
+using FluentAssertions;
+using Lumina.Application.Common.DataAccess.Entities.Authorization;
+using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
+using Lumina.Contracts.Requests.Authorization;
+using Lumina.Contracts.Responses.Authorization;
+using Lumina.DataAccess.Core.UoW;
+using Lumina.Domain.Common.Enums.Authorization;
+using Lumina.Presentation.Api.IntegrationTests.Common.Setup;
+using Microsoft.AspNetCore.Http;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.Extensions.DependencyInjection;
+using System;
+using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
+using System.Linq;
+using System.Net;
+using System.Net.Http;
+using System.Net.Http.Json;
+using System.Text.Json;
+using System.Text.Json.Serialization;
+using System.Threading;
+using System.Threading.Tasks;
+#endregion
+
+namespace Lumina.Presentation.Api.IntegrationTests.Core.Endpoints.Admin.Authorization.Roles;
+
+///
+/// Contains integration tests for the class.
+///
+[ExcludeFromCodeCoverage]
+public class UpdateRoleEndpointTests : IClassFixture, IAsyncLifetime
+{
+ private HttpClient _client;
+ private readonly AuthenticatedLuminaApiFactory _apiFactory;
+ private readonly JsonSerializerOptions _jsonOptions = new()
+ {
+ PropertyNameCaseInsensitive = true,
+ Converters = { new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) }
+ };
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Injected in-memory API factory.
+ public UpdateRoleEndpointTests(AuthenticatedLuminaApiFactory apiFactory)
+ {
+ _client = apiFactory.CreateClient();
+ _apiFactory = apiFactory;
+ }
+
+ ///
+ /// Initializes authenticated API client.
+ ///
+ public async Task InitializeAsync()
+ {
+ _client = await _apiFactory.CreateAuthenticatedAdminClientAsync();
+ }
+
+ [Fact]
+ public async Task ExecuteAsync_WhenCalledWithValidRequest_ShouldUpdateRole()
+ {
+ // Arrange
+ using IServiceScope scope = _apiFactory.Services.CreateScope();
+ LuminaDbContext dbContext = scope.ServiceProvider.GetRequiredService();
+
+ RoleEntity role = new()
+ {
+ Id = Guid.NewGuid(),
+ RoleName = "TestRole",
+ CreatedBy = Guid.NewGuid(),
+ CreatedOnUtc = DateTime.UtcNow
+ };
+ dbContext.Roles.Add(role);
+ await dbContext.SaveChangesAsync();
+
+ PermissionEntity[] permissions = [.. dbContext.Permissions.Take(2)];
+ UpdateRoleRequest request = new(
+ RoleId: role.Id,
+ RoleName: "UpdatedRole",
+ Permissions: permissions.Select(p => p.Id).ToList()
+ );
+
+ // Act
+ HttpResponseMessage response = await _client.PutAsJsonAsync($"/api/v1/roles", request);
+
+ // Assert
+ response.EnsureSuccessStatusCode();
+ response.StatusCode.Should().Be(HttpStatusCode.OK);
+
+ string content = await response.Content.ReadAsStringAsync();
+ RolePermissionsResponse? result = JsonSerializer.Deserialize(content, _jsonOptions);
+
+ result.Should().NotBeNull();
+ result!.Role.Id.Should().Be(role.Id);
+ result.Role.RoleName.Should().Be("UpdatedRole");
+ result.Permissions.Should().HaveCount(2);
+ result.Permissions.Should().AllSatisfy(permission =>
+ {
+ permission.Id.Should().NotBe(Guid.Empty);
+ permission.PermissionName.Should().NotBe(AuthorizationPermission.None);
+ });
+ }
+
+ [Fact]
+ public async Task ExecuteAsync_WhenCalledWithNonAdminAccount_ShouldReturnForbiddenResult()
+ {
+ // Arrange
+ _client = await _apiFactory.CreateAuthenticatedClientAsync();
+ UpdateRoleRequest request = new(
+ RoleId: Guid.NewGuid(),
+ RoleName: "UpdatedRole",
+ Permissions: [Guid.NewGuid()]
+ );
+
+ // Act
+ HttpResponseMessage response = await _client.PutAsJsonAsync($"/api/v1/roles", request);
+
+ // Assert
+ response.StatusCode.Should().Be(HttpStatusCode.Forbidden);
+ string content = await response.Content.ReadAsStringAsync();
+
+ Dictionary? problemDetails = JsonSerializer.Deserialize>(content, _jsonOptions);
+ problemDetails.Should().NotBeNull();
+ problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status403Forbidden);
+ problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc9110#section-15.5.4");
+ problemDetails["title"].GetString().Should().Be("General.Unauthorized");
+ problemDetails["detail"].GetString().Should().Be("NotAuthorized");
+ problemDetails["instance"].GetString().Should().Be("/api/v1/roles");
+ problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
+ }
+
+ [Fact]
+ public async Task ExecuteAsync_WhenRoleDoesNotExist_ShouldReturnNotFound()
+ {
+ // Arrange
+ Guid nonExistentRoleId = Guid.NewGuid();
+ UpdateRoleRequest request = new(
+ RoleId: nonExistentRoleId,
+ RoleName: "UpdatedRole",
+ Permissions: [Guid.NewGuid()]
+ );
+
+ // Act
+ HttpResponseMessage response = await _client.PutAsJsonAsync($"/api/v1/roles", request);
+
+ // Assert
+ response.StatusCode.Should().Be(HttpStatusCode.NotFound);
+ string content = await response.Content.ReadAsStringAsync();
+
+ Dictionary? problemDetails = JsonSerializer.Deserialize>(content, _jsonOptions);
+ problemDetails.Should().NotBeNull();
+ problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status404NotFound);
+ problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc9110#section-15.5.5");
+ problemDetails["title"].GetString().Should().Be("General.NotFound");
+ problemDetails["detail"].GetString().Should().Be("RoleNotFound");
+ problemDetails["instance"].GetString().Should().Be("/api/v1/roles");
+ problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
+ }
+
+ [Fact]
+ public async Task ExecuteAsync_WhenCancellationRequested_ShouldThrowTaskCanceledException()
+ {
+ // Arrange
+ using CancellationTokenSource cts = new();
+ UpdateRoleRequest request = new(
+ RoleId: Guid.NewGuid(),
+ RoleName: "UpdatedRole",
+ Permissions: [Guid.NewGuid()]
+ );
+
+ // Act
+ Func act = async () =>
+ {
+ cts.Cancel();
+ await _client.PutAsJsonAsync($"/api/v1/roles", request, cts.Token);
+ };
+
+ // Assert
+ await act.Should().ThrowAsync();
+ }
+
+ ///