Skip to content

Commit

Permalink
more logs, version 1.29.1
Browse files Browse the repository at this point in the history
  • Loading branch information
granstel committed Aug 28, 2024
1 parent 2e1904f commit db3f1e2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Dodo1000Bot.Api/Dodo1000Bot.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Version>1.29.0</Version>
<Version>1.29.1</Version>
<UserSecretsId>f449de95-800a-40ef-8716-6e80b7f0977d</UserSecretsId>
</PropertyGroup>

Expand Down
2 changes: 2 additions & 0 deletions Dodo1000Bot.Services/NotificationsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Threading.Tasks;
using Dodo1000Bot.Models;
using Dodo1000Bot.Models.Domain;
using Dodo1000Bot.Services.Extensions;
using Microsoft.Extensions.Logging;

namespace Dodo1000Bot.Services;
Expand All @@ -25,6 +26,7 @@ public NotificationsService(ILogger<NotificationsService> logger, IEnumerable<IN

public async Task Save(Notification notification, CancellationToken cancellationToken)
{
_logger.LogInformation("Save to DB: {notification}", notification.Serialize());
if (string.IsNullOrEmpty(notification?.Payload?.Text))
{
_logger.LogWarning("Text of notification payload is null or empty");
Expand Down
11 changes: 8 additions & 3 deletions Dodo1000Bot.Services/Repositories/NotificationsRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,36 @@
using Dapper;
using Dodo1000Bot.Models;
using Dodo1000Bot.Models.Domain;
using Dodo1000Bot.Services.Extensions;
using Microsoft.Extensions.Logging;
using MySql.Data.MySqlClient;

namespace Dodo1000Bot.Services;

public class NotificationsRepository : INotificationsRepository
{
private readonly ILogger<NotificationsRepository> _logger;
private readonly MySqlConnection _connection;

public NotificationsRepository(MySqlConnection connection)
public NotificationsRepository(ILogger<NotificationsRepository> logger, MySqlConnection connection)
{
_logger = logger;
_connection = connection;
}

public async Task Save(Notification notification, CancellationToken cancellationToken)
{
var payload = JsonSerializer.Serialize(notification?.Payload);

await _connection.ExecuteAsync(new CommandDefinition(
_logger.LogInformation("Save to DB: {payload}, {distinction}", payload, notification?.Distinction);
var rowsAffected = await _connection.ExecuteAsync(new CommandDefinition(
"INSERT IGNORE INTO notifications (Type, Payload, Distinction) VALUES (@type, @payload, @distinction)",
new
{
notification?.Type,
payload,
notification?.Distinction
}, cancellationToken: cancellationToken));
_logger.LogInformation("{rowsAffected} rows affected", rowsAffected);
}

public async Task<IList<Notification>> GetNotPushedNotifications(CancellationToken cancellationToken)
Expand Down

0 comments on commit db3f1e2

Please sign in to comment.