Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor project architecture based on tech meeting #113

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/FluentCMS.Application/Dtos/PagingRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace FluentCMS.Application.Dtos;
public class PagingRequest
{
public int PageIndex { get; set; }
public int PageSize { get; set; }
}
6 changes: 6 additions & 0 deletions src/FluentCMS.Application/Dtos/PagingResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace FluentCMS.Application.Dtos;
public class PagingResponse<TData>
{
public IEnumerable<TData> Data { get; set; } = new List<TData>();
public long Total { get; set; }
}
18 changes: 18 additions & 0 deletions src/FluentCMS.Application/Dtos/Sites/AddSiteUrlRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using FluentValidation;

namespace FluentCMS.Application.Dtos.Sites;

public class AddSiteUrlRequest
{
public Guid SiteId { get; set; }
public string NewUrl { get; set; } = "";
}

public class AddSiteUrlRequestValidator : AbstractValidator<AddSiteUrlRequest>
{
public AddSiteUrlRequestValidator()
{
RuleFor(x => x.SiteId).NotEmpty();
RuleFor(x => x.NewUrl).NotEmpty().MaximumLength(50);
}
}
21 changes: 21 additions & 0 deletions src/FluentCMS.Application/Dtos/Sites/CreateSiteRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using FluentValidation;

namespace FluentCMS.Application.Dtos.Sites;

public class CreateSiteRequest
{
public string Name { get; set; } = "";
public string Description { get; set; } = "";
public string[] URLs { get; set; } = [];
public Guid RoleId { get; set; }
}

public class CreateSiteRequestValidator : AbstractValidator<CreateSiteRequest>
{
public CreateSiteRequestValidator()
{
RuleFor(x => x.Name).NotEmpty().MaximumLength(64);
RuleFor(x => x.Description).MaximumLength(100).When(x => string.IsNullOrWhiteSpace(x.Description) == false);
RuleFor(x => x.URLs).NotNull().Must(x => x.Any());
}
}
16 changes: 16 additions & 0 deletions src/FluentCMS.Application/Dtos/Sites/DeleteSiteRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using FluentValidation;

namespace FluentCMS.Application.Dtos.Sites;

public class DeleteSiteRequest
{
public Guid Id { get; set; }
}

public class DeleteSiteRequestValidator : AbstractValidator<DeleteSiteRequest>
{
public DeleteSiteRequestValidator()
{
RuleFor(x => x.Id).NotEmpty();
}
}
23 changes: 23 additions & 0 deletions src/FluentCMS.Application/Dtos/Sites/EditSiteRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using FluentValidation;

namespace FluentCMS.Application.Dtos.Sites;

public class EditSiteRequest
{
public Guid Id { get; set; }
public string Name { get; set; } = "";
public string Description { get; set; } = "";
public Guid RoleId { get; set; }
public ICollection<string> URLs { get; set; } = new List<string>();
}

public class EditSiteRequestValidator : AbstractValidator<EditSiteRequest>
{
public EditSiteRequestValidator()
{
RuleFor(x => x.Id).NotEmpty();
RuleFor(x => x.Name).NotEmpty().MaximumLength(64);
RuleFor(x => x.Description).MaximumLength(100).When(x => string.IsNullOrWhiteSpace(x.Description) == false);
RuleFor(x => x.URLs).NotNull().Must(x => x.Any());
}
}
18 changes: 18 additions & 0 deletions src/FluentCMS.Application/Dtos/Sites/RemoveSiteUrlRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using FluentValidation;

namespace FluentCMS.Application.Dtos.Sites;

public class RemoveSiteUrlRequest
{
public Guid SiteId { get; set; }
public string Url { get; set; } = "";
}

public class RemoveSiteUrlRequestValidator : AbstractValidator<RemoveSiteUrlRequest>
{
public RemoveSiteUrlRequestValidator()
{
RuleFor(x => x.SiteId).NotEmpty();
RuleFor(x => x.Url).NotEmpty().MaximumLength(50);
}
}
4 changes: 4 additions & 0 deletions src/FluentCMS.Application/Dtos/Sites/SearchSiteRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace FluentCMS.Application.Dtos.Sites;
public class SearchSiteRequest : PagingRequest
{
}
4 changes: 4 additions & 0 deletions src/FluentCMS.Application/Dtos/Sites/SearchSiteResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace FluentCMS.Application.Dtos.Sites;
public class SearchSiteResponse : PagingResponse<SiteDto>
{
}
13 changes: 13 additions & 0 deletions src/FluentCMS.Application/Dtos/Sites/SiteDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace FluentCMS.Application.Dtos.Sites;
public class SiteDto
{
public Guid Id { get; set; }
public string CreatedBy { get; set; } = "";
public DateTime CreatedAt { get; set; } = default;
public string LastUpdatedBy { get; set; } = "";
public DateTime LastUpdatedAt { get; set; } = default;
public string Name { get; set; } = "";
public string Description { get; set; } = "";
public List<string> Urls { get; set; } = [];
public Guid RoleId { get; set; }
}
20 changes: 20 additions & 0 deletions src/FluentCMS.Application/Dtos/Users/CreateRoleRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using FluentValidation;

