basics
This commit is contained in:
18
WatchIt.Common/WatchIt.Common.Model/Media/MediaPhoto.cs
Normal file
18
WatchIt.Common/WatchIt.Common.Model/Media/MediaPhoto.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace WatchIt.Common.Model.Media;
|
||||
|
||||
public class MediaPhoto
|
||||
{
|
||||
[JsonPropertyName("media_id")]
|
||||
public required long MediaId { get; set; }
|
||||
|
||||
[JsonPropertyName("image")]
|
||||
public required byte[] Image { get; set; }
|
||||
|
||||
[JsonPropertyName("mime_type")]
|
||||
public required string MimeType { get; set; }
|
||||
|
||||
[JsonPropertyName("background")]
|
||||
public MediaPhotoBackground? Background { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace WatchIt.Common.Model.Media;
|
||||
|
||||
public class MediaPhotoBackground
|
||||
{
|
||||
[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; }
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using System.Text;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using WatchIt.Common.Query;
|
||||
|
||||
namespace WatchIt.Common.Model.Media;
|
||||
|
||||
public class MediaPhotoQueryParameters : QueryParameters<MediaPhotoResponse>
|
||||
{
|
||||
#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; }
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region PUBLIC METHODS
|
||||
|
||||
public override bool IsMeetingConditions(MediaPhotoResponse item) =>
|
||||
(
|
||||
TestString(item.MimeType, MimeType)
|
||||
&&
|
||||
TestBoolean(item.Background is not null, IsBackground)
|
||||
&&
|
||||
TestBoolean(item.Background!.IsUniversalBackground, IsUniversalBackground)
|
||||
);
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
using WatchIt.Database.Model.Media;
|
||||
|
||||
namespace WatchIt.Common.Model.Media;
|
||||
|
||||
public class MediaPhotoRequest : MediaPhoto
|
||||
{
|
||||
public MediaPhotoImage CreateMediaPhotoImage() => new MediaPhotoImage
|
||||
{
|
||||
MediaId = MediaId,
|
||||
Image = Image,
|
||||
MimeType = MimeType
|
||||
};
|
||||
|
||||
public MediaPhotoImageBackground? CreateMediaPhotoImageBackground(Guid mediaPhotoImageId) => Background is null ? null : new MediaPhotoImageBackground
|
||||
{
|
||||
Id = mediaPhotoImageId,
|
||||
IsUniversalBackground = Background.IsUniversalBackground,
|
||||
FirstGradientColor = Background.FirstGradientColor,
|
||||
SecondGradientColor = Background.SecondGradientColor
|
||||
};
|
||||
|
||||
public void UpdateMediaPhotoImage(MediaPhotoImage item)
|
||||
{
|
||||
item.MediaId = MediaId;
|
||||
item.Image = Image;
|
||||
item.MimeType = MimeType;
|
||||
}
|
||||
|
||||
public void UpdateMediaPhotoImageBackground(MediaPhotoImageBackground item)
|
||||
{
|
||||
if (Background is not null)
|
||||
{
|
||||
item.IsUniversalBackground = Background.IsUniversalBackground;
|
||||
item.FirstGradientColor = Background.FirstGradientColor;
|
||||
item.SecondGradientColor = Background.SecondGradientColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json.Serialization;
|
||||
using WatchIt.Database.Model.Media;
|
||||
|
||||
namespace WatchIt.Common.Model.Media;
|
||||
|
||||
public class MediaPhotoResponse : MediaPhoto
|
||||
{
|
||||
#region PROPERTIES
|
||||
|
||||
[JsonPropertyName("id")]
|
||||
public Guid Id { get; set; }
|
||||
|
||||
[JsonPropertyName("upload_date")]
|
||||
public DateTime UploadDate { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region CONSTRUCTORS
|
||||
|
||||
[JsonConstructor]
|
||||
public MediaPhotoResponse() {}
|
||||
|
||||
[SetsRequiredMembers]
|
||||
public MediaPhotoResponse(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 MediaPhotoBackground
|
||||
{
|
||||
IsUniversalBackground = mediaPhotoImage.MediaPhotoImageBackground.IsUniversalBackground,
|
||||
FirstGradientColor = mediaPhotoImage.MediaPhotoImageBackground.FirstGradientColor,
|
||||
SecondGradientColor = mediaPhotoImage.MediaPhotoImageBackground.SecondGradientColor
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
Reference in New Issue
Block a user