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

@@ -1,26 +1,13 @@
using FluentValidation;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using WatchIt.Database;
using WatchIt.Shared.Models.Accounts.Authenticate;
using WatchIt.Common.Model.Accounts;
namespace WatchIt.WebAPI.Validators.Accounts
namespace WatchIt.WebAPI.Validators.Accounts;
public class AuthenticateRequestValidator : AbstractValidator<AuthenticateRequest>
{
public class AuthenticateRequestValidator : AbstractValidator<AuthenticateRequest>
public AuthenticateRequestValidator()
{
#region CONSTRUCTOR
public AuthenticateRequestValidator(DatabaseContext database)
{
RuleFor(x => x.UsernameOrEmail).NotEmpty();
RuleFor(x => x.Password).NotEmpty();
}
#endregion
RuleFor(x => x.UsernameOrEmail).NotEmpty();
RuleFor(x => x.Password).NotEmpty();
}
}
}

View File

@@ -1,31 +1,21 @@
using FluentValidation;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WatchIt.Common.Model.Accounts;
using WatchIt.Database;
using WatchIt.Shared.Models.Accounts.Register;
namespace WatchIt.WebAPI.Validators.Accounts
namespace WatchIt.WebAPI.Validators.Accounts;
public class RegisterRequestValidator : AbstractValidator<RegisterRequest>
{
public class RegisterRequestValidator : AbstractValidator<RegisterRequest>
public RegisterRequestValidator(DatabaseContext database)
{
#region CONSTRUCTOR
public RegisterRequestValidator(DatabaseContext database)
{
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");
RuleFor(x => x.Password).MinimumLength(8)
.Must(x => x.Any(c => Char.IsUpper(c))).WithMessage("Password must contain at least one uppercase letter.")
.Must(x => x.Any(c => Char.IsLower(c))).WithMessage("Password must contain at least one lowercase letter.")
.Must(x => x.Any(c => Char.IsDigit(c))).WithMessage("Password must contain at least one digit.");
}
#endregion
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");
RuleFor(x => x.Password).MinimumLength(8)
.Must(x => x.Any(char.IsUpper)).WithMessage("Password must contain at least one uppercase letter.")
.Must(x => x.Any(char.IsLower)).WithMessage("Password must contain at least one lowercase letter.")
.Must(x => x.Any(char.IsDigit)).WithMessage("Password must contain at least one digit.");
}
}
}

View File

@@ -1,18 +1,11 @@
using FluentValidation;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WatchIt.WebAPI.Validators
namespace WatchIt.WebAPI.Validators;
public static class CustomValidators
{
public static class CustomValidators
{
public static IRuleBuilderOptions<T, TProperty> CannotBeIn<T, TProperty>(this IRuleBuilder<T, TProperty> ruleBuilder, IEnumerable<TProperty> collection) => ruleBuilder.Must(x => !collection.Any(e => Equals(e, x)));
public static IRuleBuilderOptions<T, TProperty> CannotBeIn<T, TProperty, TCollectionType>(this IRuleBuilder<T, TProperty> ruleBuilder, IEnumerable<TCollectionType> collection, Func<TCollectionType, TProperty> propertyFunc) => ruleBuilder.Must(x => !collection.Select(propertyFunc).Any(e => Equals(e, x)));
public static IRuleBuilderOptions<T, TProperty> MustBeIn<T, TProperty>(this IRuleBuilder<T, TProperty> ruleBuilder, IEnumerable<TProperty> collection) => ruleBuilder.Must(x => collection.Any(e => Equals(e, x)));
public static IRuleBuilderOptions<T, TProperty> MustBeIn<T, TProperty, TCollectionType>(this IRuleBuilder<T, TProperty> ruleBuilder, IEnumerable<TCollectionType> collection, Func<TCollectionType, TProperty> propertyFunc) => ruleBuilder.Must(x => collection.Select(propertyFunc).Any(e => Equals(e, x)));
}
}
public static IRuleBuilderOptions<T, TProperty> CannotBeIn<T, TProperty>(this IRuleBuilder<T, TProperty> ruleBuilder, IEnumerable<TProperty> collection) => ruleBuilder.Must(x => !collection.Any(e => Equals(e, x)));
public static IRuleBuilderOptions<T, TProperty> CannotBeIn<T, TProperty, TCollectionType>(this IRuleBuilder<T, TProperty> ruleBuilder, IEnumerable<TCollectionType> collection, Func<TCollectionType, TProperty> propertyFunc) => ruleBuilder.Must(x => !collection.Select(propertyFunc).Any(e => Equals(e, x)));
public static IRuleBuilderOptions<T, TProperty> MustBeIn<T, TProperty>(this IRuleBuilder<T, TProperty> ruleBuilder, IEnumerable<TProperty> collection) => ruleBuilder.Must(x => collection.Any(e => Equals(e, x)));
public static IRuleBuilderOptions<T, TProperty> MustBeIn<T, TProperty, TCollectionType>(this IRuleBuilder<T, TProperty> ruleBuilder, IEnumerable<TCollectionType> collection, Func<TCollectionType, TProperty> propertyFunc) => ruleBuilder.Must(x => collection.Select(propertyFunc).Any(e => Equals(e, x)));
}

View File

@@ -0,0 +1,14 @@
using FluentValidation;
using WatchIt.Common.Model.Genres;
using WatchIt.Database;
namespace WatchIt.WebAPI.Validators.Genres;
public class GenreRequestValidator : AbstractValidator<GenreRequest>
{
public GenreRequestValidator()
{
RuleFor(x => x.Name).MaximumLength(100);
When(x => !string.IsNullOrWhiteSpace(x.Description), () => RuleFor(x => x.Description).MaximumLength(1000));
}
}

View File

@@ -1,19 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FluentValidation" Version="11.9.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\WatchIt.Common\WatchIt.Common.Model\WatchIt.Common.Model.csproj" />
<ProjectReference Include="..\..\WatchIt.Database\WatchIt.Database\WatchIt.Database.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\WatchIt.Database\WatchIt.Database\WatchIt.Database.csproj" />
<ProjectReference Include="..\..\WatchIt.Shared\WatchIt.Shared.Models\WatchIt.Shared.Models.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="FluentValidation" Version="11.9.0" />
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="11.9.0" />
</ItemGroup>
</Project>