namespace FluentCMS.Application.Dtos.Users;

public class CreateRoleRequest
{
public string Name { get; set; } = string.Empty;
public string? Description { get; set; }
public bool AutoAssigned { get; set; }
public Guid? SiteId { get; set; }
}

public class CreateRoleRequestValidator : AbstractValidator<CreateRoleRequest>
{
public CreateRoleRequestValidator()
{
RuleFor(x => x.Name).NotEmpty().MaximumLength(50);
RuleFor(x => x.Description).MaximumLength(100).When(x => string.IsNullOrWhiteSpace(x.Description) == false);
}
}
21 changes: 21 additions & 0 deletions src/FluentCMS.Application/Dtos/Users/CreateUserRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using FluentValidation;

namespace FluentCMS.Application.Dtos.Users;

public class CreateUserRequest
{
public string Name { get; set; } = string.Empty;
public string Username { get; set; } = string.Empty;
public string Password { get; set; } = string.Empty;
public ICollection<Guid> Roles { get; set; } = new List<Guid>();
}

public class CreateUserRequestValidator : AbstractValidator<CreateUserRequest>
{
public CreateUserRequestValidator()
{
RuleFor(x => x.Name).NotEmpty().MaximumLength(64);
RuleFor(x => x.Username).NotEmpty().MinimumLength(3).MaximumLength(50);
RuleFor(x => x.Password).NotEmpty().MinimumLength(3).MaximumLength(50);
}
}
16 changes: 16 additions & 0 deletions src/FluentCMS.Application/Dtos/Users/DeleteRoleRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using FluentValidation;

namespace FluentCMS.Application.Dtos.Users;

public class DeleteRoleRequest
{
public required Guid Id { get; set; }
}

public class DeleteRoleRequestValidator : AbstractValidator<DeleteRoleRequest>
{
public DeleteRoleRequestValidator()
{
RuleFor(x => x.Id).NotEmpty();
}
}
16 changes: 16 additions & 0 deletions src/FluentCMS.Application/Dtos/Users/DeleteUserRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using FluentValidation;

namespace FluentCMS.Application.Dtos.Users;

public class DeleteUserRequest
{
public Guid Id { get; set; }
}

public class DeleteUserRequestValidator : AbstractValidator<DeleteUserRequest>
{
public DeleteUserRequestValidator()
{
RuleFor(x => x.Id).NotEmpty();
}
}
22 changes: 22 additions & 0 deletions src/FluentCMS.Application/Dtos/Users/EditRoleRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using FluentValidation;

namespace FluentCMS.Application.Dtos.Users;

public class EditRoleRequest
{
public required Guid Id { get; set; }
public required string Name { get; set; }
public string? Description { get; set; }
public required bool AutoAssigned { get; set; }
public Guid? SiteId { get; set; }
}

public class EditRoleRequestValidator : AbstractValidator<EditRoleRequest>
{
public EditRoleRequestValidator()
{
RuleFor(x => x.Id).NotEmpty();
RuleFor(x => x.Name).NotEmpty().MaximumLength(50);
RuleFor(x => x.Description).MaximumLength(100).When(x => string.IsNullOrWhiteSpace(x.Description) == false);
}
}
24 changes: 24 additions & 0 deletions src/FluentCMS.Application/Dtos/Users/EditUserRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using FluentValidation;

namespace FluentCMS.Application.Dtos.Users;

public class EditUserRequest
{
public Guid Id { get; set; }
public string Name { get; set; } = string.Empty;
public string Username { get; set; } = string.Empty;
public string Password { get; set; } = string.Empty;
public ICollection<Guid> Roles { get; set; } = new List<Guid>();
}

