Skip to content
This repository has been archived by the owner on Oct 21, 2023. It is now read-only.

Commit

Permalink
webapi: add more logs around characteristics
Browse files Browse the repository at this point in the history
  • Loading branch information
verdie-g committed Aug 12, 2023
1 parent 330a902 commit 45fb756
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using Crpg.Application.Common.Results;
using FluentValidation;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using LoggerFactory = Crpg.Logging.LoggerFactory;

namespace Crpg.Application.Characters.Commands;

Expand All @@ -24,6 +26,8 @@ public Validator()

internal class Handler : IMediatorRequestHandler<ConvertCharacterCharacteristicsCommand, CharacterCharacteristicsViewModel>
{
private static readonly ILogger Logger = LoggerFactory.CreateLogger<RetireCharacterCommand>();

private readonly ICrpgDbContext _db;
private readonly IMapper _mapper;

Expand Down Expand Up @@ -65,6 +69,13 @@ public async Task<Result<CharacterCharacteristicsViewModel>> Handle(ConvertChara
}

await _db.SaveChangesAsync(cancellationToken);

(string from, string to) = req.Conversion == CharacterCharacteristicConversion.AttributesToSkills
? ("attributes", "skills")
: ("skills", "attributes");
Logger.LogInformation("User '{0}' converted characteristic points of character '{1}' from {2} to {3}",
req.UserId, req.CharacterId, from, to);

return new(_mapper.Map<CharacterCharacteristicsViewModel>(character.Characteristics));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using Crpg.Common.Helpers;
using Crpg.Domain.Entities.Characters;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using LoggerFactory = Crpg.Logging.LoggerFactory;

namespace Crpg.Application.Characters.Commands;

Expand All @@ -19,6 +21,8 @@ public record UpdateCharacterCharacteristicsCommand : IMediatorRequest<Character

internal class Handler : IMediatorRequestHandler<UpdateCharacterCharacteristicsCommand, CharacterCharacteristicsViewModel>
{
private static readonly ILogger Logger = LoggerFactory.CreateLogger<RetireCharacterCommand>();

private readonly ICrpgDbContext _db;
private readonly IMapper _mapper;
private readonly ICharacterClassResolver _characterClassResolver;
Expand Down Expand Up @@ -61,6 +65,9 @@ public async Task<Result<CharacterCharacteristicsViewModel>> Handle(UpdateCharac
character.Class = _characterClassResolver.ResolveCharacterClass(character.Characteristics);

await _db.SaveChangesAsync(cancellationToken);

Logger.LogInformation("User '{0}' update characteristics of character '{1}'", req.UserId, req.CharacterId);

return new(_mapper.Map<CharacterCharacteristicsViewModel>(character.Characteristics));
}

Expand Down

0 comments on commit 45fb756

Please sign in to comment.