Files
WatchIt/WatchIt.Common/WatchIt.Common.Model/Photos/PhotoResponse.cs

62 lines
1.9 KiB
C#
Raw Normal View History

2024-09-25 22:11:28 +02:00
using System.Diagnostics.CodeAnalysis;
2024-07-03 22:18:32 +02:00
using System.Text.Json.Serialization;
2024-09-29 23:00:32 +02:00
using WatchIt.Common.Query;
2024-07-03 22:18:32 +02:00
using WatchIt.Database.Model.Media;
2024-09-25 22:11:28 +02:00
namespace WatchIt.Common.Model.Photos;
2024-07-03 22:18:32 +02:00
2024-09-29 23:00:32 +02:00
public class PhotoResponse : Photo, IQueryOrderable<PhotoResponse>
2024-07-03 22:18:32 +02:00
{
#region PROPERTIES
2024-09-29 23:00:32 +02:00
[JsonIgnore]
public static IDictionary<string, Func<PhotoResponse, IComparable>> OrderableProperties { get; } = new Dictionary<string, Func<PhotoResponse, IComparable>>
{
{ "id", x => x.Id },
{ "media_id", x => x.MediaId },
{ "mime_type", x => x.MimeType },
{ "is_background", x => x.Background is not null },
{ "is_universal_background", x => x.Background is not null && x.Background.IsUniversalBackground }
};
2024-07-03 22:18:32 +02:00
[JsonPropertyName("id")]
public Guid Id { get; set; }
2024-09-25 22:11:28 +02:00
[JsonPropertyName("media_id")]
public required long MediaId { get; set; }
2024-07-03 22:18:32 +02:00
[JsonPropertyName("upload_date")]
public DateTime UploadDate { get; set; }
#endregion
#region CONSTRUCTORS
[JsonConstructor]
2024-09-25 22:11:28 +02:00
public PhotoResponse() {}
2024-07-03 22:18:32 +02:00
[SetsRequiredMembers]
2024-09-25 22:11:28 +02:00
public PhotoResponse(MediaPhotoImage mediaPhotoImage)
2024-07-03 22:18:32 +02:00
{
Id = mediaPhotoImage.Id;
MediaId = mediaPhotoImage.MediaId;
Image = mediaPhotoImage.Image;
MimeType = mediaPhotoImage.MimeType;
UploadDate = mediaPhotoImage.UploadDate;
if (mediaPhotoImage.MediaPhotoImageBackground is not null)
{
2024-09-25 22:11:28 +02:00
Background = new PhotoBackgroundData
2024-07-03 22:18:32 +02:00
{
IsUniversalBackground = mediaPhotoImage.MediaPhotoImageBackground.IsUniversalBackground,
FirstGradientColor = mediaPhotoImage.MediaPhotoImageBackground.FirstGradientColor,
SecondGradientColor = mediaPhotoImage.MediaPhotoImageBackground.SecondGradientColor
};
}
}
#endregion
}