Refactoring, database structure changed

This commit is contained in:
2025-03-03 00:56:32 +01:00
Unverified
parent d3805ef3db
commit c603c41c0b
913 changed files with 21764 additions and 32775 deletions

View File

@@ -0,0 +1,58 @@
using Microsoft.AspNetCore.Mvc;
using WatchIt.DTO.Models.Controllers.Accounts.Account.Filters;
using WatchIt.DTO.Query;
namespace WatchIt.DTO.Models.Controllers.Accounts.Account;
public class AccountFilterQuery : IFilterQuery<Database.Model.Accounts.Account>
{
#region PROPERTIES
[FromQuery(Name = "username")]
public string? Username { get; set; }
[FromQuery(Name = "email")]
public string? Email { get; set; }
[FromQuery(Name = "is_admin")]
public bool? IsAdmin { get; set; }
[FromQuery(Name = "active_date_from")]
public DateOnly? ActiveDateFrom { get; set; }
[FromQuery(Name = "active_date_to")]
public DateOnly? ActiveDateTo { get; set; }
[FromQuery(Name = "join_date_from")]
public DateOnly? JoinDateFrom { get; set; }
[FromQuery(Name = "join_date_to")]
public DateOnly? JoinDateTo { get; set; }
[FromQuery(Name = "description")]
public string? Description { get; set; }
[FromQuery(Name = "gender_id")]
public short? GenderId { get; set; }
#endregion
#region PUBLIC METHODS
public IEnumerable<Filter<Database.Model.Accounts.Account>> GetFilters() =>
[
new AccountUsernameFilter(Username),
new AccountEmailFilter(Email),
new AccountIsAdminFilter(IsAdmin),
new AccountActiveDateFromFilter(ActiveDateFrom),
new AccountActiveDateToFilter(ActiveDateTo),
new AccountJoinDateFromFilter(JoinDateFrom),
new AccountJoinDateToFilter(JoinDateTo),
new AccountDescriptionFilter(Description),
new AccountGenderIdFilter(GenderId),
];
#endregion
}

View File

@@ -0,0 +1,18 @@
using System.Linq.Expressions;
namespace WatchIt.DTO.Models.Controllers.Accounts.Account;
public static class AccountOrderKeys
{
public static readonly Dictionary<string, Expression<Func<Database.Model.Accounts.Account, object?>>> Base = new Dictionary<string, Expression<Func<Database.Model.Accounts.Account, object?>>>
{
{ "id", x => x.Id },
{ "username", x => x.Username },
{ "email", x => x.Email },
{ "is_admin", x => x.IsAdmin },
{ "active_date", x => x.ActiveDate },
{ "join_date", x => x.JoinDate },
{ "description", x => x.Description },
{ "gender", x => x.Gender != null ? x.Gender.Name : null },
};
}

View File

@@ -0,0 +1,9 @@
namespace WatchIt.DTO.Models.Controllers.Accounts.Account;
public class AccountRequest : IPasswordEditRequest
{
public string Username { get; set; } = null!;
public string Email { get; set; } = null!;
public string Password { get; set; } = null!;
public string PasswordConfirmation { get; set; } = null!;
}

View File

@@ -0,0 +1,17 @@
using FluentValidation;
using WatchIt.Database;
namespace WatchIt.DTO.Models.Controllers.Accounts.Account;
public class AccountRequestValidator : AbstractValidator<AccountRequest>
{
public AccountRequestValidator(DatabaseContext database)
{
Include(new PasswordEditRequestValidator());
RuleFor(x => x.Username).MinimumLength(5)
.MaximumLength(50)
.CannotBeIn(database.Accounts, x => x.Username).WithMessage("Username was already used");
RuleFor(x => x.Email).EmailAddress()
.CannotBeIn(database.Accounts, x => x.Email).WithMessage("Email was already used");
}
}

View File

@@ -0,0 +1,17 @@
using WatchIt.DTO.Models.Controllers.Genders.Gender;
using WatchIt.DTO.Models.Generics.Image;
namespace WatchIt.DTO.Models.Controllers.Accounts.Account;
public class AccountResponse
{
public long Id { get; set; }
public string Username { get; set; } = null!;
public string Email { get; set; } = null!;
public bool IsAdmin { get; set; }
public DateTimeOffset ActiveDate { get; set; }
public DateTimeOffset JoinDate { get; set; }
public string? Description { get; set; }
public GenderResponse? Gender { get; set; }
public ImageResponse? ProfilePicture { get; set; }
}

