Refactoring, database structure changed
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
using WatchIt.DTO.Query;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Photos.Photo.Filters;
|
||||
|
||||
public record PhotoIsBackgroundFilter : Filter<Database.Model.Photos.Photo>
|
||||
{
|
||||
public PhotoIsBackgroundFilter(bool? query) : base(x =>
|
||||
(
|
||||
query == null
|
||||
||
|
||||
(x.Background != null) == query
|
||||
)) { }
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using WatchIt.DTO.Query;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Photos.Photo.Filters;
|
||||
|
||||
public record PhotoIsUniversalBackgroundFilter : Filter<Database.Model.Photos.Photo>
|
||||
{
|
||||
public PhotoIsUniversalBackgroundFilter(bool? query) : base(x =>
|
||||
(
|
||||
query == null
|
||||
||
|
||||
(
|
||||
x.Background != null
|
||||
&&
|
||||
x.Background.IsUniversal == query
|
||||
)
|
||||
)) { }
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using WatchIt.DTO.Query;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Photos.Photo.Filters;
|
||||
|
||||
public record PhotoMediumIdFilter : Filter<Database.Model.Photos.Photo>
|
||||
{
|
||||
public PhotoMediumIdFilter(long? query) : base(x =>
|
||||
(
|
||||
query == null
|
||||
||
|
||||
x.MediumId == query
|
||||
)) { }
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System.Text.RegularExpressions;
|
||||
using WatchIt.DTO.Query;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Photos.Photo.Filters;
|
||||
|
||||
public record PhotoMimeTypeFilter : Filter<Database.Model.Photos.Photo>
|
||||
{
|
||||
public PhotoMimeTypeFilter(string? queryRegex) : base(x =>
|
||||
(
|
||||
string.IsNullOrWhiteSpace(queryRegex)
|
||||
||
|
||||
(
|
||||
!string.IsNullOrWhiteSpace(x.MimeType)
|
||||
&&
|
||||
Regex.IsMatch(x.MimeType, queryRegex, RegexOptions.IgnoreCase)
|
||||
)
|
||||
)) { }
|
||||
};
|
||||
@@ -0,0 +1,13 @@
|
||||
using WatchIt.DTO.Query;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Photos.Photo.Filters;
|
||||
|
||||
public record PhotoUploadDateFromFilter : Filter<Database.Model.Photos.Photo>
|
||||
{
|
||||
public PhotoUploadDateFromFilter(DateOnly? query) : base(x =>
|
||||
(
|
||||
query == null
|
||||
||
|
||||
x.UploadDate.DateTime.CompareTo(query.Value) >= 0
|
||||
)) { }
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using WatchIt.DTO.Query;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Photos.Photo.Filters;
|
||||
|
||||
public record PhotoUploadDateToFilter : Filter<Database.Model.Photos.Photo>
|
||||
{
|
||||
public PhotoUploadDateToFilter(DateOnly? query) : base(x =>
|
||||
(
|
||||
query == null
|
||||
||
|
||||
x.UploadDate.DateTime.CompareTo(query.Value) <= 0
|
||||
)) { }
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Refit;
|
||||
using WatchIt.DTO.Models.Controllers.Photos.Photo.Filters;
|
||||
using WatchIt.DTO.Query;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Photos.Photo;
|
||||
|
||||
public class PhotoFilterQuery : IFilterQuery<Database.Model.Photos.Photo>
|
||||
{
|
||||
#region PROPERTIES
|
||||
|
||||
[FromQuery(Name = "medium_id")]
|
||||
[AliasAs("medium_id")]
|
||||
public long? MediumId { get; set; }
|
||||
|
||||
[FromQuery(Name = "mime_type")]
|
||||
[AliasAs("mime_type")]
|
||||
public string? MimeType { get; set; }
|
||||
|
||||
[FromQuery(Name = "is_background")]
|
||||
[AliasAs("is_background")]
|
||||
public bool? IsBackground { get; set; }
|
||||
|
||||
[FromQuery(Name = "is_universal_background")]
|
||||
[AliasAs("is_universal_background")]
|
||||
public bool? IsUniversalBackground { get; set; }
|
||||
|
||||
[FromQuery(Name = "upload_date_from")]
|
||||
[AliasAs("upload_date_from")]
|
||||
public DateOnly? UploadDateFrom { get; set; }
|
||||
|
||||
[FromQuery(Name = "upload_date_to")]
|
||||
[AliasAs("upload_date_to")]
|
||||
public DateOnly? UploadDateTo { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region PUBLIC METHODS
|
||||
|
||||
public IEnumerable<Filter<Database.Model.Photos.Photo>> GetFilters() =>
|
||||
[
|
||||
new PhotoMediumIdFilter(MediumId),
|
||||
new PhotoMimeTypeFilter(MimeType),
|
||||
new PhotoIsBackgroundFilter(IsBackground),
|
||||
new PhotoIsUniversalBackgroundFilter(IsUniversalBackground),
|
||||
new PhotoUploadDateFromFilter(UploadDateFrom),
|
||||
new PhotoUploadDateToFilter(UploadDateTo),
|
||||
];
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Photos.Photo;
|
||||
|
||||
public static class PhotoOrderKeys
|
||||
{
|
||||
public static readonly Dictionary<string, Expression<Func<Database.Model.Photos.Photo, object?>>> Base = new Dictionary<string, Expression<Func<Database.Model.Photos.Photo, object?>>>
|
||||
{
|
||||
{ "id", x => x.Id },
|
||||
{ "medium_id", x => x.MediumId },
|
||||
{ "mime_type", x => x.MimeType },
|
||||
{ "is_background", x => x.Background != null },
|
||||
{ "is_universal_background", x => x.Background != null && x.Background.IsUniversal }
|
||||
};
|
||||
}
|
||||
14
WatchIt.DTO/Models/Controllers/Photos/Photo/PhotoRequest.cs
Normal file
14
WatchIt.DTO/Models/Controllers/Photos/Photo/PhotoRequest.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using WatchIt.DTO.Models.Controllers.Photos.PhotoBackground;
|
||||
using WatchIt.DTO.Models.Generics.Image;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Photos.Photo;
|
||||
|
||||
public class PhotoRequest : ImageRequest
|
||||
{
|
||||
#region PROPERTIES
|
||||
|
||||
public long MediumId { get; set; }
|
||||
public PhotoBackgroundRequest? BackgroundData { get; set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
15
WatchIt.DTO/Models/Controllers/Photos/Photo/PhotoResponse.cs
Normal file
15
WatchIt.DTO/Models/Controllers/Photos/Photo/PhotoResponse.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using WatchIt.DTO.Models.Controllers.Photos.PhotoBackground;
|
||||
using WatchIt.DTO.Models.Generics.Image;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Photos.Photo;
|
||||
|
||||
public class PhotoResponse : ImageResponse
|
||||
{
|
||||
#region PROPERTIES
|
||||
|
||||
public Guid Id { get; set; }
|
||||
public long MediumId { get; set; }
|
||||
public PhotoBackgroundResponse? Background { get; set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using System.Drawing;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Photos.PhotoBackground;
|
||||
|
||||
public class PhotoBackgroundRequest
|
||||
{
|
||||
#region PROPERTIES
|
||||
|
||||
public bool IsUniversal { get; set; }
|
||||
public Color FirstGradientColor { get; set; }
|
||||
public Color SecondGradientColor { get; set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using System.Drawing;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Photos.PhotoBackground;
|
||||
|
||||
public class PhotoBackgroundResponse
|
||||
{
|
||||
#region PROPERTIES
|
||||
|
||||
public Guid Id { get; set; }
|
||||
public bool IsUniversal { get; set; }
|
||||
public Color FirstGradientColor { get; set; }
|
||||
public Color SecondGradientColor { get; set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
74
WatchIt.DTO/Models/Controllers/Photos/PhotosMappers.cs
Normal file
74
WatchIt.DTO/Models/Controllers/Photos/PhotosMappers.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
using WatchIt.DTO.Models.Controllers.Photos.Photo;
|
||||
using WatchIt.DTO.Models.Controllers.Photos.PhotoBackground;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Photos;
|
||||
|
||||
public static class PhotosMappers
|
||||
{
|
||||
#region PUBLIC METHODS
|
||||
|
||||
#region Photo
|
||||
|
||||
public static Database.Model.Photos.Photo ToEntity(this PhotoRequest request) => new Database.Model.Photos.Photo
|
||||
{
|
||||
MediumId = request.MediumId,
|
||||
Image = request.Image,
|
||||
MimeType = request.MimeType,
|
||||
};
|
||||
|
||||
public static PhotoResponse ToResponse(this Database.Model.Photos.Photo entity) => new PhotoResponse
|
||||
{
|
||||
Id = entity.Id,
|
||||
MediumId = entity.MediumId,
|
||||
Image = entity.Image,
|
||||
MimeType = entity.MimeType,
|
||||
UploadDate = entity.UploadDate,
|
||||
Background = entity.Background?.ToResponse()
|
||||
};
|
||||
|
||||
public static PhotoRequest ToRequest(this PhotoResponse response) => new PhotoRequest
|
||||
{
|
||||
Image = response.Image,
|
||||
MimeType = response.MimeType,
|
||||
MediumId = response.MediumId,
|
||||
BackgroundData = response.Background?.ToRequest()
|
||||
};
|
||||
|
||||
#endregion
|
||||
|
||||
#region PhotoBackground
|
||||
|
||||
public static Database.Model.Photos.PhotoBackground ToEntity(this PhotoBackgroundRequest request, Guid photoId) => new Database.Model.Photos.PhotoBackground
|
||||
{
|
||||
PhotoId = photoId,
|
||||
IsUniversal = request.IsUniversal,
|
||||
FirstGradientColor = request.FirstGradientColor,
|
||||
SecondGradientColor = request.SecondGradientColor,
|
||||
};
|
||||
|
||||
public static void UpdateWithRequest(this Database.Model.Photos.PhotoBackground entity, PhotoBackgroundRequest request)
|
||||
{
|
||||
entity.IsUniversal = request.IsUniversal;
|
||||
entity.FirstGradientColor = request.FirstGradientColor;
|
||||
entity.SecondGradientColor = request.SecondGradientColor;
|
||||
}
|
||||
|
||||
public static PhotoBackgroundResponse ToResponse(this Database.Model.Photos.PhotoBackground entity) => new PhotoBackgroundResponse
|
||||
{
|
||||
Id = entity.Id,
|
||||
IsUniversal = entity.IsUniversal,
|
||||
FirstGradientColor = entity.FirstGradientColor,
|
||||
SecondGradientColor = entity.SecondGradientColor,
|
||||
};
|
||||
|
||||
public static PhotoBackgroundRequest ToRequest(this PhotoBackgroundResponse response) => new PhotoBackgroundRequest
|
||||
{
|
||||
IsUniversal = response.IsUniversal,
|
||||
FirstGradientColor = response.FirstGradientColor,
|
||||
SecondGradientColor = response.SecondGradientColor,
|
||||
};
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
}
|
||||
Reference in New Issue
Block a user