Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Api/Controllers/EntriesController.cs
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,7 +29,7 @@ public EntriesController(ICurrentUserService currentUserService)
/// <returns></returns>
[RequiresRole(IdentityData.Roles.Staff, IdentityData.Roles.Employee)]
[HttpPost]
public async Task<ActionResult<Result<EntryDto>>> UploadDigitalFile(
public async Task<ActionResult<Result<EntryDto>>> UploadEntry(
[FromForm] UploadDigitalFileRequest request)
{
var currentUser = _currentUserService.GetCurrentUser();
Expand All@@ -50,11 +50,11 @@ public async Task<ActionResult<Result<EntryDto>>> UploadDigitalFile(
});
}

UploadDigitalFile.Command command;
CreateEntry.Command command;

if (request.IsDirectory)
{
command = new UploadDigitalFile.Command()
command = new CreateEntry.Command()
{
CurrentUser = currentUser,
Path = request.Path,
Expand All@@ -72,7 +72,7 @@ public async Task<ActionResult<Result<EntryDto>>> UploadDigitalFile(
var lastDotIndex = request.File.FileName.LastIndexOf(".", StringComparison.Ordinal);
var extension =
request.File.FileName.Substring(lastDotIndex + 1, request.File.FileName.Length - lastDotIndex - 1);
command = new UploadDigitalFile.Command()
command = new CreateEntry.Command()
{
CurrentUser = currentUser,
Path = request.Path,
Expand Down
6 changes: 3 additions & 3 deletions src/Api/Controllers/SharedController.cs
Original file line numberDiff line numberDiff line change
Expand Up@@ -99,11 +99,11 @@ public async Task<ActionResult<Result<EntryDto>>> UploadSharedEntry([
});
}

UploadSharedEntry.Command command;
CreateSharedEntry.Command command;

if (request.IsDirectory)
{
command = new UploadSharedEntry.Command()
command = new CreateSharedEntry.Command()
{
Name = request.Name,
CurrentUser = currentUser,
Expand All@@ -121,7 +121,7 @@ public async Task<ActionResult<Result<EntryDto>>> UploadSharedEntry([
var lastDotIndex = request.File.FileName.LastIndexOf(".", StringComparison.Ordinal);
var extension =
request.File.FileName.Substring(lastDotIndex + 1, request.File.FileName.Length - lastDotIndex - 1);
command = new UploadSharedEntry.Command()
command = new CreateSharedEntry.Command()
{
CurrentUser = currentUser,
EntryId = entryId,
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,19 +14,20 @@

namespace Application.Entries.Commands;

public class UploadDigitalFile {
public class CreateEntry {
public class Validator : AbstractValidator<Command>
{
public Validator()
{
RuleLevelCascadeMode = CascadeMode.Stop;

RuleFor(x => x.Name)
.NotEmpty().WithMessage("Entry's name is required.")
.MaximumLength(256).WithMessage("Name cannot exceed 256 characters.");

RuleFor(x => x.Path)
.NotEmpty().WithMessage("File's path is required.")
.Matches("^(/(?!/)[a-z_.\\-0-9]*)+(?<!/)$|^/$").WithMessage("Invalid path format.");
.NotEmpty().WithMessage("Entry's path is required.")
.Matches("^(/(?!/)[a-z_.\\s\\-0-9]*)+(?<!/)$|^/$").WithMessage("Invalid path format.");
}
}

Expand All@@ -46,9 +47,9 @@ public class Handler : IRequestHandler<Command, EntryDto>
private readonly IApplicationDbContext _context;
private readonly IMapper _mapper;
private readonly IDateTimeProvider _dateTimeProvider;
private readonly ILogger<UploadDigitalFile> _logger;
private readonly ILogger<CreateEntry> _logger;

public Handler(IApplicationDbContext context, IMapper mapper, IDateTimeProvider dateTimeProvider, ILogger<UploadDigitalFile> logger)
public Handler(IApplicationDbContext context, IMapper mapper, IDateTimeProvider dateTimeProvider, ILogger<CreateEntry> logger)
{
_context = context;
_mapper = mapper;
Expand DownExpand Up@@ -122,7 +123,7 @@ public async Task<EntryDto> Handle(Command request, CancellationToken cancellati
await _context.SaveChangesAsync(cancellationToken);
using (Logging.PushProperties(nameof(Entry), entryEntity.Id, request.CurrentUser.Id))
{
_logger.LogUploadDigitalFile(request.CurrentUser.Id.ToString(), entryEntity.Id.ToString());
_logger.LogCreateEntry(request.CurrentUser.Id.ToString(), entryEntity.Id.ToString());
}
return _mapper.Map<EntryDto>(result.Entity);
}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,7 +14,7 @@

namespace Application.Entries.Commands;

public class UploadSharedEntry
public class CreateSharedEntry
{
public class Validator : AbstractValidator<Command>
{
Expand DownExpand Up@@ -42,8 +42,8 @@ public class CommandHandler : IRequestHandler<Command, EntryDto>
private readonly IApplicationDbContext _context;
private readonly IMapper _mapper;
private readonly IDateTimeProvider _dateTimeProvider;
private readonly ILogger<UploadSharedEntry> _logger;
public CommandHandler(IApplicationDbContext context, IMapper mapper, IDateTimeProvider dateTimeProvider, ILogger<UploadSharedEntry> logger)
private readonly ILogger<CreateSharedEntry> _logger;
public CommandHandler(IApplicationDbContext context, IMapper mapper, IDateTimeProvider dateTimeProvider, ILogger<CreateSharedEntry> logger)
{
_context = context;
_mapper = mapper;
Expand DownExpand Up@@ -129,7 +129,7 @@ public async Task<EntryDto> Handle(Command request, CancellationToken cancellati
await _context.SaveChangesAsync(cancellationToken);
using (Logging.PushProperties(nameof(Entry), entity.Id, request.CurrentUser.Id))
{
_logger.LogUploadSharedEntry(request.CurrentUser.Id.ToString(), entity.Id.ToString());
_logger.LogCreateSharedEntry(request.CurrentUser.Id.ToString(), entity.Id.ToString());
}
return _mapper.Map<EntryDto>(result.Entity);
}
Expand Down
13 changes: 13 additions & 0 deletions src/Application/Entries/Commands/UpdateEntry.cs
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,7 @@
using Application.Common.Models.Operations;
using AutoMapper;
using Domain.Entities.Digital;
using FluentValidation;
using MediatR;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
Expand All@@ -14,6 +15,18 @@ namespace Application.Entries.Commands;

public class UpdateEntry
{
public class Validator : AbstractValidator<Command>
{
public Validator()
{
RuleLevelCascadeMode = CascadeMode.Stop;

RuleFor(x => x.Name)
.NotEmpty().WithMessage("Entry's name is required.")
.MaximumLength(256).WithMessage("Name cannot exceed 256 characters.");
}
}

public record Command : IRequest<EntryDto>
{
public Guid CurrentUserId { get; init; }
Expand Down
4 changes: 2 additions & 2 deletions src/Application/Entries/EntryLogExtension.cs
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,10 +19,10 @@ public static partial class EntryLogExtension
public static partial void LogUpdateEntry(this ILogger logger, string userId, string entryId);

[LoggerMessage(Level = LogLevel.Information, Message = EntryLogMessages.UploadDigitalFile, EventId = EventId.Add)]
public static partial void LogUploadDigitalFile(this ILogger logger, string userId, string entryId);
public static partial void LogCreateEntry(this ILogger logger, string userId, string entryId);

[LoggerMessage(Level = LogLevel.Information, Message = EntryLogMessages.UploadSharedEntry, EventId = EventId.Add)]
public static partial void LogUploadSharedEntry(this ILogger logger, string userId, string entryId);
public static partial void LogCreateSharedEntry(this ILogger logger, string userId, string entryId);

[LoggerMessage(Level = LogLevel.Information, Message = EntryLogMessages.DeleteBinEntry, EventId = EventId.Remove)]
public static partial void LogDeleteBinEntry(this ILogger logger, string userId, string entryId);
Expand Down
2 changes: 1 addition & 1 deletion src/Application/Entries/Queries/GetAllEntriesPaginated.cs
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,7 +19,7 @@ public Validator()

RuleFor(x => x.EntryPath)
.NotEmpty().WithMessage("File's path is required.")
.Matches("^(/(?!/)[a-z_.\\-0-9]*)+(?<!/)$|^/$").WithMessage("Invalid path format.");
.Matches("^(/(?!/)[a-z_.\\s\\-0-9]*)+(?<!/)$|^/$").WithMessage("Invalid path format.");
}
}

Expand Down