View File

@@ -0,0 +1,13 @@
using WatchIt.DTO.Query;
namespace WatchIt.DTO.Models.Controllers.Accounts.Account.Filters;
public record AccountActiveDateFromFilter : Filter<Database.Model.Accounts.Account>
{
public AccountActiveDateFromFilter(DateOnly? query) : base(x =>
(
query == null
||
x.ActiveDate.UtcDateTime.CompareTo(query.Value) >= 0
)) { }
}

View File

@@ -0,0 +1,13 @@
using WatchIt.DTO.Query;
namespace WatchIt.DTO.Models.Controllers.Accounts.Account.Filters;
public record AccountActiveDateToFilter : Filter<Database.Model.Accounts.Account>
{
public AccountActiveDateToFilter(DateOnly? query) : base(x =>
(
query == null
||
x.ActiveDate.UtcDateTime.CompareTo(query.Value) <= 0
)) { }
}

View File

@@ -0,0 +1,18 @@
using System.Text.RegularExpressions;
using WatchIt.DTO.Query;
namespace WatchIt.DTO.Models.Controllers.Accounts.Account.Filters;
public record AccountDescriptionFilter : Filter<Database.Model.Accounts.Account>
{
public AccountDescriptionFilter(string? descriptionRegex) : base(x =>
(
string.IsNullOrWhiteSpace(descriptionRegex)
||
(
!string.IsNullOrWhiteSpace(x.Description)
&&
Regex.IsMatch(x.Description, descriptionRegex, RegexOptions.IgnoreCase)
)
)) { }
}

View File

@@ -0,0 +1,18 @@
using System.Text.RegularExpressions;
using WatchIt.DTO.Query;
namespace WatchIt.DTO.Models.Controllers.Accounts.Account.Filters;
public record AccountEmailFilter : Filter<Database.Model.Accounts.Account>
{
public AccountEmailFilter(string? emailRegex) : base(x =>
(
string.IsNullOrWhiteSpace(emailRegex)
||
(
!string.IsNullOrWhiteSpace(x.Username)
&&
Regex.IsMatch(x.Username, emailRegex, RegexOptions.IgnoreCase)
)
)) { }
}

View File

@@ -0,0 +1,13 @@
using WatchIt.DTO.Query;
namespace WatchIt.DTO.Models.Controllers.Accounts.Account.Filters;
public record AccountGenderIdFilter : Filter<Database.Model.Accounts.Account>
{
public AccountGenderIdFilter(short? genderId) : base(x =>
(
genderId == null
||
x.GenderId == genderId
)) { }
}

View File

@@ -0,0 +1,13 @@
using WatchIt.DTO.Query;
namespace WatchIt.DTO.Models.Controllers.Accounts.Account.Filters;
public record AccountIsAdminFilter : Filter<Database.Model.Accounts.Account>
{
public AccountIsAdminFilter(bool? query) : base(x =>
(
query == null
||
x.IsAdmin == query
)) { }
}

View File

@@ -0,0 +1,13 @@
using WatchIt.DTO.Query;
namespace WatchIt.DTO.Models.Controllers.Accounts.Account.Filters;
public record AccountJoinDateFromFilter : Filter<Database.Model.Accounts.Account>
{
public AccountJoinDateFromFilter(DateOnly? query) : base(x =>
(
query == null
||
x.JoinDate.UtcDateTime.CompareTo(query.Value) >= 0
)) { }
}

View File

@@ -0,0 +1,13 @@
using WatchIt.DTO.Query;
namespace WatchIt.DTO.Models.Controllers.Accounts.Account.Filters;
public record AccountJoinDateToFilter : Filter<Database.Model.Accounts.Account>
{
public AccountJoinDateToFilter(DateOnly? query) : base(x =>
(
query == null
||
x.JoinDate.UtcDateTime.CompareTo(query.Value) <= 0
)) { }
}

View File

@@ -0,0 +1,18 @@
using System.Text.RegularExpressions;
using WatchIt.DTO.Query;
namespace WatchIt.DTO.Models.Controllers.Accounts.Account.Filters;
public record AccountUsernameFilter : Filter<Database.Model.Accounts.Account>
{
public AccountUsernameFilter(string? usernameRegex) : base(x =>
(
string.IsNullOrWhiteSpace(usernameRegex)
||
(
!string.IsNullOrWhiteSpace(x.Username)
&&
Regex.IsMatch(x.Username, usernameRegex, RegexOptions.IgnoreCase)
)
)) { }
}