project reorganized

This commit is contained in:
2024-04-27 22:36:16 +02:00
Unverified
parent fcca2119a5
commit 4b333878b8
233 changed files with 4916 additions and 11471 deletions

View File

@@ -0,0 +1,19 @@
using System.Text.Json.Serialization;
namespace WatchIt.Common.Model.Accounts;
public class AuthenticateRequest
{
#region PROPERTIES
[JsonPropertyName("username_or_email")]
public required string UsernameOrEmail { get; set; }
[JsonPropertyName("password")]
public required string Password { get; set; }
[JsonPropertyName("remember_me")]
public bool RememberMe { get; set; }
#endregion
}

View File

@@ -0,0 +1,16 @@
using System.Text.Json.Serialization;
namespace WatchIt.Common.Model.Accounts;
public class AuthenticateResponse
{
#region PROPERTIES
[JsonPropertyName("access_token")]
public required string AccessToken { get; init; }
[JsonPropertyName("refresh_token")]
public required string RefreshToken { get; init; }
#endregion
}

View File

@@ -0,0 +1,15 @@
using System.Text.Json.Serialization;
namespace WatchIt.Common.Model.Accounts;
public class RegisterRequest
{
[JsonPropertyName("username")]
public required string Username { get; set; }
[JsonPropertyName("email")]
public required string Email { get; set; }
[JsonPropertyName("password")]
public required string Password { get; set; }
}

View File

@@ -0,0 +1,39 @@
using System.Diagnostics.CodeAnalysis;
using System.Text.Json.Serialization;
using WatchIt.Database.Model.Account;
namespace WatchIt.Common.Model.Accounts;
public class RegisterResponse
{
#region PROPERTIES
[JsonPropertyName("id")]
public required long Id { get; init; }
[JsonPropertyName("username")]
public required string Username { get; init; }
[JsonPropertyName("email")]
public required string Email { get; init; }
[JsonPropertyName("creation_date")]
public required DateTime CreationDate { get; init; }
#endregion
#region CONSTRUCTORS
[SetsRequiredMembers]
public RegisterResponse(Account account)
{
Id = account.Id;
Username = account.Username;
Email = account.Email;
CreationDate = account.CreationDate;
}
#endregion
}

View File

@@ -0,0 +1,12 @@
using System.Text.Json.Serialization;
namespace WatchIt.Common.Model.Genres;
public class Genre
{
[JsonPropertyName("name")]
public required string Name { get; set; }
[JsonPropertyName("description")]
public string? Description { get; set; }
}

View File

@@ -0,0 +1,29 @@
using Microsoft.AspNetCore.Mvc;
namespace WatchIt.Common.Model.Genres;
public class GenreQueryParameters : QueryParameters<GenreResponse>
{
#region PROPERTIES
[FromQuery(Name = "name")]
public string? Name { get; set; }
[FromQuery(Name = "description")]
public string? Description { get; set; }
#endregion
#region PUBLIC METHODS
public override bool IsMeetingConditions(GenreResponse item) =>
(
TestString(item.Name, Name)
&&
TestString(item.Description, Description)
);
#endregion
}

View File

@@ -0,0 +1,20 @@
namespace WatchIt.Common.Model.Genres;
public class GenreRequest : Genre
{
#region PUBLIC METHODS
public Database.Model.Common.Genre CreateGenre() => new Database.Model.Common.Genre
{
Name = Name,
Description = Description,
};
public void UpdateGenre(Database.Model.Common.Genre genre)
{
genre.Name = Name;
genre.Description = Description;
}
#endregion
}

View File

@@ -0,0 +1,28 @@
using System.Diagnostics.CodeAnalysis;
using System.Text.Json.Serialization;
namespace WatchIt.Common.Model.Genres;
public class GenreResponse : Genre
{
#region PROPERTIES
[JsonPropertyName("id")]
public long Id { get; set; }
#endregion
#region CONSTRUCTORS
[SetsRequiredMembers]
public GenreResponse(Database.Model.Common.Genre genre)
{
Id = genre.Id;
Name = genre.Name;
Description = genre.Description;
}
#endregion
}

View File

@@ -0,0 +1,24 @@
using System.Text.Json.Serialization;
namespace WatchIt.Common.Model.Movies;
public class Movie
{
[JsonPropertyName("title")]
public required string Title { get; set; }
[JsonPropertyName("original_title")]
public string? OriginalTitle { get; set; }
[JsonPropertyName("description")]
public string? Description { get; set; }
[JsonPropertyName("release_date")]
public DateOnly? ReleaseDate { get; set; }
[JsonPropertyName("length")]
public short? Length { get; set; }
[JsonPropertyName("budget")]
public decimal? Budget { get; set; }
}

View File

