Media poster methods added
This commit is contained in:
@@ -24,6 +24,7 @@ public class MediaPhotoRequest : MediaPhoto
|
||||
item.MediaId = MediaId;
|
||||
item.Image = Image;
|
||||
item.MimeType = MimeType;
|
||||
item.UploadDate = DateTime.Now;
|
||||
}
|
||||
|
||||
public void UpdateMediaPhotoImageBackground(MediaPhotoImageBackground item)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace WatchIt.Common.Model.Media;
|
||||
|
||||
public class MediaPosterImage
|
||||
public abstract class MediaPoster
|
||||
{
|
||||
[JsonPropertyName("image")]
|
||||
public required byte[] Image { get; set; }
|
||||
@@ -0,0 +1,19 @@
|
||||
using WatchIt.Database.Model.Media;
|
||||
|
||||
namespace WatchIt.Common.Model.Media;
|
||||
|
||||
public class MediaPosterRequest : MediaPoster
|
||||
{
|
||||
public MediaPosterImage CreateMediaPosterImage() => new MediaPosterImage
|
||||
{
|
||||
Image = Image,
|
||||
MimeType = MimeType,
|
||||
};
|
||||
|
||||
public void UpdateMediaPosterImage(MediaPosterImage item)
|
||||
{
|
||||
item.Image = Image;
|
||||
item.MimeType = MimeType;
|
||||
item.UploadDate = DateTime.Now;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json.Serialization;
|
||||
using WatchIt.Database.Model.Media;
|
||||
|
||||
namespace WatchIt.Common.Model.Media;
|
||||
|
||||
public class MediaPosterResponse : MediaPoster
|
||||
{
|
||||
#region PROPERTIES
|
||||
|
||||
[JsonPropertyName("id")]
|
||||
public Guid Id { get; set; }
|
||||
|
||||
[JsonPropertyName("upload_date")]
|
||||
public DateTime UploadDate { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region CONSTRUCTORS
|
||||
|
||||
[JsonConstructor]
|
||||
public MediaPosterResponse() {}
|
||||
|
||||
[SetsRequiredMembers]
|
||||
public MediaPosterResponse(MediaPosterImage mediaPhotoImage)
|
||||
{
|
||||
Id = mediaPhotoImage.Id;
|
||||
Image = mediaPhotoImage.Image;
|
||||
MimeType = mediaPhotoImage.MimeType;
|
||||
UploadDate = mediaPhotoImage.UploadDate;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -7,7 +7,7 @@ public class HttpResponse
|
||||
{
|
||||
#region FIELDS
|
||||
|
||||
private HttpResponseMessage _message;
|
||||
private readonly HttpResponseMessage _message;
|
||||
|
||||
private Action? _2XXAction;
|
||||
private Action? _400Action;
|
||||
@@ -32,37 +32,37 @@ public class HttpResponse
|
||||
|
||||
#region PUBLIC METHODS
|
||||
|
||||
public HttpResponse RegisterActionFor2XXSuccess(Action action)
|
||||
public HttpResponse RegisterActionFor2XXSuccess(Action? action)
|
||||
{
|
||||
_2XXAction = action;
|
||||
return this;
|
||||
}
|
||||
|
||||
public HttpResponse RegisterActionFor2XXSuccess<T>(Action<T> action)
|
||||
public HttpResponse RegisterActionFor2XXSuccess<T>(Action<T>? action)
|
||||
{
|
||||
_2XXAction = () => Invoke(action);
|
||||
return this;
|
||||
}
|
||||
|
||||
public HttpResponse RegisterActionFor400BadRequest(Action<IDictionary<string, string[]>> action)
|
||||
public HttpResponse RegisterActionFor400BadRequest(Action<IDictionary<string, string[]>>? action)
|
||||
{
|
||||
_400Action = () => Invoke(action);
|
||||
return this;
|
||||
}
|
||||
|
||||
public HttpResponse RegisterActionFor401Unauthorized(Action action)
|
||||
public HttpResponse RegisterActionFor401Unauthorized(Action? action)
|
||||
{
|
||||
_401Action = action;
|
||||
return this;
|
||||
}
|
||||
|
||||
public HttpResponse RegisterActionFor403Forbidden(Action action)
|
||||
public HttpResponse RegisterActionFor403Forbidden(Action? action)
|
||||
{
|
||||
_403Action = action;
|
||||
return this;
|
||||
}
|
||||
|
||||
public HttpResponse RegisterActionFor404NotFound(Action action)
|
||||
public HttpResponse RegisterActionFor404NotFound(Action? action)
|
||||
{
|
||||
_404Action = action;
|
||||
return this;
|
||||
@@ -86,21 +86,21 @@ public class HttpResponse
|
||||
|
||||
#region PRIVATE METHODS
|
||||
|
||||
private async void Invoke<T>(Action<T> action)
|
||||
private async void Invoke<T>(Action<T>? action)
|
||||
{
|
||||
Stream streamData = await _message.Content.ReadAsStreamAsync();
|
||||
T? data = await JsonSerializer.DeserializeAsync<T>(streamData);
|
||||
action.Invoke(data!);
|
||||
action?.Invoke(data!);
|
||||
}
|
||||
|
||||
private async void Invoke(Action<IDictionary<string, string[]>> action)
|
||||
private async void Invoke(Action<IDictionary<string, string[]>>? action)
|
||||
{
|
||||
Stream streamData = await _message.Content.ReadAsStreamAsync();
|
||||
ValidationProblemDetails? data = await JsonSerializer.DeserializeAsync<ValidationProblemDetails>(streamData, new JsonSerializerOptions
|
||||
{
|
||||
PropertyNameCaseInsensitive = true,
|
||||
});
|
||||
action.Invoke(data!.Errors);
|
||||
action?.Invoke(data!.Errors);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user