A lot of changes
This commit is contained in:
@@ -9,7 +9,7 @@ namespace Musify.Application.Configuration
|
||||
public static IServiceCollection AddApplicationConfigurations(this IServiceCollection serviceDescriptors, IConfiguration configuration)
|
||||
{
|
||||
serviceDescriptors
|
||||
.AddValidatedConfiguration<StorageConfiguration>(configuration, StorageConfiguration.SectionName)
|
||||
.AddValidatedConfiguration<StorageSettings>(configuration, StorageSettings.SectionName)
|
||||
.AddValidatedConfiguration<PlayListConfiguration>(configuration, PlayListConfiguration.SectionName);
|
||||
|
||||
return serviceDescriptors;
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Musify.Application.Configuration
|
||||
{
|
||||
#pragma warning disable CS8618
|
||||
public class StorageConfiguration
|
||||
{
|
||||
public const string SectionName = "Storage";
|
||||
|
||||
[Required]
|
||||
public string BucketName { get; set; }
|
||||
|
||||
[Required]
|
||||
public string ServiceUrl { get; set; }
|
||||
|
||||
[Required]
|
||||
public string AccessKey { get; set; }
|
||||
|
||||
[Required]
|
||||
public string SecretAccessKey { get; set; }
|
||||
|
||||
[Required]
|
||||
public bool ForcePathStyle { get; set; }
|
||||
|
||||
[Required]
|
||||
public bool UseHttp { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Musify.Application.Configuration
|
||||
{
|
||||
public class StorageSettings
|
||||
{
|
||||
public const string SectionName = "Storage";
|
||||
|
||||
[Required]
|
||||
public required string BucketName { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ using Musify.Domain.Entities;
|
||||
namespace Musify.Application.PlayLists.Commands.CreatePlayList
|
||||
{
|
||||
public class CreatePlayListCommandHandler(IPublishEndpoint publishEndpoint, IDatabase database, IStorageHandler storageHandler,
|
||||
ILogger<CreatePlayListCommandHandler> logger, StorageConfiguration storageConfiguration, PlayListConfiguration playListConfiguration)
|
||||
ILogger<CreatePlayListCommandHandler> logger, StorageSettings storageConfiguration, PlayListConfiguration playListConfiguration)
|
||||
: IRequestHandler<CreatePlayListCommand, Task<Result<PlayListResponse>> >
|
||||
{
|
||||
public async Task<Result<PlayListResponse>> Handle(CreatePlayListCommand request, CancellationToken cancellationToken)
|
||||
@@ -57,7 +57,7 @@ namespace Musify.Application.PlayLists.Commands.CreatePlayList
|
||||
return Result.Error($"Failed to upload picture for PlayList with Id {playList.Id} to storage.");
|
||||
}
|
||||
|
||||
logger.LogInformation("PlayList with Id={PlayListId} created successfully for UserId={UserId}.", playList.Id, request.UserId);
|
||||
logger.LogInformation("Playlist image uploaded successfully for PlayList with Id={PlayListId}.", playList.Id);
|
||||
|
||||
await publishEndpoint.Publish(new ResizePictureEvent(
|
||||
storageConfiguration.BucketName,
|
||||
@@ -85,7 +85,7 @@ namespace Musify.Application.PlayLists.Commands.CreatePlayList
|
||||
await database.PlayLists.AddAsync(playList, cancellationToken);
|
||||
await database.SaveChangesAsync(cancellationToken);
|
||||
|
||||
logger.LogInformation("Picture for PlayList with Id={PlayListId} ", playList.Id);
|
||||
logger.LogInformation("PlayList with id={PlayListId} created successfully for user with id={UserId}.", playList.Id, request.UserId);
|
||||
return Result.Created(PlayListResponse.FromEntity(playList));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ using Musify.Application.Events;
|
||||
namespace Musify.Application.PlayLists.Commands.DeletePlayList
|
||||
{
|
||||
public class DeletePlayListCommandHandler(IDatabase database, IPublishEndpoint publishEndpoint,
|
||||
StorageConfiguration storageConfiguration, PlayListConfiguration playListConfiguration, ILogger<DeletePlayListCommandHandler> logger)
|
||||
StorageSettings storageConfiguration, PlayListConfiguration playListConfiguration, ILogger<DeletePlayListCommandHandler> logger)
|
||||
: IRequestHandler<DeletePlayListCommand, Task<Result>>
|
||||
{
|
||||
public async Task<Result> Handle(DeletePlayListCommand request, CancellationToken cancellationToken)
|
||||
|
||||
@@ -11,7 +11,7 @@ using Musify.Application.PlayLists.Contracts;
|
||||
namespace Musify.Application.PlayLists.Commands.UpdatePlayList
|
||||
{
|
||||
public class UpdatePlayListCommandHandler(IPublishEndpoint publishEndpoint, IDatabase database, IStorageHandler storageHandler,
|
||||
ILogger<UpdatePlayListCommandHandler> logger, StorageConfiguration storageConfiguration, PlayListConfiguration playListConfiguration)
|
||||
ILogger<UpdatePlayListCommandHandler> logger, StorageSettings storageConfiguration, PlayListConfiguration playListConfiguration)
|
||||
: IRequestHandler<UpdatePlayListCommand, Task<Result<PlayListResponse>> >
|
||||
{
|
||||
public async Task<Result<PlayListResponse>> Handle(UpdatePlayListCommand request, CancellationToken cancellationToken)
|
||||
@@ -40,7 +40,7 @@ namespace Musify.Application.PlayLists.Commands.UpdatePlayList
|
||||
{
|
||||
database.PlayLists.Update(playList);
|
||||
await database.SaveChangesAsync(cancellationToken);
|
||||
logger.LogInformation("Updated PlayList with id={PlayListId}.", playList.Id);
|
||||
logger.LogInformation("Updated PlayList with id={PlayListId} without picture changes.", playList.Id);
|
||||
return Result.Success(PlayListResponse.FromEntity(playList));
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ namespace Musify.Application.PlayLists.Commands.UpdatePlayList
|
||||
return Result.Error($"Failed to upload picture for PlayList with Id {playList.Id} to storage.");
|
||||
}
|
||||
|
||||
playList.OriginalPictureKeyName = newImageId.ToString();
|
||||
playList.OriginalPictureKeyName = imageKeyName;
|
||||
await publishEndpoint.Publish(new ResizePictureEvent(
|
||||
storageConfiguration.BucketName,
|
||||
imageKeyName,
|
||||
@@ -108,7 +108,7 @@ namespace Musify.Application.PlayLists.Commands.UpdatePlayList
|
||||
database.PlayLists.Update(playList);
|
||||
await database.SaveChangesAsync(cancellationToken);
|
||||
|
||||
logger.LogInformation("Updated PlayList with id={PlayListId}.", playList.Id);
|
||||
logger.LogInformation("Updated PlayList with id={PlayListId} and picture key {PictureKeyName}.", playList.Id, imageKeyName);
|
||||
return Result.Success(PlayListResponse.FromEntity(playList));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,15 +15,21 @@ namespace Musify.Application.Users.Commands.CreateUser
|
||||
{
|
||||
logger.LogDebug("Handling {CommandName} with Id: {UserId}", nameof(CreateUserCommand), request.Id);
|
||||
|
||||
var existingUser = database.Users.SingleOrDefaultAsync(u => u.Id == request.Id, cancellationToken);
|
||||
var existingUser = await database.Users.SingleOrDefaultAsync(u => u.Id == request.Id, cancellationToken);
|
||||
|
||||
if (existingUser is not null)
|
||||
{
|
||||
logger.LogInformation("User with Id={UserId} already exists.", request.Id);
|
||||
return Result<UserResponse>.Conflict($"A user with Id {request.Id} already exists.");
|
||||
}
|
||||
|
||||
var keycloakUser = await keycloakUserClient.GetUserByIdAsync(request.Id.ToString(), cancellationToken);
|
||||
|
||||
if (!keycloakUser.IsSuccess)
|
||||
{
|
||||
logger.LogWarning("Keycloak user with Id={UserId} was not found.", request.Id);
|
||||
return Result.NotFound("Keycloak user not found.");
|
||||
}
|
||||
|
||||
var newUser = new User
|
||||
{
|
||||
@@ -31,9 +37,9 @@ namespace Musify.Application.Users.Commands.CreateUser
|
||||
};
|
||||
|
||||
await database.Users.AddAsync(newUser, cancellationToken);
|
||||
|
||||
await database.SaveChangesAsync(cancellationToken);
|
||||
|
||||
logger.LogInformation("User with Id={UserId} created successfully.", newUser.Id);
|
||||
return Result.Created(new UserResponse(
|
||||
newUser.Id.ToString(),
|
||||
keycloakUser.Value.Name,
|
||||
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
using Ardalis.Result;
|
||||
using Ardalis.Result;
|
||||
using DispatchR.Abstractions.Send;
|
||||
using Musify.Application.Users.Contracts;
|
||||
|
||||
@@ -6,4 +6,4 @@ namespace Musify.Application.Users.Queries.GetUserByKeycloakId
|
||||
{
|
||||
public record GetUserByKeycloakQuery(Guid Id)
|
||||
: IRequest<GetUserByKeycloakQuery, Task<Result<UserResponse> >>;
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
using Ardalis.Result;
|
||||
using Ardalis.Result;
|
||||
using DispatchR.Abstractions.Send;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Musify.Application.Contracts.Infrastructure;
|
||||
@@ -32,4 +32,4 @@ namespace Musify.Application.Users.Queries.GetUserByKeycloakId
|
||||
user.UpdatedAt));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
using Ardalis.Result;
|
||||
using DispatchR.Abstractions.Send;
|
||||
using Musify.Application.Users.Contracts;
|
||||
|
||||
namespace Musify.Application.Users.Queries.GetUsers
|
||||
{
|
||||
public record GetUsersCommand(int PageNumber, int PageSize, string UsernameSearch)
|
||||
: IRequest<GetUsersCommand, Task<Result<PaginatedUserResponse>> >;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using Ardalis.Result;
|
||||
using DispatchR.Abstractions.Send;
|
||||
using Musify.Application.Users.Contracts;
|
||||
|
||||
namespace Musify.Application.Users.Queries.GetUsers
|
||||
{
|
||||
public record GetUsersQuery(int PageNumber, int PageSize, string UsernameSearch)
|
||||
: IRequest<GetUsersQuery, Task<Result<PaginatedUserResponse>> >;
|
||||
}
|
||||
+4
-4
@@ -1,4 +1,4 @@
|
||||
using Ardalis.Result;
|
||||
using Ardalis.Result;
|
||||
using DispatchR.Abstractions.Send;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Musify.Application.Contracts.Infrastructure;
|
||||
@@ -9,9 +9,9 @@ using X.PagedList.Extensions;
|
||||
namespace Musify.Application.Users.Queries.GetUsers
|
||||
{
|
||||
public class GetUsersQueryHandler(IDatabase database, IKeycloakUserClient keycloakUserClient)
|
||||
: IRequestHandler<GetUsersCommand, Task<Result<PaginatedUserResponse> >>
|
||||
: IRequestHandler<GetUsersQuery, Task<Result<PaginatedUserResponse> >>
|
||||
{
|
||||
public async Task<Result<PaginatedUserResponse>> Handle(GetUsersCommand request, CancellationToken cancellationToken)
|
||||
public async Task<Result<PaginatedUserResponse>> Handle(GetUsersQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var pageNumber = request.PageNumber < 1 ? 1 : request.PageNumber;
|
||||
var pageSize = request.PageSize < 1 ? 10 : request.PageSize;
|
||||
@@ -56,4 +56,4 @@ namespace Musify.Application.Users.Queries.GetUsers
|
||||
return Result.Success(response);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user