new photos controller created

This commit is contained in:
2024-09-25 22:11:28 +02:00
Unverified
parent bb67186587
commit 9e9e5e1742
36 changed files with 743 additions and 332 deletions

View File

@@ -0,0 +1,13 @@
using System.Text.Json.Serialization;
namespace WatchIt.Common.Model.Photos;
public abstract class Photo : Picture
{
#region PROPERTIES
[JsonPropertyName("background")]
public PhotoBackgroundData? Background { get; set; }
#endregion
}

View File

@@ -0,0 +1,19 @@
using System.Text.Json.Serialization;
namespace WatchIt.Common.Model.Photos;
public class PhotoBackgroundData
{
#region PROPERTIES
[JsonPropertyName("is_universal_background")]
public required bool IsUniversalBackground { get; set; }
[JsonPropertyName("first_gradient_color")]
public required byte[] FirstGradientColor { get; set; }
[JsonPropertyName("second_gradient_color")]
public required byte[] SecondGradientColor { get; set; }
#endregion
}

View File

@@ -0,0 +1,25 @@
using WatchIt.Database.Model.Media;
namespace WatchIt.Common.Model.Photos;
public class PhotoBackgroundDataRequest : PhotoBackgroundData
{
#region PUBLIC METHODS
public MediaPhotoImageBackground CreateMediaPhotoImageBackground(Guid photoId) => new MediaPhotoImageBackground
{
Id = photoId,
IsUniversalBackground = IsUniversalBackground,
FirstGradientColor = FirstGradientColor,
SecondGradientColor = SecondGradientColor,
};
public void UpdateMediaPhotoImageBackground(MediaPhotoImageBackground image)
{
image.IsUniversalBackground = IsUniversalBackground;
image.FirstGradientColor = FirstGradientColor;
image.SecondGradientColor = SecondGradientColor;
}
#endregion
}

View File

@@ -0,0 +1,47 @@
using Microsoft.AspNetCore.Mvc;
using WatchIt.Common.Model.Media;
using WatchIt.Common.Query;
namespace WatchIt.Common.Model.Photos;
public class PhotoQueryParameters : QueryParameters<PhotoResponse>
{
#region PROPERTIES
[FromQuery(Name = "mime_type")]
public string? MimeType { get; set; }
[FromQuery(Name = "is_background")]
public bool? IsBackground { get; set; }
[FromQuery(Name = "is_universal_background")]
public bool? IsUniversalBackground { get; set; }
[FromQuery(Name = "upload_date")]
public DateOnly? UploadDate { get; set; }
[FromQuery(Name = "upload_date_from")]
public DateOnly? UploadDateFrom { get; set; }
[FromQuery(Name = "upload_date_to")]
public DateOnly? UploadDateTo { get; set; }
#endregion
#region PUBLIC METHODS
public override bool IsMeetingConditions(PhotoResponse item) =>
(
TestString(item.MimeType, MimeType)
&&
TestBoolean(item.Background is not null, IsBackground)
&&
TestBoolean(item.Background!.IsUniversalBackground, IsUniversalBackground)
&&
TestComparable(item.UploadDate, UploadDate, UploadDateFrom, UploadDateTo)
);
#endregion
}

View File

@@ -0,0 +1,50 @@
using System.Diagnostics.CodeAnalysis;
using System.Text.Json.Serialization;
using WatchIt.Database.Model.Media;
namespace WatchIt.Common.Model.Photos;
public class PhotoResponse : Photo
{
#region PROPERTIES
[JsonPropertyName("id")]
public Guid Id { get; set; }
[JsonPropertyName("media_id")]
public required long MediaId { get; set; }
[JsonPropertyName("upload_date")]
public DateTime UploadDate { get; set; }
#endregion
#region CONSTRUCTORS
[JsonConstructor]
public PhotoResponse() {}
[SetsRequiredMembers]
public PhotoResponse(MediaPhotoImage mediaPhotoImage)
{
Id = mediaPhotoImage.Id;
MediaId = mediaPhotoImage.MediaId;
Image = mediaPhotoImage.Image;
MimeType = mediaPhotoImage.MimeType;
UploadDate = mediaPhotoImage.UploadDate;
if (mediaPhotoImage.MediaPhotoImageBackground is not null)
{
Background = new PhotoBackgroundData
{
IsUniversalBackground = mediaPhotoImage.MediaPhotoImageBackground.IsUniversalBackground,
FirstGradientColor = mediaPhotoImage.MediaPhotoImageBackground.FirstGradientColor,
SecondGradientColor = mediaPhotoImage.MediaPhotoImageBackground.SecondGradientColor
};
}
}
#endregion
}