Skip to content

Commit

Permalink
Closes #8
Browse files Browse the repository at this point in the history
  • Loading branch information
IliyanIlievPH committed Apr 10, 2020
1 parent a30cf3b commit 4e495e4
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
2 changes: 2 additions & 0 deletions settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ CustomerProfileService:
settings-key: UserManagementRabbitMQ
types:
- RabbitMq
IsPhoneVerificationDisabled:
settings-key: IsPhoneVerificationDisabled

DictionariesServiceClient:
ServiceUrl:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Data.Common;
using System.Data.Common;
using JetBrains.Annotations;
using Lykke.Common.MsSql;
using MAVN.Service.CustomerProfile.Domain.Enums;
Expand All @@ -12,8 +12,10 @@ public class CustomerProfileContext : MsSqlContext
{
private const string Schema = "customer_profile";

private readonly bool _isPhoneVerificationDisabled;

internal DbSet<AdminProfileEntity> AdminProfiles { get; set; }

internal DbSet<AdminProfileArchiveEntity> AdminProfilesArchive { get; set; }

internal DbSet<CustomerProfileEntity> CustomerProfiles { get; set; }
Expand All @@ -37,24 +39,28 @@ public class CustomerProfileContext : MsSqlContext
internal DbSet<ReferralFriendProfileArchiveEntity> ReferralFriendProfilesArchive { get; set; }

[UsedImplicitly]
public CustomerProfileContext()
public CustomerProfileContext(bool isPhoneVerificationDisabled = false)
: base(Schema)
{
_isPhoneVerificationDisabled = isPhoneVerificationDisabled;
}

public CustomerProfileContext(string connectionString, bool isTraceEnabled)
public CustomerProfileContext(string connectionString, bool isTraceEnabled, bool isPhoneVerificationDisabled = false)
: base(Schema, connectionString, isTraceEnabled)
{
_isPhoneVerificationDisabled = isPhoneVerificationDisabled;
}

public CustomerProfileContext(DbConnection dbConnection)
public CustomerProfileContext(DbConnection dbConnection, bool isPhoneVerificationDisabled = false)
: base(Schema, dbConnection)
{
_isPhoneVerificationDisabled = isPhoneVerificationDisabled;
}

public CustomerProfileContext(DbContextOptions contextOptions)
public CustomerProfileContext(DbContextOptions contextOptions, bool isPhoneVerificationDisabled = false)
: base(Schema, contextOptions)
{
_isPhoneVerificationDisabled = isPhoneVerificationDisabled;
}

protected override void OnLykkeModelCreating(ModelBuilder modelBuilder)
Expand All @@ -71,7 +77,7 @@ protected override void OnLykkeModelCreating(ModelBuilder modelBuilder)
builder.HasIndex(c => c.Status).IsUnique(false);

modelBuilder.Entity<CustomerProfileEntity>()
.HasQueryFilter(c => c.IsEmailVerified && c.IsPhoneVerified);
.HasQueryFilter(c => c.IsEmailVerified && (_isPhoneVerificationDisabled || c.IsPhoneVerified));

// configuring customer_profile_archive table
modelBuilder.Entity<CustomerProfileArchiveEntity>()
Expand Down
8 changes: 5 additions & 3 deletions src/MAVN.Service.CustomerProfile/Modules/DataLayerModule.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Autofac;
using Autofac;
using JetBrains.Annotations;
using Lykke.Common.MsSql;
using MAVN.Service.CustomerProfile.Domain.Repositories;
Expand All @@ -12,19 +12,21 @@ namespace MAVN.Service.CustomerProfile.Modules
[UsedImplicitly]
public class DataLayerModule : Module
{
private readonly bool _isPhoneVerificationDisabled;
private readonly string _connectionString;

public DataLayerModule(IReloadingManager<AppSettings> appSettings)
{
_isPhoneVerificationDisabled = appSettings.CurrentValue.CustomerProfileService.IsPhoneVerificationDisabled;
_connectionString = appSettings.CurrentValue.CustomerProfileService.Db.DataConnectionString;
}

protected override void Load(ContainerBuilder builder)
{
builder.RegisterMsSql(
_connectionString,
connString => new CustomerProfileContext(connString, false),
dbConn => new CustomerProfileContext(dbConn));
connString => new CustomerProfileContext(connString, false, isPhoneVerificationDisabled: _isPhoneVerificationDisabled),
dbConn => new CustomerProfileContext(dbConn, isPhoneVerificationDisabled: _isPhoneVerificationDisabled));

builder.RegisterType<AdminProfileRepository>()
.As<IAdminProfileRepository>()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using JetBrains.Annotations;
using JetBrains.Annotations;
using Lykke.SettingsReader.Attributes;

namespace MAVN.Service.CustomerProfile.Settings
{
Expand All @@ -8,5 +9,8 @@ public class CustomerProfileSettings
public DbSettings Db { get; set; }

public RabbitMqSettings RabbitMq { get; set; }

[Optional]
public bool IsPhoneVerificationDisabled { get; set; }
}
}

0 comments on commit 4e495e4

Please sign in to comment.