public class EditUserRequestValidator : AbstractValidator<EditUserRequest>
{
public EditUserRequestValidator()
{
RuleFor(x => x.Id).NotEmpty();
RuleFor(x => x.Name).NotEmpty().MaximumLength(50);
RuleFor(x => x.Username).NotEmpty().MinimumLength(3).MaximumLength(50);
RuleFor(x => x.Password).MinimumLength(3).MaximumLength(50)
.When(x => string.IsNullOrWhiteSpace(x.Password) == false);
}
}
15 changes: 15 additions & 0 deletions src/FluentCMS.Application/Dtos/Users/RoleDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace FluentCMS.Application.Dtos.Users;
public class RoleDto
{
public required Guid Id { get; set; }
public required string CreatedBy { get; set; }
public required DateTime CreatedAt { get; set; }
public required string LastUpdatedBy { get; set; }
public required DateTime LastUpdatedAt { get; set; }

public required string Name { get; set; }
public string? Description { get; set; }
public required bool AutoAssigned { get; set; }

public Guid? SiteId { get; set; }
}
4 changes: 4 additions & 0 deletions src/FluentCMS.Application/Dtos/Users/SearchRoleRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace FluentCMS.Application.Dtos.Users;
public class SearchRoleRequest : PagingRequest
{
}
4 changes: 4 additions & 0 deletions src/FluentCMS.Application/Dtos/Users/SearchRoleResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace FluentCMS.Application.Dtos.Users;
public class SearchRoleResponse : PagingResponse<RoleDto>
{
}
5 changes: 5 additions & 0 deletions src/FluentCMS.Application/Dtos/Users/SearchUserRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace FluentCMS.Application.Dtos.Users;
public class SearchUserRequest : PagingRequest
{
public string? Name { get; set; }
}
4 changes: 4 additions & 0 deletions src/FluentCMS.Application/Dtos/Users/SearchUserResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace FluentCMS.Application.Dtos.Users;
public class SearchUserResponse : PagingResponse<UserDto>
{
}
14 changes: 14 additions & 0 deletions src/FluentCMS.Application/Dtos/Users/UserDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace FluentCMS.Application.Dtos.Users;
public class UserDto
{
public required Guid Id { get; set; }
public required string CreatedBy { get; set; }
public required DateTime CreatedAt { get; set; }
public required string LastUpdatedBy { get; set; }
public required DateTime LastUpdatedAt { get; set; }

public string Name { get; set; } = string.Empty;
public string Username { get; set; } = string.Empty;

public virtual IEnumerable<Guid> UserRoles { get; set; } = Enumerable.Empty<Guid>();
}
12 changes: 10 additions & 2 deletions src/FluentCMS.Application/Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using FluentCMS.Repository;
using FluentCMS.Application.Services;
using FluentValidation;
using Microsoft.Extensions.DependencyInjection;

namespace FluentCMS.Application;
Expand All @@ -7,7 +8,14 @@ public static class Extensions
public static FluentCMSBuilder AddApplication(this FluentCMSBuilder fcBuilder)
{
// register mediatR
fcBuilder.Services.AddMediatR(c => c.RegisterServicesFromAssembly(typeof(Extensions).Assembly));
fcBuilder.Services.AddScoped<IUserService, UserService>();
fcBuilder.Services.AddScoped<IRoleService, RoleService>();
fcBuilder.Services.AddScoped<ISiteService, SiteService>();
fcBuilder.Services.AddScoped<IContentTypeService, ContentTypeService>();

// register automapper
fcBuilder.Services.AddAutoMapper(typeof(Extensions).Assembly);
fcBuilder.Services.AddValidatorsFromAssembly(typeof(Extensions).Assembly);

return fcBuilder;
}
Expand Down
5 changes: 4 additions & 1 deletion src/FluentCMS.Application/FluentCMS.Application.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MediatR" Version="12.1.1" />
<PackageReference Include="AutoMapper" Version="12.0.1" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
<PackageReference Include="FluentValidation" Version="11.8.0" />
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="11.8.0" />
</ItemGroup>

<ItemGroup>
Expand Down
12 changes: 12 additions & 0 deletions src/FluentCMS.Application/Mappings/SiteMappings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using AutoMapper;
using FluentCMS.Application.Dtos.Sites;
using FluentCMS.Entities.Sites;

namespace FluentCMS.Application.Mappings;
internal class SiteMappings : Profile
{
public SiteMappings()
{
CreateMap<Site, SiteDto>();
}
}
15 changes: 15 additions & 0 deletions src/FluentCMS.Application/Mappings/UserMappingProfile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using AutoMapper;
using FluentCMS.Application.Dtos.Users;
using FluentCMS.Entities.Users;

namespace FluentCMS.Application.Mappings;
internal class UserMappingProfile : Profile
{
public UserMappingProfile()
{
CreateMap<User, UserDto>()
.ForMember(x => x.UserRoles, cfg => cfg.MapFrom(y => y.UserRoles.Select(z => z.RoleId.ToString())));

CreateMap<Role, RoleDto>();
}
}
Loading