Refactoring, database structure changed
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
namespace WatchIt.DTO.Models.Controllers.Roles;
|
||||
|
||||
public interface IRoleTypeResponse
|
||||
{
|
||||
short Id { get; set; }
|
||||
string Name { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using System.Text.RegularExpressions;
|
||||
using WatchIt.Database.Model.Roles;
|
||||
using WatchIt.DTO.Query;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Roles.Role.Filters;
|
||||
|
||||
public record RoleActorNameFilter : Filter<RoleActor>
|
||||
{
|
||||
public RoleActorNameFilter(string? regexQuery) : base(x =>
|
||||
(
|
||||
string.IsNullOrWhiteSpace(regexQuery)
|
||||
||
|
||||
(
|
||||
!string.IsNullOrWhiteSpace(x.Name)
|
||||
&&
|
||||
Regex.IsMatch(x.Name, regexQuery, RegexOptions.IgnoreCase)
|
||||
)
|
||||
)) { }
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using WatchIt.Database.Model.Roles;
|
||||
using WatchIt.DTO.Query;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Roles.Role.Filters;
|
||||
|
||||
public record RoleActorTypeIdFilter : Filter<RoleActor>
|
||||
{
|
||||
public RoleActorTypeIdFilter(short? query) : base(x =>
|
||||
(
|
||||
query == null
|
||||
||
|
||||
x.ActorTypeId == query
|
||||
)) { }
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using WatchIt.Database.Model.Roles;
|
||||
using WatchIt.DTO.Query;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Roles.Role.Filters;
|
||||
|
||||
public record RoleCreatorTypeIdFilter : Filter<RoleCreator>
|
||||
{
|
||||
public RoleCreatorTypeIdFilter(short? query) : base(x =>
|
||||
(
|
||||
query == null
|
||||
||
|
||||
x.CreatorTypeId == query
|
||||
)) { }
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using WatchIt.DTO.Query;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Roles.Role.Filters;
|
||||
|
||||
public record RoleMediumIdFilter<T> : Filter<T> where T : Database.Model.Roles.Role
|
||||
{
|
||||
public RoleMediumIdFilter(long? query) : base(x =>
|
||||
(
|
||||
query == null
|
||||
||
|
||||
x.MediumId == query
|
||||
)) { }
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using WatchIt.DTO.Query;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Roles.Role.Filters;
|
||||
|
||||
public record RolePersonIdFilter<T> : Filter<T> where T : Database.Model.Roles.Role
|
||||
{
|
||||
public RolePersonIdFilter(long? query) : base(x =>
|
||||
(
|
||||
query == null
|
||||
||
|
||||
x.PersonId == query
|
||||
)) { }
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Refit;
|
||||
using WatchIt.DTO.Models.Controllers.Roles.Role.Filters;
|
||||
using WatchIt.DTO.Query;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Roles.Role.Query;
|
||||
|
||||
public abstract class BaseRoleFilterQuery<T> : IFilterQuery<T> where T : Database.Model.Roles.Role
|
||||
{
|
||||
#region PROPERTIES
|
||||
|
||||
[FromQuery(Name = "person_id")]
|
||||
[AliasAs("person_id")]
|
||||
public long? PersonId { get; set; }
|
||||
|
||||
[FromQuery(Name = "medium_id")]
|
||||
[AliasAs("medium_id")]
|
||||
public long? MediumId { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region PUBLIC METHODS
|
||||
|
||||
public virtual IEnumerable<Filter<T>> GetFilters() =>
|
||||
[
|
||||
new RolePersonIdFilter<T>(PersonId),
|
||||
new RoleMediumIdFilter<T>(MediumId),
|
||||
];
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace WatchIt.DTO.Models.Controllers.Roles.Role.Query;
|
||||
|
||||
public interface IRoleFilterQuery
|
||||
{
|
||||
short? TypeId { get; set; }
|
||||
long? PersonId { get; set; }
|
||||
long? MediumId { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Refit;
|
||||
using WatchIt.Database.Model.Roles;
|
||||
using WatchIt.DTO.Models.Controllers.Roles.Role.Filters;
|
||||
using WatchIt.DTO.Query;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Roles.Role.Query;
|
||||
|
||||
public class RoleActorFilterQuery : BaseRoleFilterQuery<RoleActor>, IRoleFilterQuery
|
||||
{
|
||||
#region PROPERTIES
|
||||
|
||||
[FromQuery(Name = "type_id")]
|
||||
[AliasAs("type_id")]
|
||||
public short? TypeId { get; set; }
|
||||
|
||||
[FromQuery(Name = "name")]
|
||||
[AliasAs("name")]
|
||||
public string? Name { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region PUBLIC METHODS
|
||||
|
||||
public override IEnumerable<Filter<RoleActor>> GetFilters() => base.GetFilters()
|
||||
.Append(new RoleActorTypeIdFilter(TypeId))
|
||||
.Append(new RoleActorNameFilter(Name));
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Refit;
|
||||
using WatchIt.Database.Model.Roles;
|
||||
using WatchIt.DTO.Models.Controllers.Roles.Role.Filters;
|
||||
using WatchIt.DTO.Query;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Roles.Role.Query;
|
||||
|
||||
public class RoleCreatorFilterQuery : BaseRoleFilterQuery<RoleCreator>, IRoleFilterQuery
|
||||
{
|
||||
#region PROPERTIES
|
||||
|
||||
[FromQuery(Name = "type_id")]
|
||||
[AliasAs("type_id")]
|
||||
public short? TypeId { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region PUBLIC METHODS
|
||||
|
||||
public override IEnumerable<Filter<RoleCreator>> GetFilters() => base.GetFilters()
|
||||
.Append(new RoleCreatorTypeIdFilter(TypeId));
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace WatchIt.DTO.Models.Controllers.Roles.Role.Request;
|
||||
|
||||
public class RoleActorRequest : RoleRequest
|
||||
{
|
||||
#region PROPERTIES
|
||||
|
||||
public short TypeId { get; set; }
|
||||
public string Name { get; set; } = null!;
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace WatchIt.DTO.Models.Controllers.Roles.Role.Request;
|
||||
|
||||
public class RoleCreatorRequest : RoleRequest
|
||||
{
|
||||
#region PROPERTIES
|
||||
|
||||
public short TypeId { get; set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace WatchIt.DTO.Models.Controllers.Roles.Role.Request;
|
||||
|
||||
public abstract class RoleRequest
|
||||
{
|
||||
#region PROPERTIES
|
||||
|
||||
public long MediumId { get; set; }
|
||||
public long PersonId { get; set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace WatchIt.DTO.Models.Controllers.Roles.Role.Response;
|
||||
|
||||
public class RoleActorResponse : RoleResponse
|
||||
{
|
||||
#region PROPERTIES
|
||||
|
||||
public string Name { get; set; } = null!;
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
namespace WatchIt.DTO.Models.Controllers.Roles.Role.Response;
|
||||
|
||||
public class RoleCreatorResponse : RoleResponse;
|
||||
@@ -0,0 +1,13 @@
|
||||
namespace WatchIt.DTO.Models.Controllers.Roles.Role.Response;
|
||||
|
||||
public abstract class RoleResponse
|
||||
{
|
||||
#region PROPERTIES
|
||||
|
||||
public Guid Id { get; set; }
|
||||
public long MediumId { get; set; }
|
||||
public long PersonId { get; set; }
|
||||
public short TypeId { get; set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
25
WatchIt.DTO/Models/Controllers/Roles/Role/RoleOrderKeys.cs
Normal file
25
WatchIt.DTO/Models/Controllers/Roles/Role/RoleOrderKeys.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System.Linq.Expressions;
|
||||
using WatchIt.Database.Model.Roles;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Roles.Role;
|
||||
|
||||
public class RoleOrderKeys
|
||||
{
|
||||
public static Dictionary<string, Expression<Func<T, object?>>> Base<T>() where T : Database.Model.Roles.Role => new Dictionary<string, Expression<Func<T, object?>>>
|
||||
{
|
||||
{ "person", item => item.PersonId },
|
||||
{ "medium", item => item.MediumId },
|
||||
{ "medium.release_date", item => item.Medium.ReleaseDate }
|
||||
};
|
||||
|
||||
public static readonly Dictionary<string, Expression<Func<RoleActor, object?>>> RoleActor = new Dictionary<string, Expression<Func<RoleActor, object?>>>
|
||||
{
|
||||
{ "type_id", x => x.ActorTypeId },
|
||||
{ "name", x => x.Name },
|
||||
};
|
||||
|
||||
public static readonly Dictionary<string, Expression<Func<RoleCreator, object?>>> RoleCreator = new Dictionary<string, Expression<Func<RoleCreator, object?>>>
|
||||
{
|
||||
{ "type_id", x => x.CreatorTypeId },
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System.Text.RegularExpressions;
|
||||
using WatchIt.DTO.Query;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Roles.RoleActorType.Filters;
|
||||
|
||||
public record RoleActorTypeNameFilter : Filter<Database.Model.Roles.RoleActorType>
|
||||
{
|
||||
public RoleActorTypeNameFilter(string? nameRegex) : base(x =>
|
||||
(
|
||||
string.IsNullOrWhiteSpace(nameRegex)
|
||||
||
|
||||
(
|
||||
!string.IsNullOrWhiteSpace(x.Name)
|
||||
&&
|
||||
Regex.IsMatch(x.Name, nameRegex, RegexOptions.IgnoreCase)
|
||||
)
|
||||
)) { }
|
||||
};
|
||||
@@ -0,0 +1,26 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using WatchIt.DTO.Models.Controllers.Roles.RoleActorType.Filters;
|
||||
using WatchIt.DTO.Query;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Roles.RoleActorType;
|
||||
|
||||
public class RoleActorTypeFilterQuery : IFilterQuery<Database.Model.Roles.RoleActorType>
|
||||
{
|
||||
#region PROPERTIES
|
||||
|
||||
[FromQuery(Name = "name")]
|
||||
public string? Name { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region PUBLIC METHODS
|
||||
|
||||
public IEnumerable<Filter<Database.Model.Roles.RoleActorType>> GetFilters() =>
|
||||
[
|
||||
new RoleActorTypeNameFilter(Name),
|
||||
];
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Roles.RoleActorType;
|
||||
|
||||
public static class RoleActorTypeOrderKeys
|
||||
{
|
||||
public static readonly Dictionary<string, Expression<Func<Database.Model.Roles.RoleActorType, object?>>> Base = new Dictionary<string, Expression<Func<Database.Model.Roles.RoleActorType, object?>>>
|
||||
{
|
||||
{ "id", x => x.Id },
|
||||
{ "name", x => x.Name },
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace WatchIt.DTO.Models.Controllers.Roles.RoleActorType;
|
||||
|
||||
public class RoleActorTypeRequest
|
||||
{
|
||||
#region PROPERTIES
|
||||
|
||||
public string Name { get; set; } = null!;
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace WatchIt.DTO.Models.Controllers.Roles.RoleActorType;
|
||||
|
||||
public class RoleActorTypeResponse : IRoleTypeResponse
|
||||
{
|
||||
#region PROPERTIES
|
||||
|
||||
public short Id { get; set; }
|
||||
public string Name { get; set; } = null!;
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System.Text.RegularExpressions;
|
||||
using WatchIt.DTO.Query;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Roles.RoleCreatorType.Filters;
|
||||
|
||||
public record RoleCreatorTypeNameFilter : Filter<Database.Model.Roles.RoleCreatorType>
|
||||
{
|
||||
public RoleCreatorTypeNameFilter(string? nameRegex) : base(x =>
|
||||
(
|
||||
string.IsNullOrWhiteSpace(nameRegex)
|
||||
||
|
||||
(
|
||||
!string.IsNullOrWhiteSpace(x.Name)
|
||||
&&
|
||||
Regex.IsMatch(x.Name, nameRegex, RegexOptions.IgnoreCase)
|
||||
)
|
||||
)) { }
|
||||
};
|
||||
@@ -0,0 +1,27 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using WatchIt.DTO.Models.Controllers.Roles.RoleActorType.Filters;
|
||||
using WatchIt.DTO.Models.Controllers.Roles.RoleCreatorType.Filters;
|
||||
using WatchIt.DTO.Query;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Roles.RoleCreatorType;
|
||||
|
||||
public class RoleCreatorTypeFilterQuery : IFilterQuery<Database.Model.Roles.RoleCreatorType>
|
||||
{
|
||||
#region PROPERTIES
|
||||
|
||||
[FromQuery(Name = "name")]
|
||||
public string? Name { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region PUBLIC METHODS
|
||||
|
||||
public IEnumerable<Filter<Database.Model.Roles.RoleCreatorType>> GetFilters() =>
|
||||
[
|
||||
new RoleCreatorTypeNameFilter(Name),
|
||||
];
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Roles.RoleCreatorType;
|
||||
|
||||
public static class RoleCreatorTypeOrderKeys
|
||||
{
|
||||
public static readonly Dictionary<string, Expression<Func<Database.Model.Roles.RoleCreatorType, object?>>> Base = new Dictionary<string, Expression<Func<Database.Model.Roles.RoleCreatorType, object?>>>
|
||||
{
|
||||
{ "id", x => x.Id },
|
||||
{ "name", x => x.Name },
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace WatchIt.DTO.Models.Controllers.Roles.RoleCreatorType;
|
||||
|
||||
public class RoleCreatorTypeRequest
|
||||
{
|
||||
#region PROPERTIES
|
||||
|
||||
public string Name { get; set; } = null!;
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace WatchIt.DTO.Models.Controllers.Roles.RoleCreatorType;
|
||||
|
||||
public class RoleCreatorTypeResponse : IRoleTypeResponse
|
||||
{
|
||||
#region PROPERTIES
|
||||
|
||||
public short Id { get; set; }
|
||||
public string Name { get; set; } = null!;
|
||||
|
||||
#endregion
|
||||
}
|
||||
130
WatchIt.DTO/Models/Controllers/Roles/RolesMappers.cs
Normal file
130
WatchIt.DTO/Models/Controllers/Roles/RolesMappers.cs
Normal file
@@ -0,0 +1,130 @@
|
||||
using WatchIt.Database.Model.Roles;
|
||||
using WatchIt.DTO.Models.Controllers.Roles.Role.Request;
|
||||
using WatchIt.DTO.Models.Controllers.Roles.Role.Response;
|
||||
using WatchIt.DTO.Models.Controllers.Roles.RoleActorType;
|
||||
using WatchIt.DTO.Models.Controllers.Roles.RoleCreatorType;
|
||||
using WatchIt.DTO.Models.Generics.Rating;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Roles;
|
||||
|
||||
public static class RolesMappers
|
||||
{
|
||||
#region PUBLIC METHODS
|
||||
|
||||
#region Roles
|
||||
|
||||
public static RoleActor ToEntity(this RoleActorRequest request)
|
||||
{
|
||||
RoleActor roleActor = new RoleActor();
|
||||
roleActor.SetRoleEntityProperties(request);
|
||||
roleActor.ActorTypeId = request.TypeId;
|
||||
roleActor.Name = request.Name;
|
||||
return roleActor;
|
||||
}
|
||||
|
||||
public static void UpdateWithRequest(this RoleActor entity, RoleActorRequest request)
|
||||
{
|
||||
entity.SetRoleEntityProperties(request);
|
||||
entity.ActorTypeId = request.TypeId;
|
||||
entity.Name = request.Name;
|
||||
}
|
||||
|
||||
public static RoleCreator ToEntity(this RoleCreatorRequest request)
|
||||
{
|
||||
RoleCreator roleActor = new RoleCreator();
|
||||
roleActor.SetRoleEntityProperties(request);
|
||||
roleActor.CreatorTypeId = request.TypeId;
|
||||
return roleActor;
|
||||
}
|
||||
|
||||
public static void UpdateWithRequest(this RoleCreator entity, RoleCreatorRequest request)
|
||||
{
|
||||
entity.SetRoleEntityProperties(request);
|
||||
entity.CreatorTypeId = request.TypeId;
|
||||
}
|
||||
|
||||
public static RoleActorResponse ToResponse(this RoleActor entity)
|
||||
{
|
||||
RoleActorResponse response = new RoleActorResponse();
|
||||
response.SetRoleResponseProperties(entity);
|
||||
response.Name = entity.Name;
|
||||
response.TypeId = entity.ActorTypeId;
|
||||
return response;
|
||||
}
|
||||
|
||||
public static RoleCreatorResponse ToResponse(this RoleCreator entity)
|
||||
{
|
||||
RoleCreatorResponse response = new RoleCreatorResponse();
|
||||
response.SetRoleResponseProperties(entity);
|
||||
response.TypeId = entity.CreatorTypeId;
|
||||
return response;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region RoleRating
|
||||
|
||||
public static RoleRating ToEntity(this RatingRequest request, Guid roleId, long userId)
|
||||
{
|
||||
RoleRating entity = new RoleRating
|
||||
{
|
||||
RoleId = roleId,
|
||||
AccountId = userId
|
||||
};
|
||||
entity.UpdateWithRequest(request);
|
||||
return entity;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region RoleActorType
|
||||
|
||||
public static RoleActorTypeResponse ToResponse(this Database.Model.Roles.RoleActorType entity) => new RoleActorTypeResponse
|
||||
{
|
||||
Id = entity.Id,
|
||||
Name = entity.Name,
|
||||
};
|
||||
|
||||
public static Database.Model.Roles.RoleActorType ToEntity(this RoleActorTypeRequest request) => new Database.Model.Roles.RoleActorType
|
||||
{
|
||||
Name = request.Name,
|
||||
};
|
||||
|
||||
#endregion
|
||||
|
||||
#region RoleCreatorType
|
||||
|
||||
public static RoleCreatorTypeResponse ToResponse(this Database.Model.Roles.RoleCreatorType entity) => new RoleCreatorTypeResponse
|
||||
{
|
||||
Id = entity.Id,
|
||||
Name = entity.Name,
|
||||
};
|
||||
|
||||
public static Database.Model.Roles.RoleCreatorType ToEntity(this RoleCreatorTypeRequest request) => new Database.Model.Roles.RoleCreatorType
|
||||
{
|
||||
Name = request.Name,
|
||||
};
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region PRIVATE METHODS
|
||||
|
||||
private static void SetRoleEntityProperties(this Database.Model.Roles.Role role, RoleRequest request)
|
||||
{
|
||||
role.MediumId = request.MediumId;
|
||||
role.PersonId = request.PersonId;
|
||||
}
|
||||
|
||||
private static void SetRoleResponseProperties(this RoleResponse response, Database.Model.Roles.Role entity)
|
||||
{
|
||||
response.Id = entity.Id;
|
||||
response.PersonId = entity.PersonId;
|
||||
response.MediumId = entity.MediumId;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
Reference in New Issue
Block a user