@@ -0,0 +1,67 @@
using Microsoft.AspNetCore.Mvc;
namespace WatchIt.Common.Model.Movies;
public class MovieQueryParameters : QueryParameters<MovieResponse>
{
#region PROPERTIES
[FromQuery(Name = "title")]
public string? Title { get; set; }
[FromQuery(Name = "original_title")]
public string? OriginalTitle { get; set; }
[FromQuery(Name = "description")]
public string? Description { get; set; }
[FromQuery(Name = "release_date")]
public DateOnly? ReleaseDate { get; set; }
[FromQuery(Name = "release_date_from")]
public DateOnly? ReleaseDateFrom { get; set; }
[FromQuery(Name = "release_date_to")]
public DateOnly? ReleaseDateTo { get; set; }
[FromQuery(Name = "length")]
public short? Length { get; set; }
[FromQuery(Name = "length_from")]
public short? LengthFrom { get; set; }
[FromQuery(Name = "length_to")]
public short? LengthTo { get; set; }
[FromQuery(Name = "budget")]
public decimal? Budget { get; set; }
[FromQuery(Name = "budget_from")]
public decimal? BudgetFrom { get; set; }
[FromQuery(Name = "budget_to")]
public decimal? BudgetTo { get; set; }
#endregion
#region PUBLIC METHODS
public override bool IsMeetingConditions(MovieResponse item) =>
(
TestString(item.Title, Title)
&&
TestString(item.OriginalTitle, OriginalTitle)
&&
TestString(item.Description, Description)
&&
TestComparable(item.ReleaseDate, ReleaseDate, ReleaseDateFrom, ReleaseDateTo)
&&
TestComparable(item.Length, Length, LengthFrom, LengthTo)
&&
TestComparable(item.Budget, Budget, BudgetFrom, BudgetTo)
);
#endregion
}

View File

@@ -0,0 +1,39 @@
using WatchIt.Database.Model.Media;
namespace WatchIt.Common.Model.Movies;
public class MovieRequest : Movie
{
#region PUBLIC METHODS
public Media CreateMedia() => new Media
{
Title = Title,
OriginalTitle = OriginalTitle,
Description = Description,
ReleaseDate = ReleaseDate,
Length = Length,
};
public MediaMovie CreateMediaMovie(long id) => new MediaMovie
{
Id = id,
Budget = Budget,
};
public void UpdateMedia(Media media)
{
media.Title = Title;
media.OriginalTitle = OriginalTitle;
media.Description = Description;
media.ReleaseDate = ReleaseDate;
media.Length = Length;
}
public void UpdateMediaMovie(MediaMovie mediaMovie)
{
mediaMovie.Budget = Budget;
}
#endregion
}

View File

@@ -0,0 +1,31 @@
using System.Diagnostics.CodeAnalysis;
using WatchIt.Database.Model.Media;
namespace WatchIt.Common.Model.Movies;
public class MovieResponse : Movie
{
#region PROPERTIES
public long Id { get; set; }
#endregion
#region CONSTRUCTORS
[SetsRequiredMembers]
public MovieResponse(MediaMovie mediaMovie)
{
Id = mediaMovie.Media.Id;
Title = mediaMovie.Media.Title;
OriginalTitle = mediaMovie.Media.OriginalTitle;
Description = mediaMovie.Media.Description;
ReleaseDate = mediaMovie.Media.ReleaseDate;
Length = mediaMovie.Media.Length;
Budget = mediaMovie.Budget;
}
#endregion
}

View File

@@ -0,0 +1,118 @@
using System.Reflection;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using Microsoft.AspNetCore.Mvc;
namespace WatchIt.Common.Model;
public abstract class QueryParameters<T> where T : class
{
#region PROPERTIES
[FromQuery(Name = "order_by")]
public string? OrderBy { get; set; }
[FromQuery(Name = "order")]
public string? Order { get; set; }
[FromQuery(Name = "first")]
public int? First { get; set; }
[FromQuery(Name = "after")]
public int? After { get; set; }
#endregion
#region PUBLIC METHODS
public abstract bool IsMeetingConditions(T item);
public IEnumerable<T> PrepareData(IEnumerable<T> data)
{
data = data.Where(IsMeetingConditions);
if (OrderBy is not null)
{
PropertyInfo[] properties = typeof(T).GetProperties();
foreach (PropertyInfo property in properties)
{
JsonPropertyNameAttribute? attribute = property.GetCustomAttributes<JsonPropertyNameAttribute>(true).FirstOrDefault();
if (attribute is not null && attribute.Name == OrderBy)
{
if (Order == "asc")
{
data = data.OrderBy(property.GetValue);
}
else
{
data = data.OrderByDescending(property.GetValue);
}
break;
}
}
}
if (After is not null)
{
data = data.Skip(After.Value);
}
if (First is not null)
{
data = data.Take(First.Value);
}
return data;
}
#endregion
#region PRIVATE METHODS
protected bool TestString(string? property, string? regexQuery) =>
(
string.IsNullOrEmpty(regexQuery)
||
(
!string.IsNullOrEmpty(property)
&&
new Regex(regexQuery).IsMatch(property)
)
);
protected bool TestComparable(IComparable? property, IComparable? exact, IComparable? from, IComparable? to) =>
(
(
exact is null
||
(
property is not null
&&
property.CompareTo(exact) == 0
)
)
&&
(
from is null
||
(
property is not null
&&
property.CompareTo(from) > 0
)
)
&&
(
to is null
||
(
property is not null
&&
property.CompareTo(to) < 0
)
)
);
#endregion
}

View File

@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\WatchIt.Database\WatchIt.Database.Model\WatchIt.Database.Model\WatchIt.Database.Model.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>
</Project>