-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Have configured cache with redis, added handler to each response, fix…
…ed json settings, changed docker-compose.yml
- Loading branch information
Showing
37 changed files
with
341 additions
and
108 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
WeatherBotApi.DatabaseApp/Core/DatabaseApp.Application/DependencyInjection.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
12 changes: 7 additions & 5 deletions
12
...p.IntegrationEvents/IntegrationEventHandlers/GetAllUsersRequestIntegrationEventHandler.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,18 +1,20 @@ | ||
using System.Text.Json; | ||
using DatabaseApp.Application.Users.Queries.GetAllUsers; | ||
using MediatR; | ||
using TelegramBotApp.Domain.Responses; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using TelegramBotApp.Messaging.IntegrationContext; | ||
using TelegramBotApp.Messaging.IntegrationContext.UserIntegrationEvents; | ||
using TelegramBotApp.Messaging.IntegrationResponseContext.IntegrationResponses; | ||
|
||
namespace DatabaseApp.IntegrationEvents.IntegrationEventHandlers; | ||
|
||
public class GetAllUsersRequestIntegrationEventHandler(ISender mediator) | ||
public class GetAllUsersRequestIntegrationEventHandler(IServiceScopeFactory factory) | ||
: IIntegrationEventHandler<GetAllUsersRequestIntegrationEvent> | ||
{ | ||
public async Task<UniversalResponse?> Handle(GetAllUsersRequestIntegrationEvent @event) | ||
public async Task<IResponseMessage?> Handle(GetAllUsersRequestIntegrationEvent @event) | ||
{ | ||
using var scope = factory.CreateScope(); | ||
var mediator = scope.ServiceProvider.GetRequiredService<IMediator>(); | ||
var users = await mediator.Send(new GetAllUsersQuery()); | ||
return new(JsonSerializer.Serialize(users.Select(u => u.TelegramId))); | ||
return new AllUsersResponse { UserTelegramIds = users.Select(u => u.TelegramId).ToList() }; | ||
} | ||
} |
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
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
1 change: 1 addition & 0 deletions
1
...legramBotApp/Core/TelegramBotApp.Application/TelegramBotContext/TelegramBotInitializer.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
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
6 changes: 0 additions & 6 deletions
6
WeatherBotApi.TelegramBotApp/Core/TelegramBotApp.Domain/Responses/UniversalResponse.cs
This file was deleted.
Oops, something went wrong.
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
20 changes: 20 additions & 0 deletions
20
WeatherBotApi.TelegramBotApp/Infrastructure/TelegramBotApp.Caching/Caching/CacheService.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,20 @@ | ||
using System.Text.Json; | ||
using Microsoft.Extensions.Caching.Distributed; | ||
|
||
namespace TelegramBotApp.Caching.Caching; | ||
|
||
public class CacheService(IDistributedCache distributedCache) : ICacheService | ||
{ | ||
public async Task<T?> GetAsync<T>(string key, CancellationToken cancellationToken = default) where T : class | ||
{ | ||
var value = await distributedCache.GetStringAsync(key, cancellationToken); | ||
|
||
return value == null ? null : JsonSerializer.Deserialize<T>(value); | ||
} | ||
|
||
public async Task SetAsync<T>(string key, T value, CancellationToken cancellationToken = default) where T : class => | ||
await distributedCache.SetStringAsync(key, JsonSerializer.Serialize(value), cancellationToken); | ||
|
||
public async Task RemoveAsync(string key, CancellationToken cancellationToken = default) => | ||
await distributedCache.RemoveAsync(key, cancellationToken); | ||
} |
8 changes: 8 additions & 0 deletions
8
WeatherBotApi.TelegramBotApp/Infrastructure/TelegramBotApp.Caching/Caching/Interfaces.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,8 @@ | ||
namespace TelegramBotApp.Caching.Caching; | ||
|
||
public interface ICacheService | ||
{ | ||
public Task<T?> GetAsync<T>(string key, CancellationToken cancellationToken = default) where T : class; | ||
public Task SetAsync<T>(string key, T value, CancellationToken cancellationToken = default) where T : class; | ||
public Task RemoveAsync(string key, CancellationToken cancellationToken = default); | ||
} |
14 changes: 14 additions & 0 deletions
14
WeatherBotApi.TelegramBotApp/Infrastructure/TelegramBotApp.Caching/DependencyInjection.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 Microsoft.Extensions.DependencyInjection; | ||
using TelegramBotApp.Caching.Caching; | ||
|
||
namespace TelegramBotApp.Caching; | ||
|
||
public static class DependencyInjection | ||
{ | ||
// ReSharper disable once UnusedMethodReturnValue.Global | ||
public static IServiceCollection AddCaching(this IServiceCollection services) | ||
{ | ||
services.AddSingleton<ICacheService, CacheService>(); | ||
return services; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...BotApi.TelegramBotApp/Infrastructure/TelegramBotApp.Caching/TelegramBotApp.Caching.csproj
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,13 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="8.0.1" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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
Oops, something went wrong.