diff --git a/Core/HyBe.Application/Abstractions/Services/Authentications/IInternalAuthentication.cs b/Core/HyBe.Application/Abstractions/Services/Authentications/IInternalAuthentication.cs new file mode 100644 index 0000000..68c60df --- /dev/null +++ b/Core/HyBe.Application/Abstractions/Services/Authentications/IInternalAuthentication.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HyBe.Application.Abstractions.Services.Authentications +{ + public interface IInternalAuthentication + { + Task LoginAsync(string usernameOrEmail, string password); + Task RefreshTokenLoginAsync(string refreshToken); + } +} diff --git a/Core/HyBe.Application/Abstractions/Services/Configurations/IApplicationService.cs b/Core/HyBe.Application/Abstractions/Services/Configurations/IApplicationService.cs new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/Core/HyBe.Application/Abstractions/Services/Configurations/IApplicationService.cs @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Core/HyBe.Application/Abstractions/Services/IAuthService.cs b/Core/HyBe.Application/Abstractions/Services/IAuthService.cs new file mode 100644 index 0000000..295a6f5 --- /dev/null +++ b/Core/HyBe.Application/Abstractions/Services/IAuthService.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using HyBe.Application.Abstractions.Services.Authentications; + +namespace HyBe.Application.Abstractions.Services +{ + public interface IAuthService : IInternalAuthentication + { + Task PasswordResetAsnyc(string email); + Task VerifyResetTokenAsync(string resetToken, string userId); + } +} diff --git a/Core/HyBe.Application/Abstractions/Services/IAuthorizationEndpointService.cs b/Core/HyBe.Application/Abstractions/Services/IAuthorizationEndpointService.cs new file mode 100644 index 0000000..e69de29 diff --git a/Core/HyBe.Application/Abstractions/Services/IMailService.cs b/Core/HyBe.Application/Abstractions/Services/IMailService.cs new file mode 100644 index 0000000..e69de29 diff --git a/Core/HyBe.Application/Abstractions/Services/IRoleService.cs b/Core/HyBe.Application/Abstractions/Services/IRoleService.cs new file mode 100644 index 0000000..e69de29 diff --git a/Core/HyBe.Application/Abstractions/Services/IUserService.cs b/Core/HyBe.Application/Abstractions/Services/IUserService.cs new file mode 100644 index 0000000..a81e907 --- /dev/null +++ b/Core/HyBe.Application/Abstractions/Services/IUserService.cs @@ -0,0 +1,11 @@ +using HyBe.Application.DTOs.User; +using HyBe.Domain.Entities.Identity; + +namespace HyBe.Application.Abstractions.Services +{ + public interface IUserService + { + Task CreateAsync(CreateUser model); + Task UpdateRefreshTokenAsync(string refreshToken, AppUser user, DateTime accessTokenDate, int addOnAccessTokenDate); + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Abstractions/Token/ITokenHandler.cs b/Core/HyBe.Application/Abstractions/Token/ITokenHandler.cs new file mode 100644 index 0000000..cacfeb7 --- /dev/null +++ b/Core/HyBe.Application/Abstractions/Token/ITokenHandler.cs @@ -0,0 +1,10 @@ +using HyBe.Domain.Entities.Identity; + +namespace HyBe.Application.Abstractions.Token +{ + public interface ITokenHandler + { + DTOs.Token CreateAccessToken(AppUser appUser); + string CreateRefreshToken(); + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/CustomAttributes/AuthorizeDefinitionAttribute.cs b/Core/HyBe.Application/CustomAttributes/AuthorizeDefinitionAttribute.cs new file mode 100644 index 0000000..e69de29 diff --git a/Core/HyBe.Application/DTOs/Configuration/Action.cs b/Core/HyBe.Application/DTOs/Configuration/Action.cs new file mode 100644 index 0000000..e69de29 diff --git a/Core/HyBe.Application/DTOs/Configuration/Menu.cs b/Core/HyBe.Application/DTOs/Configuration/Menu.cs new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/Core/HyBe.Application/DTOs/Configuration/Menu.cs @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Core/HyBe.Application/DTOs/Token.cs b/Core/HyBe.Application/DTOs/Token.cs new file mode 100644 index 0000000..e3f6373 --- /dev/null +++ b/Core/HyBe.Application/DTOs/Token.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.DTOs +{ + public class Token + { + public string AccessToken { get; set; } + public DateTime Expiration { get; set; } + public string RefreshToken { get; set; } + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/DTOs/User/CreateUser.cs b/Core/HyBe.Application/DTOs/User/CreateUser.cs new file mode 100644 index 0000000..d517f03 --- /dev/null +++ b/Core/HyBe.Application/DTOs/User/CreateUser.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.DTOs.User +{ + public class CreateUser + { + public string NameSurname { get; set; } + public string Username { get; set; } + public string Email { get; set; } + public string Password { get; set; } + public string PasswordConfirm { get; set; } + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/DTOs/User/CreateUserResponse.cs b/Core/HyBe.Application/DTOs/User/CreateUserResponse.cs new file mode 100644 index 0000000..602779d --- /dev/null +++ b/Core/HyBe.Application/DTOs/User/CreateUserResponse.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.DTOs.User +{ + public class CreateUserResponse + { + public bool Succeeded { get; set; } + public string Message { get; set; } + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/DTOs/User/ListUser.cs b/Core/HyBe.Application/DTOs/User/ListUser.cs new file mode 100644 index 0000000..e69de29 diff --git a/Core/HyBe.Application/Exceptions/AuthenticationErrorException.cs b/Core/HyBe.Application/Exceptions/AuthenticationErrorException.cs new file mode 100644 index 0000000..7a6c486 --- /dev/null +++ b/Core/HyBe.Application/Exceptions/AuthenticationErrorException.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Exceptions +{ + public class AuthenticationErrorException : Exception + { + public AuthenticationErrorException() :base("Kimlik doğrulama hatası!") + { + } + + public AuthenticationErrorException(string? message) : base(message) + { + } + + public AuthenticationErrorException(string? message, Exception? innerException) : base(message, innerException) + { + } + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Exceptions/NotFoundUserException.cs b/Core/HyBe.Application/Exceptions/NotFoundUserException.cs new file mode 100644 index 0000000..ba27c4e --- /dev/null +++ b/Core/HyBe.Application/Exceptions/NotFoundUserException.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Exceptions +{ + public class NotFoundUserException : Exception + { + public NotFoundUserException() : base("Kullanıcı adı veya şifre hatalı.") + { + } + + public NotFoundUserException(string? message) : base(message) + { + } + + public NotFoundUserException(string? message, Exception? innerException) : base(message, innerException) + { + } + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Exceptions/PasswordChangeFailedException.cs b/Core/HyBe.Application/Exceptions/PasswordChangeFailedException.cs new file mode 100644 index 0000000..8c3375e --- /dev/null +++ b/Core/HyBe.Application/Exceptions/PasswordChangeFailedException.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Exceptions +{ + public class PasswordChangeFailedException : Exception + { + public PasswordChangeFailedException() : base("Şifre güncellenirken bir sorun oluştu.") + { + } + + public PasswordChangeFailedException(string? message) : base(message) + { + } + + public PasswordChangeFailedException(string? message, Exception? innerException) : base(message, innerException) + { + } + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Exceptions/UserCreateFailedException.cs b/Core/HyBe.Application/Exceptions/UserCreateFailedException.cs new file mode 100644 index 0000000..78a0dd7 --- /dev/null +++ b/Core/HyBe.Application/Exceptions/UserCreateFailedException.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Exceptions +{ + public class UserCreateFailedException : Exception + { + public UserCreateFailedException() : base("Kullanıcı oluşturulurken beklenmeyen bir hatayla karşılaşıldı!") + { + } + + public UserCreateFailedException(string? message) : base(message) + { + } + + public UserCreateFailedException(string? message, Exception? innerException) : base(message, innerException) + { + } + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/AssignRoleToUser/AssignRoleToUserCommandHandler.cs b/Core/HyBe.Application/Features/AppUser/Commands/AssignRoleToUser/AssignRoleToUserCommandHandler.cs new file mode 100644 index 0000000..e69de29 diff --git a/Core/HyBe.Application/Features/AppUser/Commands/AssignRoleToUser/AssignRoleToUserCommandRequest.cs b/Core/HyBe.Application/Features/AppUser/Commands/AssignRoleToUser/AssignRoleToUserCommandRequest.cs new file mode 100644 index 0000000..e69de29 diff --git a/Core/HyBe.Application/Features/AppUser/Commands/AssignRoleToUser/AssignRoleToUserCommandResponse.cs b/Core/HyBe.Application/Features/AppUser/Commands/AssignRoleToUser/AssignRoleToUserCommandResponse.cs new file mode 100644 index 0000000..e69de29 diff --git a/Core/HyBe.Application/Features/AppUser/Commands/CreateUser/CreateUserCommandHandler.cs b/Core/HyBe.Application/Features/AppUser/Commands/CreateUser/CreateUserCommandHandler.cs new file mode 100644 index 0000000..5dce92a --- /dev/null +++ b/Core/HyBe.Application/Features/AppUser/Commands/CreateUser/CreateUserCommandHandler.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using HyBe.Application.Abstractions.Services; +using HyBe.Application.DTOs.User; +using MediatR; + +namespace HyBe.Application.Features.AppUser.Commands.CreateUser +{ + public class CreateUserCommandHandler:IRequestHandler + { + readonly IUserService _userService; + public CreateUserCommandHandler(IUserService userService) + { + _userService = userService; + } + + public async Task Handle(CreateUserCommandRequest request, CancellationToken cancellationToken) + { + CreateUserResponse response = await _userService.CreateAsync(new() + { + Email = request.Email, + NameSurname = request.NameSurname, + Password = request.Password, + PasswordConfirm = request.PasswordConfirm, + Username = request.Username, + }); + + return new() + { + Message = response.Message, + Succeeded = response.Succeeded, + }; + + //throw new UserCreateFailedException(); + } + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/CreateUser/CreateUserCommandRequest.cs b/Core/HyBe.Application/Features/AppUser/Commands/CreateUser/CreateUserCommandRequest.cs new file mode 100644 index 0000000..5620932 --- /dev/null +++ b/Core/HyBe.Application/Features/AppUser/Commands/CreateUser/CreateUserCommandRequest.cs @@ -0,0 +1,17 @@ +using MediatR; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Features.AppUser.Commands.CreateUser +{ + public class CreateUserCommandRequest : IRequest + { + public string NameSurname { get; set; } + public string Username { get; set; } + public string Email { get; set; } + public string Password { get; set; } + public string PasswordConfirm { get; set; } + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/CreateUser/CreateUserCommandResponse.cs b/Core/HyBe.Application/Features/AppUser/Commands/CreateUser/CreateUserCommandResponse.cs new file mode 100644 index 0000000..11eabca --- /dev/null +++ b/Core/HyBe.Application/Features/AppUser/Commands/CreateUser/CreateUserCommandResponse.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Features.AppUser.Commands.CreateUser +{ + public class CreateUserCommandResponse + { + public bool Succeeded { get; set; } + public string Message { get; set; } + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandHandler.cs b/Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandHandler.cs new file mode 100644 index 0000000..10b4195 --- /dev/null +++ b/Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandHandler.cs @@ -0,0 +1,24 @@ +using HyBe.Application.Abstractions.Services; +using MediatR; + +namespace HyBe.Application.Features.AppUser.Commands.LoginUser +{ + public class LoginUserCommandHandler : IRequestHandler + { + readonly IAuthService _authService; + public LoginUserCommandHandler(IAuthService authService) + { + _authService = authService; + } + + public async Task Handle(LoginUserCommandRequest request, CancellationToken cancellationToken) + { + var token = await _authService.LoginAsync(request.UsernameOrEmail, request.Password); + return new LoginUserSuccessCommandResponse() + { + Token = token + }; + } + } +} + diff --git a/Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandRequest.cs b/Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandRequest.cs new file mode 100644 index 0000000..8696b75 --- /dev/null +++ b/Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandRequest.cs @@ -0,0 +1,10 @@ +using MediatR; + +namespace HyBe.Application.Features.AppUser.Commands.LoginUser +{ + public class LoginUserCommandRequest : IRequest + { + public string UsernameOrEmail { get; set; } + public string Password { get; set; } + } +} diff --git a/Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandResponse.cs b/Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandResponse.cs new file mode 100644 index 0000000..8aa5145 --- /dev/null +++ b/Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandResponse.cs @@ -0,0 +1,17 @@ +using HyBe.Application.DTOs; + +namespace HyBe.Application.Features.AppUser.Commands.LoginUser +{ + public class LoginUserCommandResponse + { + + } + public class LoginUserSuccessCommandResponse : LoginUserCommandResponse + { + public Token Token { get; set; } + } + public class LoginUserErrorCommandResponse : LoginUserCommandResponse + { + public string Message { get; set; } + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/PasswordReset/PasswordResetCommandHandler.cs b/Core/HyBe.Application/Features/AppUser/Commands/PasswordReset/PasswordResetCommandHandler.cs new file mode 100644 index 0000000..e69de29 diff --git a/Core/HyBe.Application/Features/AppUser/Commands/PasswordReset/PasswordResetCommandRequest.cs b/Core/HyBe.Application/Features/AppUser/Commands/PasswordReset/PasswordResetCommandRequest.cs new file mode 100644 index 0000000..e69de29 diff --git a/Core/HyBe.Application/Features/AppUser/Commands/PasswordReset/PasswordResetCommandResponse.cs b/Core/HyBe.Application/Features/AppUser/Commands/PasswordReset/PasswordResetCommandResponse.cs new file mode 100644 index 0000000..e69de29 diff --git a/Core/HyBe.Application/Features/AppUser/Commands/RefreshTokenLogin/RefreshTokenLoginCommandHandler.cs b/Core/HyBe.Application/Features/AppUser/Commands/RefreshTokenLogin/RefreshTokenLoginCommandHandler.cs new file mode 100644 index 0000000..76e31d3 --- /dev/null +++ b/Core/HyBe.Application/Features/AppUser/Commands/RefreshTokenLogin/RefreshTokenLoginCommandHandler.cs @@ -0,0 +1,29 @@ +using HyBe.Application.Abstractions.Services; +using HyBe.Application.DTOs; +using MediatR; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HyBe.Application.Features.AppUser.Commands.RefreshTokenLogin +{ + public class RefreshTokenLoginCommandHandler : IRequestHandler + { + readonly IAuthService _authService; + public RefreshTokenLoginCommandHandler(IAuthService authService) + { + _authService = authService; + } + + public async Task Handle(RefreshTokenLoginCommandRequest request, CancellationToken cancellationToken) + { + Token token = await _authService.RefreshTokenLoginAsync(request.RefreshToken); + return new() + { + Token = token + }; + } + } +} diff --git a/Core/HyBe.Application/Features/AppUser/Commands/RefreshTokenLogin/RefreshTokenLoginCommandRequest.cs b/Core/HyBe.Application/Features/AppUser/Commands/RefreshTokenLogin/RefreshTokenLoginCommandRequest.cs new file mode 100644 index 0000000..42cabc0 --- /dev/null +++ b/Core/HyBe.Application/Features/AppUser/Commands/RefreshTokenLogin/RefreshTokenLoginCommandRequest.cs @@ -0,0 +1,14 @@ +using MediatR; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HyBe.Application.Features.AppUser.Commands.RefreshTokenLogin +{ + public class RefreshTokenLoginCommandRequest : IRequest + { + public string RefreshToken { get; set; } + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/RefreshTokenLogin/RefreshTokenLoginCommandResponse.cs b/Core/HyBe.Application/Features/AppUser/Commands/RefreshTokenLogin/RefreshTokenLoginCommandResponse.cs new file mode 100644 index 0000000..45d9a4a --- /dev/null +++ b/Core/HyBe.Application/Features/AppUser/Commands/RefreshTokenLogin/RefreshTokenLoginCommandResponse.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using HyBe.Application.DTOs; + +namespace HyBe.Application.Features.AppUser.Commands.RefreshTokenLogin +{ + public class RefreshTokenLoginCommandResponse + { + public Token Token { get; set; } + } +} diff --git a/Core/HyBe.Application/Features/AppUser/Commands/UpdatePassword/UpdatePasswordCommandHandler.cs b/Core/HyBe.Application/Features/AppUser/Commands/UpdatePassword/UpdatePasswordCommandHandler.cs new file mode 100644 index 0000000..e69de29 diff --git a/Core/HyBe.Application/Features/AppUser/Commands/UpdatePassword/UpdatePasswordCommandRequest.cs b/Core/HyBe.Application/Features/AppUser/Commands/UpdatePassword/UpdatePasswordCommandRequest.cs new file mode 100644 index 0000000..e69de29 diff --git a/Core/HyBe.Application/Features/AppUser/Commands/UpdatePassword/UpdatePasswordCommandResponse.cs b/Core/HyBe.Application/Features/AppUser/Commands/UpdatePassword/UpdatePasswordCommandResponse.cs new file mode 100644 index 0000000..e69de29 diff --git a/Core/HyBe.Application/Features/AppUser/Commands/VerifyResetToken/VerifyResetTokenCommandHandler.cs b/Core/HyBe.Application/Features/AppUser/Commands/VerifyResetToken/VerifyResetTokenCommandHandler.cs new file mode 100644 index 0000000..e69de29 diff --git a/Core/HyBe.Application/Features/AppUser/Commands/VerifyResetToken/VerifyResetTokenCommandRequest.cs b/Core/HyBe.Application/Features/AppUser/Commands/VerifyResetToken/VerifyResetTokenCommandRequest.cs new file mode 100644 index 0000000..e69de29 diff --git a/Core/HyBe.Application/Features/AppUser/Commands/VerifyResetToken/VerifyResetTokenCommandResponse.cs b/Core/HyBe.Application/Features/AppUser/Commands/VerifyResetToken/VerifyResetTokenCommandResponse.cs new file mode 100644 index 0000000..e69de29 diff --git a/Core/HyBe.Application/Features/AppUser/Queries/GetAllUsers/GetAllUsersQueryHandler.cs b/Core/HyBe.Application/Features/AppUser/Queries/GetAllUsers/GetAllUsersQueryHandler.cs new file mode 100644 index 0000000..e69de29 diff --git a/Core/HyBe.Application/Features/AppUser/Queries/GetAllUsers/GetAllUsersQueryRequest.cs b/Core/HyBe.Application/Features/AppUser/Queries/GetAllUsers/GetAllUsersQueryRequest.cs new file mode 100644 index 0000000..e69de29 diff --git a/Core/HyBe.Application/Features/AppUser/Queries/GetAllUsers/GetAllUsersQueryResponse.cs b/Core/HyBe.Application/Features/AppUser/Queries/GetAllUsers/GetAllUsersQueryResponse.cs new file mode 100644 index 0000000..e69de29 diff --git a/Core/HyBe.Application/Features/AppUser/Queries/GetRolesToUser/GetRolesToUserQueryHandler.cs b/Core/HyBe.Application/Features/AppUser/Queries/GetRolesToUser/GetRolesToUserQueryHandler.cs new file mode 100644 index 0000000..e69de29 diff --git a/Core/HyBe.Application/Features/AppUser/Queries/GetRolesToUser/GetRolesToUserQueryRequest.cs b/Core/HyBe.Application/Features/AppUser/Queries/GetRolesToUser/GetRolesToUserQueryRequest.cs new file mode 100644 index 0000000..e69de29 diff --git a/Core/HyBe.Application/Features/AppUser/Queries/GetRolesToUser/GetRolesToUserQueryResponse.cs b/Core/HyBe.Application/Features/AppUser/Queries/GetRolesToUser/GetRolesToUserQueryResponse.cs new file mode 100644 index 0000000..e69de29 diff --git a/Core/HyBe.Application/Features/Role/Commands/CreateRole/CreateRoleCommandHandler.cs b/Core/HyBe.Application/Features/Role/Commands/CreateRole/CreateRoleCommandHandler.cs new file mode 100644 index 0000000..e69de29 diff --git a/Core/HyBe.Application/Features/Role/Commands/CreateRole/CreateRoleCommandRequest.cs b/Core/HyBe.Application/Features/Role/Commands/CreateRole/CreateRoleCommandRequest.cs new file mode 100644 index 0000000..e69de29 diff --git a/Core/HyBe.Application/Features/Role/Commands/CreateRole/CreateRoleCommandResponse.cs b/Core/HyBe.Application/Features/Role/Commands/CreateRole/CreateRoleCommandResponse.cs new file mode 100644 index 0000000..e69de29 diff --git a/Core/HyBe.Application/Features/Role/Commands/DeleteRole/DeleteRoleCommandHandler.cs b/Core/HyBe.Application/Features/Role/Commands/DeleteRole/DeleteRoleCommandHandler.cs new file mode 100644 index 0000000..e69de29 diff --git a/Core/HyBe.Application/Features/Role/Commands/DeleteRole/DeleteRoleCommandRequest.cs b/Core/HyBe.Application/Features/Role/Commands/DeleteRole/DeleteRoleCommandRequest.cs new file mode 100644 index 0000000..e69de29 diff --git a/Core/HyBe.Application/Features/Role/Commands/DeleteRole/DeleteRoleCommandResponse.cs b/Core/HyBe.Application/Features/Role/Commands/DeleteRole/DeleteRoleCommandResponse.cs new file mode 100644 index 0000000..e69de29 diff --git a/Core/HyBe.Application/Features/Role/Commands/UpdateRole/UpdateRoleCommandHandler.cs b/Core/HyBe.Application/Features/Role/Commands/UpdateRole/UpdateRoleCommandHandler.cs new file mode 100644 index 0000000..e69de29 diff --git a/Core/HyBe.Application/Features/Role/Commands/UpdateRole/UpdateRoleCommandRequest.cs b/Core/HyBe.Application/Features/Role/Commands/UpdateRole/UpdateRoleCommandRequest.cs new file mode 100644 index 0000000..e69de29 diff --git a/Core/HyBe.Application/Features/Role/Commands/UpdateRole/UpdateRoleCommandResponse.cs b/Core/HyBe.Application/Features/Role/Commands/UpdateRole/UpdateRoleCommandResponse.cs new file mode 100644 index 0000000..e69de29 diff --git a/Core/HyBe.Application/Features/Role/Queries/GetRoleById/GetRoleByIdQueryHandler.cs b/Core/HyBe.Application/Features/Role/Queries/GetRoleById/GetRoleByIdQueryHandler.cs new file mode 100644 index 0000000..30e6afa --- /dev/null +++ b/Core/HyBe.Application/Features/Role/Queries/GetRoleById/GetRoleByIdQueryHandler.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Features.Role.Queries.GetRoleById +{ + public class GetRoleByIdQueryHandler + { + + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/Role/Queries/GetRoleById/GetRoleByIdQueryRequest.cs b/Core/HyBe.Application/Features/Role/Queries/GetRoleById/GetRoleByIdQueryRequest.cs new file mode 100644 index 0000000..e5120a9 --- /dev/null +++ b/Core/HyBe.Application/Features/Role/Queries/GetRoleById/GetRoleByIdQueryRequest.cs @@ -0,0 +1,9 @@ +using MediatR; + +namespace HyBe.Application.Features.Role.Queries.GetRoleById +{ + public class GetRoleByIdQueryRequest : IRequest + { + public string Id { get; set; } + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/Role/Queries/GetRoleById/GetRoleByIdQueryResponse.cs b/Core/HyBe.Application/Features/Role/Queries/GetRoleById/GetRoleByIdQueryResponse.cs new file mode 100644 index 0000000..bda23b8 --- /dev/null +++ b/Core/HyBe.Application/Features/Role/Queries/GetRoleById/GetRoleByIdQueryResponse.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Features.Role.Queries.GetRoleById +{ + public class GetRoleByIdQueryResponse + { + + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/Role/Queries/GetRoles/GetRolesQueryHandler.cs b/Core/HyBe.Application/Features/Role/Queries/GetRoles/GetRolesQueryHandler.cs new file mode 100644 index 0000000..2f5721b --- /dev/null +++ b/Core/HyBe.Application/Features/Role/Queries/GetRoles/GetRolesQueryHandler.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Features.Role.Queries.GetRoles +{ + public class GetRolesQueryHandler + { + + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/Role/Queries/GetRoles/GetRolesQueryRequest.cs b/Core/HyBe.Application/Features/Role/Queries/GetRoles/GetRolesQueryRequest.cs new file mode 100644 index 0000000..7e02c9d --- /dev/null +++ b/Core/HyBe.Application/Features/Role/Queries/GetRoles/GetRolesQueryRequest.cs @@ -0,0 +1,10 @@ +using MediatR; + +namespace HyBe.Application.Features.Role.Queries.GetRoles +{ + public class GetRolesQueryRequest : IRequest + { + public int Page { get; set; } = 0; + public int Size { get; set; } = 5; + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/Role/Queries/GetRoles/GetRolesQueryResponse.cs b/Core/HyBe.Application/Features/Role/Queries/GetRoles/GetRolesQueryResponse.cs new file mode 100644 index 0000000..ea5aa96 --- /dev/null +++ b/Core/HyBe.Application/Features/Role/Queries/GetRoles/GetRolesQueryResponse.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Features.Role.Queries.GetRoles +{ + public class GetRolesQueryResponse + { + + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Helpers/CustomEncoders.cs b/Core/HyBe.Application/Helpers/CustomEncoders.cs new file mode 100644 index 0000000..c564047 --- /dev/null +++ b/Core/HyBe.Application/Helpers/CustomEncoders.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.AspNetCore.WebUtilities; + +namespace HyBe.Application.Helpers +{ + static public class CustomEncoders + { + public static string UrlEncode(this string value) + { + byte[] bytes = Encoding.UTF8.GetBytes(value); + return WebEncoders.Base64UrlEncode(bytes); + } + public static string UrlDecode(this string value) + { + byte[] bytes = WebEncoders.Base64UrlDecode(value); + return Encoding.UTF8.GetString(bytes); + } + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/HyBe.Application.csproj b/Core/HyBe.Application/HyBe.Application.csproj index 08d706a..6eb237b 100644 --- a/Core/HyBe.Application/HyBe.Application.csproj +++ b/Core/HyBe.Application/HyBe.Application.csproj @@ -7,7 +7,7 @@ - + @@ -25,10 +25,7 @@ - - - - + @@ -71,7 +68,6 @@ - diff --git a/Core/HyBe.Domain/Entities/Backtests/Backtest.cs b/Core/HyBe.Domain/Entities/Backtests/Backtest.cs index 01b1b30..f69e97f 100644 --- a/Core/HyBe.Domain/Entities/Backtests/Backtest.cs +++ b/Core/HyBe.Domain/Entities/Backtests/Backtest.cs @@ -1,16 +1,16 @@ using HyBe.Domain.Enums; -using HyBe.SharedKernel.Domain; -namespace HyBe.Domain.Entities.Backtests; -public class Backtest : BaseEntity -{ - public string Name { get; set; } - public Market Market { get; set; } - public OrderType OrderType { get; set; } - public PositionType PositionType { get; set; } - public TrendStrategy TrendStrategy { get; set; } - public int[]? Symbols { get; set; } - public int[]? Strategy { get; set; } - public int[]? Formation { get; set; } - public DateTimeOffset Start { get; set; } - public DateTimeOffset Finish { get; set; } +using HyBe.SharedKernel.Domain; +namespace HyBe.Domain.Entities.Backtests; +public class Backtest : BaseEntity +{ + public string Name { get; set; } + public Market Market { get; set; } + public OrderType OrderType { get; set; } + public PositionType PositionType { get; set; } + public TrendStrategy TrendStrategy { get; set; } + public int[]? Symbols { get; set; } + public int[]? Strategy { get; set; } + public int[]? Formation { get; set; } + public DateTimeOffset Start { get; set; } + public DateTimeOffset Finish { get; set; } } \ No newline at end of file diff --git a/Core/HyBe.Domain/Entities/Identity/AppRole.cs b/Core/HyBe.Domain/Entities/Identity/AppRole.cs new file mode 100644 index 0000000..0a2f0e7 --- /dev/null +++ b/Core/HyBe.Domain/Entities/Identity/AppRole.cs @@ -0,0 +1,10 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Identity; + +namespace HyBe.Domain.Entities.Identity +{ + public class AppRole : IdentityRole + { + public ICollection Endpoints { get; set; } + } +} \ No newline at end of file diff --git a/Core/HyBe.Domain/Entities/Identity/AppUser.cs b/Core/HyBe.Domain/Entities/Identity/AppUser.cs new file mode 100644 index 0000000..778383d --- /dev/null +++ b/Core/HyBe.Domain/Entities/Identity/AppUser.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Identity; + +namespace HyBe.Domain.Entities.Identity +{ + public class AppUser : IdentityUser + { + public string NameSurname { get; set; } + public string? RefreshToken { get; set; } + public DateTime? RefreshTokenEndDate { get; set; } + + } +} \ No newline at end of file diff --git a/Core/HyBe.Domain/Entities/Identity/Endpoint.cs b/Core/HyBe.Domain/Entities/Identity/Endpoint.cs new file mode 100644 index 0000000..2093b1f --- /dev/null +++ b/Core/HyBe.Domain/Entities/Identity/Endpoint.cs @@ -0,0 +1,23 @@ +using HyBe.SharedKernel.Domain; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HyBe.Domain.Entities.Identity +{ + public class Endpoint : BaseEntity + { + public Endpoint() + { + Roles = new HashSet(); + } + public string ActionType { get; set; } + public string HttpType { get; set; } + public string Definition { get; set; } + public string Code { get; set; } + public Menu Menu { get; set; } + public ICollection Roles { get; set; } + } +} diff --git a/Core/HyBe.Domain/Entities/Identity/Menu.cs b/Core/HyBe.Domain/Entities/Identity/Menu.cs new file mode 100644 index 0000000..db07a9e --- /dev/null +++ b/Core/HyBe.Domain/Entities/Identity/Menu.cs @@ -0,0 +1,15 @@ +using HyBe.SharedKernel.Domain; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HyBe.Domain.Entities.Identity +{ + public class Menu : BaseEntity + { + public string Name { get; set; } + public ICollection Endpoints { get; set; } + } +} diff --git a/Core/HyBe.Domain/Enums/ActionType.cs b/Core/HyBe.Domain/Enums/ActionType.cs new file mode 100644 index 0000000..ebfc10a --- /dev/null +++ b/Core/HyBe.Domain/Enums/ActionType.cs @@ -0,0 +1,10 @@ +namespace HyBe.Domain.Enums +{ + public enum ActionType + { + Reading, + Writing, + Updating, + Deleting + } +} \ No newline at end of file diff --git a/Core/HyBe.Domain/HyBe.Domain.csproj b/Core/HyBe.Domain/HyBe.Domain.csproj index 2dabe87..5059972 100644 --- a/Core/HyBe.Domain/HyBe.Domain.csproj +++ b/Core/HyBe.Domain/HyBe.Domain.csproj @@ -1,4 +1,4 @@ - + net7.0 @@ -29,6 +29,14 @@ + + + + + + + diff --git a/Core/HyBe.SharedKernel/HyBe.SharedKernel.csproj b/Core/HyBe.SharedKernel/HyBe.SharedKernel.csproj index 69fd34b..16c656f 100644 --- a/Core/HyBe.SharedKernel/HyBe.SharedKernel.csproj +++ b/Core/HyBe.SharedKernel/HyBe.SharedKernel.csproj @@ -1,4 +1,4 @@ - + net7.0 @@ -25,6 +25,7 @@ + @@ -42,16 +43,19 @@ runtime; build; native; contentfiles; analyzers; buildtransitive all + + - + + diff --git a/Infrastructure/HyBe.Infrastructure/HyBe.Infrastructure.csproj b/Infrastructure/HyBe.Infrastructure/HyBe.Infrastructure.csproj index aed52ba..033f5bc 100644 --- a/Infrastructure/HyBe.Infrastructure/HyBe.Infrastructure.csproj +++ b/Infrastructure/HyBe.Infrastructure/HyBe.Infrastructure.csproj @@ -1,4 +1,4 @@ - + net7.0 @@ -7,7 +7,8 @@ - + + diff --git a/Infrastructure/HyBe.Infrastructure/InfrastructureServiceRegistration.cs b/Infrastructure/HyBe.Infrastructure/InfrastructureServiceRegistration.cs index 62f471c..9de0abe 100644 --- a/Infrastructure/HyBe.Infrastructure/InfrastructureServiceRegistration.cs +++ b/Infrastructure/HyBe.Infrastructure/InfrastructureServiceRegistration.cs @@ -1,6 +1,12 @@ using System; using HyBe.Application.Abstractions.Infrastructure; +using HyBe.Application.Abstractions.Services; +using HyBe.Application.Abstractions.Token; +// using HyBe.Application.Abstractions.Token; +using HyBe.Infrastructure.Services; using HyBe.Infrastructure.Services.NotificationService; +using HyBe.Infrastructure.Services.Token; +// using HyBe.Infrastructure.Services.Token; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -10,6 +16,9 @@ public static class InfrastructureServiceRegistration { public static IServiceCollection AddInfrastructureServices(this IServiceCollection services) { + services.AddScoped(); + // services.AddScoped(); + // services.AddScoped(); services.AddScoped(); return services; } diff --git a/Infrastructure/HyBe.Infrastructure/Services/MailService.cs b/Infrastructure/HyBe.Infrastructure/Services/MailService.cs new file mode 100644 index 0000000..b84ff5b --- /dev/null +++ b/Infrastructure/HyBe.Infrastructure/Services/MailService.cs @@ -0,0 +1,26 @@ +// using HyBe.Application.Abstractions.Services; +// using System; +// using System.Collections.Generic; +// using System.Linq; +// using System.Threading.Tasks; + +// namespace HyBe.Infrastructure.Services +// { +// public class MailService : IMailService +// { +// public Task SendMailAsync(string to, string subject, string body, bool isBodyHtml = true) +// { +// throw new NotImplementedException(); +// } + +// public Task SendMailAsync(string[] tos, string subject, string body, bool isBodyHtml = true) +// { +// throw new NotImplementedException(); +// } + +// public Task SendPasswordResetMailAsync(string to, string userId, string resetToken) +// { +// throw new NotImplementedException(); +// } +// } +// } \ No newline at end of file diff --git a/Infrastructure/HyBe.Infrastructure/Services/Token/TokenHandler.cs b/Infrastructure/HyBe.Infrastructure/Services/Token/TokenHandler.cs new file mode 100644 index 0000000..4b731c7 --- /dev/null +++ b/Infrastructure/HyBe.Infrastructure/Services/Token/TokenHandler.cs @@ -0,0 +1,66 @@ +using System; +using System.Collections.Generic; +using System.IdentityModel.Tokens.Jwt; +using System.Linq; +using System.Security.Claims; +using System.Security.Cryptography; +using System.Text; +using System.Threading.Tasks; +using HyBe.Application.Abstractions.Token; +using HyBe.Domain.Entities.Identity; +using Microsoft.Extensions.Configuration; +using Microsoft.IdentityModel.Tokens; + +namespace HyBe.Infrastructure.Services.Token +{ + public class TokenHandler : ITokenHandler + { + readonly IConfiguration _configuration; + + public TokenHandler(IConfiguration configuration) + { + _configuration = configuration; + } + public Application.DTOs.Token CreateAccessToken(AppUser user) + { + Application.DTOs.Token token = new(); + + //Security Key'in simetriğini alıyoruz. + SymmetricSecurityKey securityKey = new(Encoding.UTF8.GetBytes(_configuration["Token:SecurityKey"])); + + //Şifrelenmiş kimliği oluşturuyoruz. + SigningCredentials signingCredentials = new(securityKey, SecurityAlgorithms.HmacSha256); + + //Oluşturulacak token ayarlarını veriyoruz. + if (!int.TryParse(_configuration["Token:AccessTokenLifeTime"], out int accessTokenLifeTime)) + return null; + + token.Expiration = DateTime.UtcNow.AddMinutes(accessTokenLifeTime); + JwtSecurityToken securityToken = new( + audience: _configuration["Token:Audience"], + issuer: _configuration["Token:Issuer"], + expires: token.Expiration, + notBefore: DateTime.UtcNow, + signingCredentials: signingCredentials, + claims: new List { new(ClaimTypes.Name, user?.UserName) } + ); + + //Token oluşturucu sınıfından bir örnek alalım. + JwtSecurityTokenHandler tokenHandler = new(); + token.AccessToken = tokenHandler.WriteToken(securityToken); + + //string refreshToken = CreateRefreshToken(); + + token.RefreshToken = CreateRefreshToken(); + return token; + } + + public string CreateRefreshToken() + { + byte[] number = new byte[32]; + using RandomNumberGenerator random = RandomNumberGenerator.Create(); + random.GetBytes(number); + return Convert.ToBase64String(number); + } + } +} \ No newline at end of file diff --git a/Infrastructure/HyBe.Persistence/Contexts/HypanceDbContext.cs b/Infrastructure/HyBe.Persistence/Contexts/HypanceDbContext.cs index 413cb28..206a7d6 100644 --- a/Infrastructure/HyBe.Persistence/Contexts/HypanceDbContext.cs +++ b/Infrastructure/HyBe.Persistence/Contexts/HypanceDbContext.cs @@ -11,9 +11,11 @@ using HyBe.Domain.Entities.Wallets; using Microsoft.EntityFrameworkCore; using HyBe.Domain.Entities.Signals; +using Microsoft.AspNetCore.Identity.EntityFrameworkCore; +using HyBe.Domain.Entities.Identity; namespace HyBe.Persistence.Contexts; -public class HypanceDbContext : DbContext +public class HypanceDbContext : IdentityDbContext { #region Fields private readonly IDomainEventDispatcher _dispatcher; diff --git a/Infrastructure/HyBe.Persistence/HyBe.Persistence.csproj b/Infrastructure/HyBe.Persistence/HyBe.Persistence.csproj index bdd56b4..6a34bb2 100644 --- a/Infrastructure/HyBe.Persistence/HyBe.Persistence.csproj +++ b/Infrastructure/HyBe.Persistence/HyBe.Persistence.csproj @@ -1,4 +1,4 @@ - + net7.0 @@ -15,6 +15,16 @@ + + + + diff --git a/Infrastructure/HyBe.Persistence/Migrations/20230318141515_migration1.Designer.cs b/Infrastructure/HyBe.Persistence/Migrations/20230318141515_migration1.Designer.cs new file mode 100644 index 0000000..6661d04 --- /dev/null +++ b/Infrastructure/HyBe.Persistence/Migrations/20230318141515_migration1.Designer.cs @@ -0,0 +1,621 @@ +// +using System; +using HyBe.Persistence.Contexts; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace HyBe.Persistence.Migrations +{ + [DbContext(typeof(HypanceDbContext))] + [Migration("20230318141515_migration1")] + partial class migration1 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("HyBe.Domain.Entities.Backtests.Backtest", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Finish") + .HasColumnType("timestamp with time zone"); + + b.Property("Formation") + .HasColumnType("integer[]"); + + b.Property("Market") + .HasColumnType("integer"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("OrderType") + .HasColumnType("integer"); + + b.Property("PositionType") + .HasColumnType("integer"); + + b.Property("Start") + .HasColumnType("timestamp with time zone"); + + b.Property("Strategy") + .HasColumnType("integer[]"); + + b.Property("Symbols") + .HasColumnType("integer[]"); + + b.Property("TrendStrategy") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Backtests"); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Bot", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("AssetIds") + .IsRequired() + .HasColumnType("integer[]"); + + b.Property("BotOptions") + .HasColumnType("integer"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text"); + + b.Property("FormationIds") + .HasColumnType("integer[]"); + + b.Property("Market") + .HasColumnType("integer"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("OrderType") + .HasColumnType("integer"); + + b.Property("PositionType") + .HasColumnType("integer"); + + b.Property("PriceVolume") + .HasColumnType("numeric"); + + b.Property("StrategyIds") + .HasColumnType("integer[]"); + + b.Property("TrendStrategy") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Bots"); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Formations.Formation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("DefaultPeriod") + .HasColumnType("integer"); + + b.Property("IsActive") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Formations"); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Formations.FormationSignal", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("FormationSignalName") + .IsRequired() + .HasColumnType("text"); + + b.Property("Interval") + .HasColumnType("integer"); + + b.Property("IsActive") + .HasColumnType("boolean"); + + b.Property("Period") + .HasColumnType("integer"); + + b.Property("Result") + .HasColumnType("boolean"); + + b.Property("SymbolName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("FormationSignals"); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Indicators.Indicator", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("DefaultPeriod") + .HasColumnType("integer"); + + b.Property("IsActive") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Indicators"); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Indicators.IndicatorSignal", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("IndicatorName") + .IsRequired() + .HasColumnType("text"); + + b.Property("Interval") + .HasColumnType("integer"); + + b.Property("IsActive") + .HasColumnType("boolean"); + + b.Property("Period") + .HasColumnType("integer"); + + b.Property("Signals") + .IsRequired() + .HasColumnType("integer[]"); + + b.Property("SymbolName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("IndicatorSignals"); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Signals.Signal", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("IndicatorId") + .HasColumnType("integer"); + + b.Property("Interval") + .HasColumnType("integer"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Period") + .HasColumnType("integer"); + + b.Property("SignalResult") + .HasColumnType("integer"); + + b.Property("StrategyId") + .HasColumnType("uuid"); + + b.Property("TrendStrategy") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("StrategyId"); + + b.ToTable("Signals"); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Strategies.Strategy", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Strategies"); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Symbols.Candlestick", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("ClosePrice") + .HasColumnType("numeric"); + + b.Property("CloseTime") + .HasColumnType("timestamp with time zone"); + + b.Property("HighPrice") + .HasColumnType("numeric"); + + b.Property("Interval") + .HasColumnType("integer"); + + b.Property("IsActive") + .HasColumnType("boolean"); + + b.Property("LowPrice") + .HasColumnType("numeric"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("OpenPrice") + .HasColumnType("numeric"); + + b.Property("OpenTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Symbol") + .IsRequired() + .HasColumnType("text"); + + b.Property("Volume") + .HasColumnType("numeric"); + + b.HasKey("Id"); + + b.ToTable("Candlesticks"); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Symbols.Symbol", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("IsActive") + .HasColumnType("boolean"); + + b.Property("MaxQuantity") + .HasColumnType("numeric"); + + b.Property("MinQuantity") + .HasColumnType("numeric"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Symbols"); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Wallets.Wallet", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Balance") + .HasColumnType("numeric"); + + b.HasKey("Id"); + + b.ToTable("Wallets"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("text"); + + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("NormalizedName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasDatabaseName("RoleNameIndex"); + + b.ToTable("AspNetRoles", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClaimType") + .HasColumnType("text"); + + b.Property("ClaimValue") + .HasColumnType("text"); + + b.Property("RoleId") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("AccessFailedCount") + .HasColumnType("integer"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("text"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("boolean"); + + b.Property("LockoutEnabled") + .HasColumnType("boolean"); + + b.Property("LockoutEnd") + .HasColumnType("timestamp with time zone"); + + b.Property("NormalizedEmail") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("NormalizedUserName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("PasswordHash") + .HasColumnType("text"); + + b.Property("PhoneNumber") + .HasColumnType("text"); + + b.Property("PhoneNumberConfirmed") + .HasColumnType("boolean"); + + b.Property("SecurityStamp") + .HasColumnType("text"); + + b.Property("TwoFactorEnabled") + .HasColumnType("boolean"); + + b.Property("UserName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasDatabaseName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasDatabaseName("UserNameIndex"); + + b.ToTable("AspNetUsers", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClaimType") + .HasColumnType("text"); + + b.Property("ClaimValue") + .HasColumnType("text"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasColumnType("text"); + + b.Property("ProviderKey") + .HasColumnType("text"); + + b.Property("ProviderDisplayName") + .HasColumnType("text"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId") + .HasColumnType("text"); + + b.Property("RoleId") + .HasColumnType("text"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetUserRoles", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId") + .HasColumnType("text"); + + b.Property("LoginProvider") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("Value") + .HasColumnType("text"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens", (string)null); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Signals.Signal", b => + { + b.HasOne("HyBe.Domain.Entities.Strategies.Strategy", null) + .WithMany("Signals") + .HasForeignKey("StrategyId"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Strategies.Strategy", b => + { + b.Navigation("Signals"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Infrastructure/HyBe.Persistence/Migrations/20230318141515_migration1.cs b/Infrastructure/HyBe.Persistence/Migrations/20230318141515_migration1.cs new file mode 100644 index 0000000..066ca82 --- /dev/null +++ b/Infrastructure/HyBe.Persistence/Migrations/20230318141515_migration1.cs @@ -0,0 +1,223 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace HyBe.Persistence.Migrations +{ + /// + public partial class migration1 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "AspNetRoles", + columns: table => new + { + Id = table.Column(type: "text", nullable: false), + Name = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), + NormalizedName = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), + ConcurrencyStamp = table.Column(type: "text", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetRoles", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "AspNetUsers", + columns: table => new + { + Id = table.Column(type: "text", nullable: false), + UserName = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), + NormalizedUserName = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), + Email = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), + NormalizedEmail = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), + EmailConfirmed = table.Column(type: "boolean", nullable: false), + PasswordHash = table.Column(type: "text", nullable: true), + SecurityStamp = table.Column(type: "text", nullable: true), + ConcurrencyStamp = table.Column(type: "text", nullable: true), + PhoneNumber = table.Column(type: "text", nullable: true), + PhoneNumberConfirmed = table.Column(type: "boolean", nullable: false), + TwoFactorEnabled = table.Column(type: "boolean", nullable: false), + LockoutEnd = table.Column(type: "timestamp with time zone", nullable: true), + LockoutEnabled = table.Column(type: "boolean", nullable: false), + AccessFailedCount = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUsers", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "AspNetRoleClaims", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + RoleId = table.Column(type: "text", nullable: false), + ClaimType = table.Column(type: "text", nullable: true), + ClaimValue = table.Column(type: "text", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetRoleClaims", x => x.Id); + table.ForeignKey( + name: "FK_AspNetRoleClaims_AspNetRoles_RoleId", + column: x => x.RoleId, + principalTable: "AspNetRoles", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AspNetUserClaims", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + UserId = table.Column(type: "text", nullable: false), + ClaimType = table.Column(type: "text", nullable: true), + ClaimValue = table.Column(type: "text", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUserClaims", x => x.Id); + table.ForeignKey( + name: "FK_AspNetUserClaims_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AspNetUserLogins", + columns: table => new + { + LoginProvider = table.Column(type: "text", nullable: false), + ProviderKey = table.Column(type: "text", nullable: false), + ProviderDisplayName = table.Column(type: "text", nullable: true), + UserId = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUserLogins", x => new { x.LoginProvider, x.ProviderKey }); + table.ForeignKey( + name: "FK_AspNetUserLogins_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AspNetUserRoles", + columns: table => new + { + UserId = table.Column(type: "text", nullable: false), + RoleId = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUserRoles", x => new { x.UserId, x.RoleId }); + table.ForeignKey( + name: "FK_AspNetUserRoles_AspNetRoles_RoleId", + column: x => x.RoleId, + principalTable: "AspNetRoles", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_AspNetUserRoles_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AspNetUserTokens", + columns: table => new + { + UserId = table.Column(type: "text", nullable: false), + LoginProvider = table.Column(type: "text", nullable: false), + Name = table.Column(type: "text", nullable: false), + Value = table.Column(type: "text", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUserTokens", x => new { x.UserId, x.LoginProvider, x.Name }); + table.ForeignKey( + name: "FK_AspNetUserTokens_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_AspNetRoleClaims_RoleId", + table: "AspNetRoleClaims", + column: "RoleId"); + + migrationBuilder.CreateIndex( + name: "RoleNameIndex", + table: "AspNetRoles", + column: "NormalizedName", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_AspNetUserClaims_UserId", + table: "AspNetUserClaims", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_AspNetUserLogins_UserId", + table: "AspNetUserLogins", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_AspNetUserRoles_RoleId", + table: "AspNetUserRoles", + column: "RoleId"); + + migrationBuilder.CreateIndex( + name: "EmailIndex", + table: "AspNetUsers", + column: "NormalizedEmail"); + + migrationBuilder.CreateIndex( + name: "UserNameIndex", + table: "AspNetUsers", + column: "NormalizedUserName", + unique: true); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "AspNetRoleClaims"); + + migrationBuilder.DropTable( + name: "AspNetUserClaims"); + + migrationBuilder.DropTable( + name: "AspNetUserLogins"); + + migrationBuilder.DropTable( + name: "AspNetUserRoles"); + + migrationBuilder.DropTable( + name: "AspNetUserTokens"); + + migrationBuilder.DropTable( + name: "AspNetRoles"); + + migrationBuilder.DropTable( + name: "AspNetUsers"); + } + } +} diff --git a/Infrastructure/HyBe.Persistence/Migrations/20230318194141_migration2.Designer.cs b/Infrastructure/HyBe.Persistence/Migrations/20230318194141_migration2.Designer.cs new file mode 100644 index 0000000..f1430cf --- /dev/null +++ b/Infrastructure/HyBe.Persistence/Migrations/20230318194141_migration2.Designer.cs @@ -0,0 +1,724 @@ +// +using System; +using HyBe.Persistence.Contexts; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace HyBe.Persistence.Migrations +{ + [DbContext(typeof(HypanceDbContext))] + [Migration("20230318194141_migration2")] + partial class migration2 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("AppRoleEndpoint", b => + { + b.Property("EndpointsId") + .HasColumnType("uuid"); + + b.Property("RolesId") + .HasColumnType("text"); + + b.HasKey("EndpointsId", "RolesId"); + + b.HasIndex("RolesId"); + + b.ToTable("AppRoleEndpoint"); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Backtests.Backtest", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Finish") + .HasColumnType("timestamp with time zone"); + + b.Property("Formation") + .HasColumnType("integer[]"); + + b.Property("Market") + .HasColumnType("integer"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("OrderType") + .HasColumnType("integer"); + + b.Property("PositionType") + .HasColumnType("integer"); + + b.Property("Start") + .HasColumnType("timestamp with time zone"); + + b.Property("Strategy") + .HasColumnType("integer[]"); + + b.Property("Symbols") + .HasColumnType("integer[]"); + + b.Property("TrendStrategy") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Backtests"); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Bot", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("AssetIds") + .IsRequired() + .HasColumnType("integer[]"); + + b.Property("BotOptions") + .HasColumnType("integer"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text"); + + b.Property("FormationIds") + .HasColumnType("integer[]"); + + b.Property("Market") + .HasColumnType("integer"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("OrderType") + .HasColumnType("integer"); + + b.Property("PositionType") + .HasColumnType("integer"); + + b.Property("PriceVolume") + .HasColumnType("numeric"); + + b.Property("StrategyIds") + .HasColumnType("integer[]"); + + b.Property("TrendStrategy") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Bots"); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Formations.Formation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("DefaultPeriod") + .HasColumnType("integer"); + + b.Property("IsActive") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Formations"); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Formations.FormationSignal", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("FormationSignalName") + .IsRequired() + .HasColumnType("text"); + + b.Property("Interval") + .HasColumnType("integer"); + + b.Property("IsActive") + .HasColumnType("boolean"); + + b.Property("Period") + .HasColumnType("integer"); + + b.Property("Result") + .HasColumnType("boolean"); + + b.Property("SymbolName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("FormationSignals"); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Identity.AppRole", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("text"); + + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("NormalizedName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasDatabaseName("RoleNameIndex"); + + b.ToTable("AspNetRoles", (string)null); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Identity.AppUser", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("AccessFailedCount") + .HasColumnType("integer"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("text"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("boolean"); + + b.Property("LockoutEnabled") + .HasColumnType("boolean"); + + b.Property("LockoutEnd") + .HasColumnType("timestamp with time zone"); + + b.Property("NameSurname") + .IsRequired() + .HasColumnType("text"); + + b.Property("NormalizedEmail") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("NormalizedUserName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("PasswordHash") + .HasColumnType("text"); + + b.Property("PhoneNumber") + .HasColumnType("text"); + + b.Property("PhoneNumberConfirmed") + .HasColumnType("boolean"); + + b.Property("RefreshToken") + .HasColumnType("text"); + + b.Property("RefreshTokenEndDate") + .HasColumnType("timestamp with time zone"); + + b.Property("SecurityStamp") + .HasColumnType("text"); + + b.Property("TwoFactorEnabled") + .HasColumnType("boolean"); + + b.Property("UserName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasDatabaseName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasDatabaseName("UserNameIndex"); + + b.ToTable("AspNetUsers", (string)null); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Identity.Endpoint", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("ActionType") + .IsRequired() + .HasColumnType("text"); + + b.Property("Code") + .IsRequired() + .HasColumnType("text"); + + b.Property("Definition") + .IsRequired() + .HasColumnType("text"); + + b.Property("HttpType") + .IsRequired() + .HasColumnType("text"); + + b.Property("MenuId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("MenuId"); + + b.ToTable("Endpoint"); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Identity.Menu", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Menu"); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Indicators.Indicator", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("DefaultPeriod") + .HasColumnType("integer"); + + b.Property("IsActive") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Indicators"); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Indicators.IndicatorSignal", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("IndicatorName") + .IsRequired() + .HasColumnType("text"); + + b.Property("Interval") + .HasColumnType("integer"); + + b.Property("IsActive") + .HasColumnType("boolean"); + + b.Property("Period") + .HasColumnType("integer"); + + b.Property("Signals") + .IsRequired() + .HasColumnType("integer[]"); + + b.Property("SymbolName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("IndicatorSignals"); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Signals.Signal", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("IndicatorId") + .HasColumnType("integer"); + + b.Property("Interval") + .HasColumnType("integer"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Period") + .HasColumnType("integer"); + + b.Property("SignalResult") + .HasColumnType("integer"); + + b.Property("StrategyId") + .HasColumnType("uuid"); + + b.Property("TrendStrategy") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("StrategyId"); + + b.ToTable("Signals"); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Strategies.Strategy", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Strategies"); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Symbols.Candlestick", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("ClosePrice") + .HasColumnType("numeric"); + + b.Property("CloseTime") + .HasColumnType("timestamp with time zone"); + + b.Property("HighPrice") + .HasColumnType("numeric"); + + b.Property("Interval") + .HasColumnType("integer"); + + b.Property("IsActive") + .HasColumnType("boolean"); + + b.Property("LowPrice") + .HasColumnType("numeric"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("OpenPrice") + .HasColumnType("numeric"); + + b.Property("OpenTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Symbol") + .IsRequired() + .HasColumnType("text"); + + b.Property("Volume") + .HasColumnType("numeric"); + + b.HasKey("Id"); + + b.ToTable("Candlesticks"); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Symbols.Symbol", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("IsActive") + .HasColumnType("boolean"); + + b.Property("MaxQuantity") + .HasColumnType("numeric"); + + b.Property("MinQuantity") + .HasColumnType("numeric"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Symbols"); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Wallets.Wallet", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Balance") + .HasColumnType("numeric"); + + b.HasKey("Id"); + + b.ToTable("Wallets"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClaimType") + .HasColumnType("text"); + + b.Property("ClaimValue") + .HasColumnType("text"); + + b.Property("RoleId") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClaimType") + .HasColumnType("text"); + + b.Property("ClaimValue") + .HasColumnType("text"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasColumnType("text"); + + b.Property("ProviderKey") + .HasColumnType("text"); + + b.Property("ProviderDisplayName") + .HasColumnType("text"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId") + .HasColumnType("text"); + + b.Property("RoleId") + .HasColumnType("text"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetUserRoles", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId") + .HasColumnType("text"); + + b.Property("LoginProvider") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("Value") + .HasColumnType("text"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens", (string)null); + }); + + modelBuilder.Entity("AppRoleEndpoint", b => + { + b.HasOne("HyBe.Domain.Entities.Identity.Endpoint", null) + .WithMany() + .HasForeignKey("EndpointsId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("HyBe.Domain.Entities.Identity.AppRole", null) + .WithMany() + .HasForeignKey("RolesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Identity.Endpoint", b => + { + b.HasOne("HyBe.Domain.Entities.Identity.Menu", "Menu") + .WithMany("Endpoints") + .HasForeignKey("MenuId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Menu"); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Signals.Signal", b => + { + b.HasOne("HyBe.Domain.Entities.Strategies.Strategy", null) + .WithMany("Signals") + .HasForeignKey("StrategyId"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.HasOne("HyBe.Domain.Entities.Identity.AppRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("HyBe.Domain.Entities.Identity.AppUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("HyBe.Domain.Entities.Identity.AppUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.HasOne("HyBe.Domain.Entities.Identity.AppRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("HyBe.Domain.Entities.Identity.AppUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("HyBe.Domain.Entities.Identity.AppUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Identity.Menu", b => + { + b.Navigation("Endpoints"); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Strategies.Strategy", b => + { + b.Navigation("Signals"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Infrastructure/HyBe.Persistence/Migrations/20230318194141_migration2.cs b/Infrastructure/HyBe.Persistence/Migrations/20230318194141_migration2.cs new file mode 100644 index 0000000..7eb26d9 --- /dev/null +++ b/Infrastructure/HyBe.Persistence/Migrations/20230318194141_migration2.cs @@ -0,0 +1,127 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace HyBe.Persistence.Migrations +{ + /// + public partial class migration2 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "NameSurname", + table: "AspNetUsers", + type: "text", + nullable: false, + defaultValue: ""); + + migrationBuilder.AddColumn( + name: "RefreshToken", + table: "AspNetUsers", + type: "text", + nullable: true); + + migrationBuilder.AddColumn( + name: "RefreshTokenEndDate", + table: "AspNetUsers", + type: "timestamp with time zone", + nullable: true); + + migrationBuilder.CreateTable( + name: "Menu", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + Name = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Menu", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Endpoint", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + ActionType = table.Column(type: "text", nullable: false), + HttpType = table.Column(type: "text", nullable: false), + Definition = table.Column(type: "text", nullable: false), + Code = table.Column(type: "text", nullable: false), + MenuId = table.Column(type: "uuid", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Endpoint", x => x.Id); + table.ForeignKey( + name: "FK_Endpoint_Menu_MenuId", + column: x => x.MenuId, + principalTable: "Menu", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AppRoleEndpoint", + columns: table => new + { + EndpointsId = table.Column(type: "uuid", nullable: false), + RolesId = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AppRoleEndpoint", x => new { x.EndpointsId, x.RolesId }); + table.ForeignKey( + name: "FK_AppRoleEndpoint_AspNetRoles_RolesId", + column: x => x.RolesId, + principalTable: "AspNetRoles", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_AppRoleEndpoint_Endpoint_EndpointsId", + column: x => x.EndpointsId, + principalTable: "Endpoint", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_AppRoleEndpoint_RolesId", + table: "AppRoleEndpoint", + column: "RolesId"); + + migrationBuilder.CreateIndex( + name: "IX_Endpoint_MenuId", + table: "Endpoint", + column: "MenuId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "AppRoleEndpoint"); + + migrationBuilder.DropTable( + name: "Endpoint"); + + migrationBuilder.DropTable( + name: "Menu"); + + migrationBuilder.DropColumn( + name: "NameSurname", + table: "AspNetUsers"); + + migrationBuilder.DropColumn( + name: "RefreshToken", + table: "AspNetUsers"); + + migrationBuilder.DropColumn( + name: "RefreshTokenEndDate", + table: "AspNetUsers"); + } + } +} diff --git a/Infrastructure/HyBe.Persistence/Migrations/HypanceDbContextModelSnapshot.cs b/Infrastructure/HyBe.Persistence/Migrations/HypanceDbContextModelSnapshot.cs index e71dd24..7f53681 100644 --- a/Infrastructure/HyBe.Persistence/Migrations/HypanceDbContextModelSnapshot.cs +++ b/Infrastructure/HyBe.Persistence/Migrations/HypanceDbContextModelSnapshot.cs @@ -17,11 +17,26 @@ protected override void BuildModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "7.0.2") + .HasAnnotation("ProductVersion", "7.0.3") .HasAnnotation("Relational:MaxIdentifierLength", 63); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + modelBuilder.Entity("AppRoleEndpoint", b => + { + b.Property("EndpointsId") + .HasColumnType("uuid"); + + b.Property("RolesId") + .HasColumnType("text"); + + b.HasKey("EndpointsId", "RolesId"); + + b.HasIndex("RolesId"); + + b.ToTable("AppRoleEndpoint"); + }); + modelBuilder.Entity("HyBe.Domain.Entities.Backtests.Backtest", b => { b.Property("Id") @@ -163,6 +178,153 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("FormationSignals"); }); + modelBuilder.Entity("HyBe.Domain.Entities.Identity.AppRole", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("text"); + + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("NormalizedName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasDatabaseName("RoleNameIndex"); + + b.ToTable("AspNetRoles", (string)null); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Identity.AppUser", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("AccessFailedCount") + .HasColumnType("integer"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("text"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("boolean"); + + b.Property("LockoutEnabled") + .HasColumnType("boolean"); + + b.Property("LockoutEnd") + .HasColumnType("timestamp with time zone"); + + b.Property("NameSurname") + .IsRequired() + .HasColumnType("text"); + + b.Property("NormalizedEmail") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("NormalizedUserName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("PasswordHash") + .HasColumnType("text"); + + b.Property("PhoneNumber") + .HasColumnType("text"); + + b.Property("PhoneNumberConfirmed") + .HasColumnType("boolean"); + + b.Property("RefreshToken") + .HasColumnType("text"); + + b.Property("RefreshTokenEndDate") + .HasColumnType("timestamp with time zone"); + + b.Property("SecurityStamp") + .HasColumnType("text"); + + b.Property("TwoFactorEnabled") + .HasColumnType("boolean"); + + b.Property("UserName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasDatabaseName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasDatabaseName("UserNameIndex"); + + b.ToTable("AspNetUsers", (string)null); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Identity.Endpoint", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("ActionType") + .IsRequired() + .HasColumnType("text"); + + b.Property("Code") + .IsRequired() + .HasColumnType("text"); + + b.Property("Definition") + .IsRequired() + .HasColumnType("text"); + + b.Property("HttpType") + .IsRequired() + .HasColumnType("text"); + + b.Property("MenuId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("MenuId"); + + b.ToTable("Endpoint"); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Identity.Menu", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Menu"); + }); + modelBuilder.Entity("HyBe.Domain.Entities.Indicators.Indicator", b => { b.Property("Id") @@ -216,7 +378,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("IndicatorSignals"); }); - modelBuilder.Entity("HyBe.Domain.Entities.Strategies.Signal", b => + modelBuilder.Entity("HyBe.Domain.Entities.Signals.Signal", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -354,13 +516,201 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("Wallets"); }); - modelBuilder.Entity("HyBe.Domain.Entities.Strategies.Signal", b => + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClaimType") + .HasColumnType("text"); + + b.Property("ClaimValue") + .HasColumnType("text"); + + b.Property("RoleId") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClaimType") + .HasColumnType("text"); + + b.Property("ClaimValue") + .HasColumnType("text"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasColumnType("text"); + + b.Property("ProviderKey") + .HasColumnType("text"); + + b.Property("ProviderDisplayName") + .HasColumnType("text"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId") + .HasColumnType("text"); + + b.Property("RoleId") + .HasColumnType("text"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetUserRoles", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId") + .HasColumnType("text"); + + b.Property("LoginProvider") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("Value") + .HasColumnType("text"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens", (string)null); + }); + + modelBuilder.Entity("AppRoleEndpoint", b => + { + b.HasOne("HyBe.Domain.Entities.Identity.Endpoint", null) + .WithMany() + .HasForeignKey("EndpointsId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("HyBe.Domain.Entities.Identity.AppRole", null) + .WithMany() + .HasForeignKey("RolesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Identity.Endpoint", b => + { + b.HasOne("HyBe.Domain.Entities.Identity.Menu", "Menu") + .WithMany("Endpoints") + .HasForeignKey("MenuId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Menu"); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Signals.Signal", b => { b.HasOne("HyBe.Domain.Entities.Strategies.Strategy", null) .WithMany("Signals") .HasForeignKey("StrategyId"); }); + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.HasOne("HyBe.Domain.Entities.Identity.AppRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("HyBe.Domain.Entities.Identity.AppUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("HyBe.Domain.Entities.Identity.AppUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.HasOne("HyBe.Domain.Entities.Identity.AppRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("HyBe.Domain.Entities.Identity.AppUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("HyBe.Domain.Entities.Identity.AppUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Identity.Menu", b => + { + b.Navigation("Endpoints"); + }); + modelBuilder.Entity("HyBe.Domain.Entities.Strategies.Strategy", b => { b.Navigation("Signals"); diff --git a/Infrastructure/HyBe.Persistence/PersistenceServiceRegistration.cs b/Infrastructure/HyBe.Persistence/PersistenceServiceRegistration.cs index 19ef15f..26ebb02 100644 --- a/Infrastructure/HyBe.Persistence/PersistenceServiceRegistration.cs +++ b/Infrastructure/HyBe.Persistence/PersistenceServiceRegistration.cs @@ -1,9 +1,13 @@ using HyBe.Application.Abstractions.Services; +using HyBe.Application.Abstractions.Services.Authentications; +using HyBe.Domain.Entities.Identity; +// using HyBe.Application.Abstractions.Services.Authentications; using HyBe.Persistence.Contexts; using HyBe.Persistence.Repositories; using HyBe.Persistence.Services; using HyBe.SharedKernel.Events; using HyBe.SharedKernel.Repositories; +using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -15,9 +19,20 @@ public static IServiceCollection AddPersistenceServices(this IServiceCollection IConfiguration configuration) { services.AddDbContext(options => options.UseNpgsql(configuration.GetConnectionString("HypanceConnectionString"))); - services.AddScoped(typeof(IRepository<>), typeof(EfRepository<>)); + + services.AddIdentity(options => + { + options.Password.RequiredLength = 3; + options.Password.RequireNonAlphanumeric = false; + options.Password.RequireDigit = false; + options.Password.RequireLowercase = false; + options.Password.RequireUppercase = false; + }).AddEntityFrameworkStores() + .AddDefaultTokenProviders(); + + services.AddScoped(typeof(IRepository<>), typeof(EfRepository<>)); services.AddScoped(); - services.AddScoped(); + services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); @@ -27,7 +42,20 @@ public static IServiceCollection AddPersistenceServices(this IServiceCollection services.AddScoped(); services.AddScoped(); services.AddScoped(); - services.AddScoped(); + + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + // services.AddScoped(); + // services.AddScoped(); + + services.AddScoped(); + + + + //services.AddScoped(); + + return services; } diff --git a/Infrastructure/HyBe.Persistence/Services/AuthService.cs b/Infrastructure/HyBe.Persistence/Services/AuthService.cs new file mode 100644 index 0000000..ff2695b --- /dev/null +++ b/Infrastructure/HyBe.Persistence/Services/AuthService.cs @@ -0,0 +1,101 @@ +using HyBe.Application.Abstractions.Services; +using HyBe.Application.Abstractions.Token; +using HyBe.Application.DTOs; +using HyBe.Application.Exceptions; +using HyBe.Domain.Entities.Identity; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; + +namespace HyBe.Persistence.Services +{ + public class AuthService : IAuthService + { + readonly UserManager _userManager; + readonly ITokenHandler _tokenHandler; + readonly SignInManager _signInManager; + readonly IUserService _userService; + public AuthService( + UserManager userManager, + ITokenHandler tokenHandler, + SignInManager signInManager, + IUserService userService) + { + _userManager = userManager; + _tokenHandler = tokenHandler; + _signInManager = signInManager; + _userService = userService; + } + async Task CreateUserExternalAsync(AppUser user, string email, string name, UserLoginInfo info, int accessTokenLifeTime) + { + bool result = user != null; + if (user == null) + { + user = await _userManager.FindByEmailAsync(email); + if (user == null) + { + user = new() + { + Id = Guid.NewGuid().ToString(), + Email = email, + UserName = email, + NameSurname = name + }; + var identityResult = await _userManager.CreateAsync(user); + result = identityResult.Succeeded; + } + } + + if (result) + { + await _userManager.AddLoginAsync(user, info); //AspNetUserLogins + + Token token = _tokenHandler.CreateAccessToken(user); + await _userService.UpdateRefreshTokenAsync(token.RefreshToken, user, token.Expiration, 15); + return token; + } + throw new Exception("Invalid external authentication."); + } + + public async Task LoginAsync(string usernameOrEmail, string password) + { + Domain.Entities.Identity.AppUser user = await _userManager.FindByNameAsync(usernameOrEmail); + if (user == null) + user = await _userManager.FindByEmailAsync(usernameOrEmail); + + if (user == null) + throw new NotFoundUserException(); + + SignInResult result = await _signInManager.CheckPasswordSignInAsync(user, password, false); + if (result.Succeeded) //Authentication başarılı! + { + Token token = _tokenHandler.CreateAccessToken(user); + await _userService.UpdateRefreshTokenAsync(token.RefreshToken, user, token.Expiration, 15); + return token; + } + throw new AuthenticationErrorException(); + } + + public Task PasswordResetAsnyc(string email) + { + throw new NotImplementedException(); + } + + public async Task RefreshTokenLoginAsync(string refreshToken) + { + AppUser? user = await _userManager.Users.FirstOrDefaultAsync(u => u.RefreshToken == refreshToken); + if (user != null && user?.RefreshTokenEndDate > DateTime.UtcNow) + { + Token token = _tokenHandler.CreateAccessToken(user); + await _userService.UpdateRefreshTokenAsync(token.RefreshToken, user, token.Expiration, 300); + return token; + } + else + throw new NotFoundUserException(); + } + + public Task VerifyResetTokenAsync(string resetToken, string userId) + { + throw new NotImplementedException(); + } + } +} diff --git a/Infrastructure/HyBe.Persistence/Services/AuthorizationEndpointService.cs b/Infrastructure/HyBe.Persistence/Services/AuthorizationEndpointService.cs new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/Infrastructure/HyBe.Persistence/Services/AuthorizationEndpointService.cs @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Infrastructure/HyBe.Persistence/Services/RoleService.cs b/Infrastructure/HyBe.Persistence/Services/RoleService.cs new file mode 100644 index 0000000..e69de29 diff --git a/Infrastructure/HyBe.Persistence/Services/UserService.cs b/Infrastructure/HyBe.Persistence/Services/UserService.cs new file mode 100644 index 0000000..00a8280 --- /dev/null +++ b/Infrastructure/HyBe.Persistence/Services/UserService.cs @@ -0,0 +1,53 @@ +using HyBe.Application.Abstractions.Services; +using HyBe.Application.DTOs.User; +using HyBe.Application.Exceptions; +using HyBe.Domain.Entities.Identity; +using Microsoft.AspNetCore.Identity; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Persistence.Services +{ + public class UserService : IUserService + { + readonly UserManager _userManager; + public UserService(UserManager userManager) + { + _userManager = userManager; + } + public async Task CreateAsync(CreateUser model) + { + IdentityResult result = await _userManager.CreateAsync(new() + { + Id = Guid.NewGuid().ToString(), + UserName = model.Username, + Email = model.Email, + NameSurname = model.NameSurname, + }, model.Password); + + CreateUserResponse response = new() { Succeeded = result.Succeeded }; + + if (result.Succeeded) + response.Message = "Kullanıcı başarıyla oluşturulmuştur."; + else + foreach (var error in result.Errors) + response.Message += $"{error.Code} - {error.Description}\n"; + + return response; + } + + public async Task UpdateRefreshTokenAsync(string refreshToken, AppUser user, DateTime accessTokenDate, int addOnAccessTokenDate) + { + if (user != null) + { + user.RefreshToken = refreshToken; + user.RefreshTokenEndDate = accessTokenDate.AddSeconds(addOnAccessTokenDate); + await _userManager.UpdateAsync(user); + } + else + throw new NotFoundUserException(); + } + } +} \ No newline at end of file diff --git a/Presentation/HyBe.WebAPI/Controllers/ApplicationServicesController.cs b/Presentation/HyBe.WebAPI/Controllers/ApplicationServicesController.cs new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/Presentation/HyBe.WebAPI/Controllers/ApplicationServicesController.cs @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Presentation/HyBe.WebAPI/Controllers/AuthController.cs b/Presentation/HyBe.WebAPI/Controllers/AuthController.cs new file mode 100644 index 0000000..19a7c0c --- /dev/null +++ b/Presentation/HyBe.WebAPI/Controllers/AuthController.cs @@ -0,0 +1,30 @@ +using HyBe.Application.Features.AppUser.Commands.LoginUser; +using HyBe.Application.Features.AppUser.Commands.RefreshTokenLogin; +using MediatR; +using Microsoft.AspNetCore.Mvc; + +namespace HyBe.WebAPI.Controllers.v1 +{ + [Route("api/v1.0/[controller]/[action]")] + [ApiController] + public class AuthController : ControllerBase + { + readonly IMediator _mediator; + public AuthController(IMediator mediator) + { + _mediator = mediator; + } + [HttpPost] + public async Task Login(LoginUserCommandRequest loginUserCommandRequest) + { + LoginUserCommandResponse response = await _mediator.Send(loginUserCommandRequest); + return Ok(response); + } + [HttpPost] + public async Task RefreshTokenLogin([FromBody] RefreshTokenLoginCommandRequest refreshTokenLoginCommandRequest) + { + RefreshTokenLoginCommandResponse response = await _mediator.Send(refreshTokenLoginCommandRequest); + return Ok(response); + } + } +} diff --git a/Presentation/HyBe.WebAPI/Controllers/AuthorizationEndpointsController.cs b/Presentation/HyBe.WebAPI/Controllers/AuthorizationEndpointsController.cs new file mode 100644 index 0000000..0c11db5 --- /dev/null +++ b/Presentation/HyBe.WebAPI/Controllers/AuthorizationEndpointsController.cs @@ -0,0 +1,34 @@ +/* using HyBe.Application.Features.AuthorizationEndpoint.Commands.AssignRoleEndpoint; +using HyBe.Application.Features.AuthorizationEndpoint.Queries.GetRolesToEndpoint; */ +using MediatR; +using Microsoft.AspNetCore.Mvc; + +namespace HyBe.WebAPI.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class AuthorizationEndpointsController : ControllerBase + { + readonly IMediator _mediator; + + public AuthorizationEndpointsController(IMediator mediator) + { + _mediator = mediator; + } + + /* [HttpPost("[action]")] + public async Task GetRolesToEndpoint(GetRolesToEndpointQueryRequest rolesToEndpointQueryRequest) + { + GetRolesToEndpointQueryResponse response = await _mediator.Send(rolesToEndpointQueryRequest); + return Ok(response); + } + + [HttpPost] + public async Task AssignRoleEndpoint(AssignRoleEndpointCommandRequest assignRoleEndpointCommandRequest) + { + assignRoleEndpointCommandRequest.Type = typeof(Program); + AssignRoleEndpointCommandResponse response = await _mediator.Send(assignRoleEndpointCommandRequest); + return Ok(response); + } */ + } +} \ No newline at end of file diff --git a/Presentation/HyBe.WebAPI/Controllers/RolesController.cs b/Presentation/HyBe.WebAPI/Controllers/RolesController.cs new file mode 100644 index 0000000..e69de29 diff --git a/Presentation/HyBe.WebAPI/Controllers/UsersController.cs b/Presentation/HyBe.WebAPI/Controllers/UsersController.cs new file mode 100644 index 0000000..6168b9d --- /dev/null +++ b/Presentation/HyBe.WebAPI/Controllers/UsersController.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using HyBe.Application.Abstractions.Services; +using HyBe.Application.Features.AppUser.Commands.CreateUser; +using HyBe.Domain.Enums; +using MediatR; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Mvc; + +namespace HyBe.WebAPI.Controllers.v1 +{ + [Microsoft.AspNetCore.Mvc.Route("api/[Controller]")] + [ApiController] + public class UsersController : ControllerBase + { + readonly IMediator _mediator; + public UsersController(IMediator mediator) + { + _mediator = mediator; + + } + [HttpPost] + public async Task CreateUser(CreateUserCommandRequest createUserCommandRequest) + { + CreateUserCommandResponse response = await _mediator.Send(createUserCommandRequest); + return Ok(response); + } + + } +} \ No newline at end of file diff --git a/Presentation/HyBe.WebAPI/Controllers/v1/SymbolController.cs b/Presentation/HyBe.WebAPI/Controllers/v1/SymbolController.cs index 77826e0..5078cbf 100644 --- a/Presentation/HyBe.WebAPI/Controllers/v1/SymbolController.cs +++ b/Presentation/HyBe.WebAPI/Controllers/v1/SymbolController.cs @@ -6,12 +6,14 @@ using HyBe.Application.Features.Symbols.Queries.GetListSymbol; using HyBe.Domain.Contracts.Symbols; using MediatR; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; namespace HyBe.WebAPI.Controllers.v1 { [Route("api/v1.0/[controller]/[action]")] [ApiController] + [Authorize(AuthenticationSchemes = "Admin")] public class SymbolController : ControllerBase { #region Fileds diff --git a/Presentation/HyBe.WebAPI/HyBe.WebAPI.csproj b/Presentation/HyBe.WebAPI/HyBe.WebAPI.csproj index dd8914c..32a7f14 100644 --- a/Presentation/HyBe.WebAPI/HyBe.WebAPI.csproj +++ b/Presentation/HyBe.WebAPI/HyBe.WebAPI.csproj @@ -9,6 +9,7 @@ + diff --git a/Presentation/HyBe.WebAPI/Program.cs b/Presentation/HyBe.WebAPI/Program.cs index 543fd20..e252f46 100644 --- a/Presentation/HyBe.WebAPI/Program.cs +++ b/Presentation/HyBe.WebAPI/Program.cs @@ -1,24 +1,70 @@  -using HyBe.Application; +using HyBe.Application; using HyBe.Persistence; using HyBe.Infrastructure; using Microsoft.Extensions.Configuration; +using Microsoft.AspNetCore.Authentication.JwtBearer; +using Microsoft.IdentityModel.Tokens; +using System.Text; +using System.Security.Claims; +using Microsoft.OpenApi.Models; var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddControllers(); builder.Services.AddApplicationServices(); +builder.Services.AddHttpContextAccessor(); builder.Services.AddPersistenceServices(builder.Configuration); builder.Services.AddInfrastructureServices(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); -builder.Services.AddSwaggerGen(m=> m.SwaggerDoc("v1",new Microsoft.OpenApi.Models.OpenApiInfo() + +builder.Services.AddSwaggerGen(c => { - Title = "Hypance Backend Project", - Version = "v1", - License = new Microsoft.OpenApi.Models.OpenApiLicense() { Name ="Hypance"} -})); + c.SwaggerDoc("v1", new OpenApiInfo { Title = "Hypance Backend Project", Version = "v1" }); + c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme() + { + Name = "Authorization", + Type = SecuritySchemeType.Http, + Scheme = "Bearer", + BearerFormat = "JWT", + In = ParameterLocation.Header, + Description = "JWT Authorization header using the Bearer scheme." + }); + c.AddSecurityRequirement(new OpenApiSecurityRequirement + { + { + new OpenApiSecurityScheme + { + Reference = new OpenApiReference + { + Type = ReferenceType.SecurityScheme, + Id = "Bearer" + } + }, + new string[] {} + } + }); +}); +builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) + .AddJwtBearer("Admin", options => + { + options.TokenValidationParameters = new() + { + ValidateAudience = true, //Olu�turulacak token de�erini kimlerin/hangi originlerin/sitelerin kullan�c� belirledi�imiz de�erdir. -> www.bilmemne.com + ValidateIssuer = true, //Olu�turulacak token de�erini kimin da��tt�n� ifade edece�imiz aland�r. -> www.myapi.com + ValidateLifetime = true, //Olu�turulan token de�erinin s�resini kontrol edecek olan do�rulamad�r. + ValidateIssuerSigningKey = true, //�retilecek token de�erinin uygulamam�za ait bir de�er oldu�unu ifade eden suciry key verisinin do�rulanmas�d�r. + + ValidAudience = builder.Configuration["Token:Audience"], + ValidIssuer = builder.Configuration["Token:Issuer"], + IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(builder.Configuration["Token:SecurityKey"])), + LifetimeValidator = (notBefore, expires, securityToken, validationParameters) => expires != null ? expires > DateTime.UtcNow : false, + + NameClaimType = ClaimTypes.Name //JWT �zerinde Name claimne kar��l�k gelen de�eri User.Identity.Name propertysinden elde edebiliriz. + }; + }); var app = builder.Build(); @@ -29,8 +75,12 @@ app.UseSwaggerUI(); } +app.UseHttpLogging(); +app.UseCors(); + app.UseHttpsRedirection(); +app.UseAuthentication(); app.UseAuthorization(); app.MapControllers();