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

@@ -1,18 +0,0 @@
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; }
}

View File

@@ -1,12 +1,13 @@
using WatchIt.Database.Model.Media;
using WatchIt.Common.Model.Photos;
using WatchIt.Database.Model.Media;
namespace WatchIt.Common.Model.Media;
public class MediaPhotoRequest : MediaPhoto
public class MediaPhotoRequest : Photo
{
public MediaPhotoImage CreateMediaPhotoImage() => new MediaPhotoImage
public MediaPhotoImage CreateMediaPhotoImage(long mediaId) => new MediaPhotoImage
{
MediaId = MediaId,
MediaId = mediaId,
Image = Image,
MimeType = MimeType
};
@@ -18,22 +19,4 @@ public class MediaPhotoRequest : MediaPhoto
FirstGradientColor = Background.FirstGradientColor,
SecondGradientColor = Background.SecondGradientColor
};
public void UpdateMediaPhotoImage(MediaPhotoImage item)
{
item.MediaId = MediaId;
item.Image = Image;
item.MimeType = MimeType;
item.UploadDate = DateTime.Now;
}
public void UpdateMediaPhotoImageBackground(MediaPhotoImageBackground item)
{
if (Background is not null)
{
item.IsUniversalBackground = Background.IsUniversalBackground;
item.FirstGradientColor = Background.FirstGradientColor;
item.SecondGradientColor = Background.SecondGradientColor;
}
}
}

View File

@@ -2,20 +2,8 @@
namespace WatchIt.Common.Model.Media;
public abstract class MediaPoster
public abstract class MediaPoster : Picture
{
#region PROPERTIES
[JsonPropertyName("image")]
public required byte[] Image { get; set; }
[JsonPropertyName("mime_type")]
public required string MimeType { get; set; }
#endregion
#region PUBLIC METHODS
public override string ToString() => $"data:{MimeType};base64,{Convert.ToBase64String(Image)}";

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

@@ -1,9 +1,11 @@
using System.Text.Json.Serialization;
using System.Text.Json.Serialization;
namespace WatchIt.Common.Model.Media;
namespace WatchIt.Common.Model.Photos;
public class MediaPhotoBackground
public class PhotoBackgroundData
{
#region PROPERTIES
[JsonPropertyName("is_universal_background")]
public required bool IsUniversalBackground { get; set; }
@@ -12,4 +14,6 @@ public class MediaPhotoBackground
[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

@@ -1,10 +1,10 @@
using System.Text;
using Microsoft.AspNetCore.Mvc;
using WatchIt.Common.Model.Media;
using WatchIt.Common.Query;
namespace WatchIt.Common.Model.Media;
namespace WatchIt.Common.Model.Photos;
public class MediaPhotoQueryParameters : QueryParameters<MediaPhotoResponse>
public class PhotoQueryParameters : QueryParameters<PhotoResponse>
{
#region PROPERTIES
@@ -17,19 +17,30 @@ public class MediaPhotoQueryParameters : QueryParameters<MediaPhotoResponse>
[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(MediaPhotoResponse item) =>
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

@@ -1,16 +1,19 @@
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.CodeAnalysis;
using System.Text.Json.Serialization;
using WatchIt.Database.Model.Media;
namespace WatchIt.Common.Model.Media;
namespace WatchIt.Common.Model.Photos;
public class MediaPhotoResponse : MediaPhoto
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; }
@@ -21,10 +24,10 @@ public class MediaPhotoResponse : MediaPhoto
#region CONSTRUCTORS
[JsonConstructor]
public MediaPhotoResponse() {}
public PhotoResponse() {}
[SetsRequiredMembers]
public MediaPhotoResponse(MediaPhotoImage mediaPhotoImage)
public PhotoResponse(MediaPhotoImage mediaPhotoImage)
{
Id = mediaPhotoImage.Id;
MediaId = mediaPhotoImage.MediaId;
@@ -34,7 +37,7 @@ public class MediaPhotoResponse : MediaPhoto
if (mediaPhotoImage.MediaPhotoImageBackground is not null)
{
Background = new MediaPhotoBackground
Background = new PhotoBackgroundData
{
IsUniversalBackground = mediaPhotoImage.MediaPhotoImageBackground.IsUniversalBackground,
FirstGradientColor = mediaPhotoImage.MediaPhotoImageBackground.FirstGradientColor,

View File

@@ -0,0 +1,16 @@
using System.Text.Json.Serialization;
namespace WatchIt.Common.Model;
public abstract class Picture
{
#region PROPERTIES
[JsonPropertyName("image")]
public required byte[] Image { get; set; }
[JsonPropertyName("mime_type")]
public required string MimeType { get; set; }
#endregion
}