Add initial implementation of API, database, and user management components.
This commit is contained in:
24
MikrocopApi/Mappers/AuthMappingExtensions.cs
Normal file
24
MikrocopApi/Mappers/AuthMappingExtensions.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using MikrocopApi.Dtos;
|
||||
|
||||
namespace MikrocopApi.Mappers;
|
||||
|
||||
public static class AuthMappingExtensions
|
||||
{
|
||||
public static LoginResponseDto ToDto(this (string AccessToken, DateTime ExpiresAtUtc) token)
|
||||
{
|
||||
return new LoginResponseDto
|
||||
{
|
||||
AccessToken = token.AccessToken,
|
||||
ExpiresAtUtc = token.ExpiresAtUtc,
|
||||
TokenType = "Bearer"
|
||||
};
|
||||
}
|
||||
|
||||
public static ValidatePasswordResponseDto ToDto(this bool isValid)
|
||||
{
|
||||
return new ValidatePasswordResponseDto
|
||||
{
|
||||
IsValid = isValid
|
||||
};
|
||||
}
|
||||
}
|
||||
47
MikrocopApi/Mappers/UserMappingExtensions.cs
Normal file
47
MikrocopApi/Mappers/UserMappingExtensions.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using MikrocopApi.Dtos;
|
||||
using MikrocopDb.Entities;
|
||||
|
||||
namespace MikrocopApi.Mappers;
|
||||
|
||||
public static class UserMappingExtensions
|
||||
{
|
||||
public static UserEntity ToEntity(this CreateUserDto dto)
|
||||
{
|
||||
return new UserEntity
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
UserName = dto.UserName.Trim(),
|
||||
FullName = dto.FullName.Trim(),
|
||||
Email = dto.Email.Trim(),
|
||||
MobileNumber = dto.MobileNumber.Trim(),
|
||||
Language = dto.Language.Trim(),
|
||||
Culture = dto.Culture.Trim(),
|
||||
PasswordHash = string.Empty,
|
||||
PasswordSalt = string.Empty
|
||||
};
|
||||
}
|
||||
|
||||
public static void ApplyFromDto(this UserEntity entity, UpdateUserDto dto)
|
||||
{
|
||||
entity.UserName = dto.UserName.Trim();
|
||||
entity.FullName = dto.FullName.Trim();
|
||||
entity.Email = dto.Email.Trim();
|
||||
entity.MobileNumber = dto.MobileNumber.Trim();
|
||||
entity.Language = dto.Language.Trim();
|
||||
entity.Culture = dto.Culture.Trim();
|
||||
}
|
||||
|
||||
public static UserDto ToDto(this UserEntity entity)
|
||||
{
|
||||
return new UserDto
|
||||
{
|
||||
Id = entity.Id,
|
||||
UserName = entity.UserName,
|
||||
FullName = entity.FullName,
|
||||
Email = entity.Email,
|
||||
MobileNumber = entity.MobileNumber,
|
||||
Language = entity.Language,
|
||||
Culture = entity.Culture
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user