Skip to content

Commit

Permalink
Merge pull request #14 from OpenMAVN/10-add-admin-email-verified
Browse files Browse the repository at this point in the history
#10 fix mapping fields for AdminProfile
  • Loading branch information
vitaliidasaev committed Apr 28, 2020
2 parents d6ff124 + 9df11a8 commit 0012d83
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,6 @@ public AdminProfileEntity()
[EncryptedProperty]
public string JobTitle { get; set; }

internal static AdminProfileEntity Create(AdminProfile adminProfile)
{
return new AdminProfileEntity
{
AdminId = adminProfile.AdminId,
FirstName = adminProfile.FirstName,
LastName = adminProfile.LastName,
Email = adminProfile.Email,
IsEmailVerified = adminProfile.IsEmailVerified,
PhoneNumber = adminProfile.PhoneNumber,
Company = adminProfile.Company,
Department = adminProfile.Department,
JobTitle = adminProfile.JobTitle
};
}

internal void Update(AdminProfile adminProfile)
{
AdminId = adminProfile.AdminId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AutoMapper;
using Falcon.Common.Encryption;
using Lykke.Common.MsSql;
using MAVN.Service.CustomerProfile.Domain.Enums;
Expand All @@ -15,13 +16,16 @@ namespace MAVN.Service.CustomerProfile.MsSqlRepositories.Repositories
public class AdminProfileRepository : IAdminProfileRepository
{
private readonly MsSqlContextFactory<CustomerProfileContext> _contextFactory;
private readonly IMapper _mapper;
private readonly IEncryptionService _encryptionService;

public AdminProfileRepository(
MsSqlContextFactory<CustomerProfileContext> contextFactory,
IMapper mapper,
IEncryptionService encryptionService)
{
_contextFactory = contextFactory;
_mapper = mapper;
_encryptionService = encryptionService;
}

Expand All @@ -32,7 +36,7 @@ public async Task<IReadOnlyList<AdminProfile>> GetAllAsync()
var entities = await context.AdminProfiles.ToListAsync();

return entities
.Select(entity => ToDomain(_encryptionService.Decrypt(entity)))
.Select(entity => _mapper.Map<AdminProfile>(_encryptionService.Decrypt(entity)))
.ToList();
}
}
Expand All @@ -46,7 +50,7 @@ public async Task<IReadOnlyList<AdminProfile>> GetAsync(IReadOnlyList<Guid> iden
.ToListAsync();

return entities
.Select(entity => ToDomain(_encryptionService.Decrypt(entity)))
.Select(entity => _mapper.Map<AdminProfile>(_encryptionService.Decrypt(entity)))
.ToList();
}
}
Expand All @@ -57,7 +61,7 @@ public async Task<AdminProfile> GetByIdAsync(Guid adminId)
{
var entity = await context.AdminProfiles.FindAsync(adminId);

return entity != null ? ToDomain(_encryptionService.Decrypt(entity)) : null;
return entity != null ? _mapper.Map<AdminProfile>(_encryptionService.Decrypt(entity)) : null;
}
}

Expand All @@ -70,7 +74,7 @@ public async Task<AdminProfileErrorCodes> InsertAsync(AdminProfile adminProfile)
if (entity != null)
return AdminProfileErrorCodes.AdminProfileAlreadyExists;

entity = AdminProfileEntity.Create(adminProfile);
entity = _mapper.Map<AdminProfileEntity>(adminProfile);

entity = _encryptionService.Encrypt(entity);

Expand Down Expand Up @@ -151,18 +155,5 @@ public async Task DeleteAsync(Guid adminId)
return (AdminProfileErrorCodes.None, wasEmailPreviouslyVerified);
}
}

private static AdminProfile ToDomain(AdminProfileEntity entity)
=> new AdminProfile
{
AdminId = entity.AdminId,
FirstName = entity.FirstName,
LastName = entity.LastName,
Email = entity.Email,
PhoneNumber = entity.PhoneNumber,
Company = entity.Company,
Department = entity.Department,
JobTitle = entity.JobTitle,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@
using MAVN.Service.CustomerProfile.Client.Models.Responses;
using MAVN.Service.CustomerProfile.Domain.Enums;
using MAVN.Service.CustomerProfile.Domain.Models;
using MAVN.Service.CustomerProfile.MsSqlRepositories.Entities;

namespace MAVN.Service.CustomerProfile.MappingProfiles
{
public class AutoMapperProfile : Profile
{
public AutoMapperProfile()
{
// entity and domain model
CreateMap<AdminProfileEntity, Domain.Models.AdminProfile>();
CreateMap<Domain.Models.AdminProfile, AdminProfileEntity>()
.ForMember(dest => dest.WasEmailEverVerified, src => src.Ignore());
// domain model and client model
CreateMap<Domain.Models.AdminProfile, Client.Models.Responses.AdminProfile>(MemberList.Source);
CreateMap<Client.Models.Responses.AdminProfile, Domain.Models.AdminProfile>(MemberList.Destination);
CreateMap<AdminProfileRequest, Domain.Models.AdminProfile>()
Expand Down

0 comments on commit 0012d83

Please sign in to comment.