Unify API route parameters, return IResult everywhere, merge picture upload DTOs and centralize validation limits
Guid and long route constraints, id/trackId parameter names, Update*Request without the New prefix, sentence-case operation summaries, shared security scheme id and a single Limits class.
This commit is contained in:
@@ -1,8 +0,0 @@
|
||||
namespace Musify.Api.Validators.Albums;
|
||||
|
||||
public static class AlbumReleaseYear
|
||||
{
|
||||
public const int Earliest = 1877;
|
||||
|
||||
public static int Latest => DateTime.UtcNow.Year + 1;
|
||||
}
|
||||
@@ -9,13 +9,13 @@ public sealed class CreateAlbumRequestValidator : AbstractValidator<CreateAlbumR
|
||||
{
|
||||
RuleFor(x => x.Title)
|
||||
.NotEmpty()
|
||||
.MaximumLength(200);
|
||||
.MaximumLength(Limits.AlbumTitle);
|
||||
|
||||
RuleFor(x => x.Description)
|
||||
.MaximumLength(256);
|
||||
.MaximumLength(Limits.Description);
|
||||
|
||||
RuleFor(x => x.ReleaseYear)
|
||||
.InclusiveBetween(AlbumReleaseYear.Earliest, AlbumReleaseYear.Latest)
|
||||
.InclusiveBetween(Limits.EarliestReleaseYear, Limits.LatestReleaseYear)
|
||||
.When(x => x.ReleaseYear.HasValue);
|
||||
|
||||
RuleFor(x => x.PictureIntentId)
|
||||
|
||||
@@ -7,15 +7,15 @@ public sealed class UpdateAlbumRequestValidator : AbstractValidator<UpdateAlbumR
|
||||
{
|
||||
public UpdateAlbumRequestValidator()
|
||||
{
|
||||
RuleFor(x => x.NewTitle)
|
||||
RuleFor(x => x.Title)
|
||||
.NotEmpty()
|
||||
.MaximumLength(200);
|
||||
.MaximumLength(Limits.AlbumTitle);
|
||||
|
||||
RuleFor(x => x.NewDescription)
|
||||
.MaximumLength(256);
|
||||
RuleFor(x => x.Description)
|
||||
.MaximumLength(Limits.Description);
|
||||
|
||||
RuleFor(x => x.NewReleaseYear)
|
||||
.InclusiveBetween(AlbumReleaseYear.Earliest, AlbumReleaseYear.Latest)
|
||||
.When(x => x.NewReleaseYear.HasValue);
|
||||
RuleFor(x => x.ReleaseYear)
|
||||
.InclusiveBetween(Limits.EarliestReleaseYear, Limits.LatestReleaseYear)
|
||||
.When(x => x.ReleaseYear.HasValue);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace Musify.Api.Validators;
|
||||
|
||||
public static class Limits
|
||||
{
|
||||
public const int TrackTitle = 200;
|
||||
public const int AlbumTitle = 200;
|
||||
public const int PlayListName = 50;
|
||||
public const int Description = 256;
|
||||
public const int EarliestReleaseYear = 1877;
|
||||
|
||||
public static int LatestReleaseYear => DateTime.UtcNow.Year + 1;
|
||||
}
|
||||
+4
-4
@@ -1,12 +1,12 @@
|
||||
using FluentValidation;
|
||||
using Musify.Api.DataTransferObjects.Albums;
|
||||
using Musify.Api.DataTransferObjects;
|
||||
using Musify.Application.Configuration;
|
||||
|
||||
namespace Musify.Api.Validators.Albums;
|
||||
namespace Musify.Api.Validators;
|
||||
|
||||
public sealed class RequestAlbumPictureUploadRequestValidator : AbstractValidator<RequestAlbumPictureUploadRequest>
|
||||
public sealed class PictureUploadRequestValidator : AbstractValidator<PictureUploadRequest>
|
||||
{
|
||||
public RequestAlbumPictureUploadRequestValidator(UploadIntentConfiguration uploadConfiguration)
|
||||
public PictureUploadRequestValidator(UploadIntentConfiguration uploadConfiguration)
|
||||
{
|
||||
RuleFor(x => x.FileType)
|
||||
.MustBeFileType(Uploads.PictureFileTypes);
|
||||
@@ -9,10 +9,10 @@ public sealed class CreatePlayListRequestValidator : AbstractValidator<CreatePla
|
||||
{
|
||||
RuleFor(x => x.Name)
|
||||
.NotEmpty()
|
||||
.MaximumLength(50);
|
||||
.MaximumLength(Limits.PlayListName);
|
||||
|
||||
RuleFor(x => x.Description)
|
||||
.MaximumLength(256);
|
||||
.MaximumLength(Limits.Description);
|
||||
|
||||
RuleFor(x => x.Visibility)
|
||||
.IsInEnum();
|
||||
|
||||
-20
@@ -1,20 +0,0 @@
|
||||
using FluentValidation;
|
||||
using Musify.Api.DataTransferObjects.PlayLists;
|
||||
using Musify.Application.Configuration;
|
||||
|
||||
namespace Musify.Api.Validators.PlayLists;
|
||||
|
||||
public sealed class RequestPlayListPictureUploadRequestValidator : AbstractValidator<RequestPlayListPictureUploadRequest>
|
||||
{
|
||||
public RequestPlayListPictureUploadRequestValidator(UploadIntentConfiguration uploadConfiguration)
|
||||
{
|
||||
RuleFor(x => x.FileType)
|
||||
.MustBeFileType(Uploads.PictureFileTypes);
|
||||
|
||||
RuleFor(x => x.ContentType)
|
||||
.MustBeContentType(Uploads.PictureContentTypes);
|
||||
|
||||
RuleFor(x => x.ExpectedSizeBytes)
|
||||
.MustBeValidUploadSize(uploadConfiguration.MaxUploadBytes);
|
||||
}
|
||||
}
|
||||
@@ -7,17 +7,17 @@ public sealed class UpdatePlayListRequestValidator : AbstractValidator<UpdatePla
|
||||
{
|
||||
public UpdatePlayListRequestValidator()
|
||||
{
|
||||
RuleFor(x => x.NewName)
|
||||
RuleFor(x => x.Name)
|
||||
.NotEmpty()
|
||||
.MaximumLength(50)
|
||||
.When(x => x.NewName != null);
|
||||
.MaximumLength(Limits.PlayListName)
|
||||
.When(x => x.Name != null);
|
||||
|
||||
RuleFor(x => x.NewDescription)
|
||||
.MaximumLength(256)
|
||||
.When(x => x.NewDescription != null);
|
||||
RuleFor(x => x.Description)
|
||||
.MaximumLength(Limits.Description)
|
||||
.When(x => x.Description != null);
|
||||
|
||||
RuleFor(x => x.NewVisibility)
|
||||
RuleFor(x => x.Visibility)
|
||||
.IsInEnum()
|
||||
.When(x => x.NewVisibility != null);
|
||||
.When(x => x.Visibility != null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ public sealed class CreateTrackRequestValidator : AbstractValidator<CreateTrackR
|
||||
{
|
||||
RuleFor(x => x.Title)
|
||||
.NotEmpty()
|
||||
.MaximumLength(200);
|
||||
.MaximumLength(Limits.TrackTitle);
|
||||
|
||||
RuleFor(x => x.PictureIntentId)
|
||||
.NotEmpty();
|
||||
|
||||
Reference in New Issue
Block a user