This repository has been archived by the owner on Feb 6, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of https://github.com/noordwind/Coolector into…
… develop
- Loading branch information
Showing
11 changed files
with
103 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/Services/Coolector.Services.Storage/Framework/IoC/MapperModule.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using Autofac; | ||
using Coolector.Common.DTO.Users; | ||
using Coolector.Services.Storage.Mappers; | ||
|
||
namespace Coolector.Services.Storage.Framework.IoC | ||
{ | ||
public class MapperModule : Module | ||
{ | ||
protected override void Load(ContainerBuilder builder) | ||
{ | ||
builder.RegisterType<UserMapper>().As<IMapper<UserDto>>(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Coolector.Services.Storage.Mappers | ||
{ | ||
public interface IMapper<out T> | ||
{ | ||
T Map(dynamic source); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/Services/Coolector.Services.Storage/Mappers/UserMapper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using Coolector.Common.DTO.Users; | ||
|
||
namespace Coolector.Services.Storage.Mappers | ||
{ | ||
public class UserMapper : IMapper<UserDto> | ||
{ | ||
public UserDto Map(dynamic source) | ||
{ | ||
return new UserDto | ||
{ | ||
Id = source.id, | ||
UserId = source.userId, | ||
Email = source.email, | ||
Name = source.name, | ||
Role = source.role, | ||
State = source.state, | ||
CreatedAt = source.createdAt | ||
}; | ||
} | ||
} | ||
} |
5 changes: 3 additions & 2 deletions
5
src/Services/Coolector.Services.Storage/Providers/IProviderClient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Coolector.Common.Types; | ||
using Coolector.Services.Storage.Mappers; | ||
|
||
namespace Coolector.Services.Storage.Providers | ||
{ | ||
public interface IProviderClient | ||
{ | ||
Task<Maybe<T>> GetAsync<T>(string url, string endpoint) where T : class; | ||
Task<Maybe<T>> GetAsync<T>(string url, string endpoint, IMapper<T> mapper) where T : class; | ||
Task<Maybe<T>> GetUsingStorageAsync<T>(string url, string endpoint, | ||
Func<Task<Maybe<T>>> storageFetch, Func<T, Task> storageSave) where T : class; | ||
Func<Task<Maybe<T>>> storageFetch, Func<T, Task> storageSave, IMapper<T> mapper) where T : class; | ||
} | ||
} |
3 changes: 2 additions & 1 deletion
3
src/Services/Coolector.Services.Storage/Providers/IServiceClient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
using System.Threading.Tasks; | ||
using Coolector.Common.Types; | ||
using Coolector.Services.Storage.Mappers; | ||
|
||
namespace Coolector.Services.Storage.Providers | ||
{ | ||
public interface IServiceClient | ||
{ | ||
Task<Maybe<T>> GetAsync<T>(string url, string endpoint) where T : class; | ||
Task<Maybe<T>> GetAsync<T>(string url, string endpoint, IMapper<T> mapper) where T : class; | ||
} | ||
} |
31 changes: 0 additions & 31 deletions
31
src/Services/Coolector.Services.Storage/Providers/IUserProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,11 @@ | ||
using System.Threading.Tasks; | ||
using Coolector.Common.DTO.Users; | ||
using Coolector.Common.Types; | ||
using Coolector.Services.Storage.Repositories; | ||
using Coolector.Services.Storage.Settings; | ||
|
||
namespace Coolector.Services.Storage.Providers | ||
{ | ||
public interface IUserProvider | ||
{ | ||
Task<Maybe<UserDto>> GetAsync(string userId); | ||
} | ||
|
||
public class UserProvider : IUserProvider | ||
{ | ||
private readonly IUserRepository _userRepository; | ||
private readonly IProviderClient _providerClient; | ||
private readonly ProviderSettings _providerSettings; | ||
|
||
public UserProvider(IUserRepository userRepository, | ||
IProviderClient providerClient, | ||
ProviderSettings providerSettings) | ||
{ | ||
_userRepository = userRepository; | ||
_providerClient = providerClient; | ||
_providerSettings = providerSettings; | ||
} | ||
|
||
public async Task<Maybe<UserDto>> GetAsync(string userId) | ||
=> await _providerClient.GetUsingStorageAsync(_providerSettings.UsersApiUrl, $"users/{userId}", | ||
async () => | ||
{ | ||
var user = await _userRepository.GetByIdAsync(userId); | ||
|
||
return user.HasValue ? user.Value : new Maybe<UserDto>(); | ||
}, | ||
async user => | ||
{ | ||
await _userRepository.AddAsync(user); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/Services/Coolector.Services.Storage/Providers/UserProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System.Threading.Tasks; | ||
using Coolector.Common.DTO.Users; | ||
using Coolector.Common.Types; | ||
using Coolector.Services.Storage.Mappers; | ||
using Coolector.Services.Storage.Repositories; | ||
using Coolector.Services.Storage.Settings; | ||
|
||
namespace Coolector.Services.Storage.Providers | ||
{ | ||
public class UserProvider : IUserProvider | ||
{ | ||
private readonly IUserRepository _userRepository; | ||
private readonly IProviderClient _providerClient; | ||
private readonly ProviderSettings _providerSettings; | ||
private readonly IMapper<UserDto> _mapper; | ||
|
||
public UserProvider(IUserRepository userRepository, | ||
IProviderClient providerClient, | ||
ProviderSettings providerSettings, | ||
IMapper<UserDto> mapper) | ||
{ | ||
_userRepository = userRepository; | ||
_providerClient = providerClient; | ||
_providerSettings = providerSettings; | ||
_mapper = mapper; | ||
} | ||
|
||
public async Task<Maybe<UserDto>> GetAsync(string userId) | ||
=> await _providerClient.GetUsingStorageAsync(_providerSettings.UsersApiUrl, $"users/{userId}", | ||
async () => | ||
{ | ||
var user = await _userRepository.GetByIdAsync(userId); | ||
|
||
return user.HasValue ? user.Value : new Maybe<UserDto>(); | ||
}, | ||
async user => | ||
{ | ||
await _userRepository.AddAsync(user); | ||
}, | ||
_mapper); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters