Refactors application layer abstractions#48
Conversation
Moves the Result abstraction from the Application layer to the Domain layer. This change promotes a cleaner architecture by aligning the Result type with core domain concepts, improving maintainability and reducing dependencies on the Application layer. Updates Telegram.Bot package to version 22.7.2.
WalkthroughAtualização do pacote Telegram.Bot para 22.7.2 e migração de referências de namespace de Changes
Estimated code review effort🎯 3 (Moderado) | ⏱️ ~20 minutos Possibly related PRs
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
InvoiceReminder.API.UnitTests/Endpoints/ScanEmailDefinitionEndpointsTests.cs (1)
468-481: Teste configura o método errado no mock (nome incorreto).Configura
GetBySenderBeneficiaryAsyncmas validaGetBySenderEmailAddressAsync; o teste falha.Corrija:
- _ = _scanEmailDefinitionAppService.GetBySenderBeneficiaryAsync(Arg.Any<string>(), Arg.Any<Guid>()) - .ThrowsAsync(new ArgumentException("Service error")); + _ = _scanEmailDefinitionAppService.GetBySenderEmailAddressAsync(Arg.Any<string>(), Arg.Any<Guid>()) + .ThrowsAsync<ArgumentException>();
🧹 Nitpick comments (6)
InvoiceReminder.Domain/Abstractions/Result.cs (1)
5-7: Aprimorar anotações de nulabilidade para reduzir warnings e deixar a intenção explícita.Permite
Errornulo em sucesso e documenta queValuepode ser default em falha, sem quebrar usos com tipos valor.Aplique:
+using System.Diagnostics.CodeAnalysis; -namespace InvoiceReminder.Domain.Abstractions; +namespace InvoiceReminder.Domain.Abstractions; public class Result<T> { public bool IsSuccess { get; } - public T Value { get; } - public string Error { get; } + [MaybeNull] public T Value { get; } + public string? Error { get; } - protected Result(bool isSuccess, T value, string error) + protected Result(bool isSuccess, [AllowNull] T value, string? error) { IsSuccess = isSuccess; Value = value; Error = error; }Also applies to: 9-24
InvoiceReminder.Application/AppServices/BaseAppService.cs (1)
47-54: Evitar dupla enumeração em GetAll().Materialize antes de checar vazio e mapear.
public virtual Result<IEnumerable<TEntityViewModel>> GetAll() { - var entities = _repository.GetAll(); - - return !entities.Any() - ? Result<IEnumerable<TEntityViewModel>>.Failure($"Empty Result.") - : Result<IEnumerable<TEntityViewModel>>.Success(entities.Adapt<IEnumerable<TEntityViewModel>>()); + var entities = _repository.GetAll(); + var list = entities as ICollection<TEntity> ?? entities.ToList(); + return list.Count == 0 + ? Result<IEnumerable<TEntityViewModel>>.Failure("Empty Result.") + : Result<IEnumerable<TEntityViewModel>>.Success(list.Adapt<IEnumerable<TEntityViewModel>>()); }InvoiceReminder.Application/AppServices/InvoiceAppService.cs (1)
19-26: Validar entrada do barcode.Evita chamada ao repositório com string nula/vazia.
public async Task<Result<InvoiceViewModel>> GetByBarcodeAsync(string value) { + if (string.IsNullOrWhiteSpace(value)) + { + return Result<InvoiceViewModel>.Failure($"Parameter {nameof(value)} was Null or Empty."); + } var entity = await _repository.GetByBarCodeAsync(value); return entity is null ? Result<InvoiceViewModel>.Failure("Invoice not Found.") : Result<InvoiceViewModel>.Success(entity.Adapt<InvoiceViewModel>()); }InvoiceReminder.API.UnitTests/Endpoints/InvoiceEndpointsTests.cs (1)
501-503: URLs com e sem barra final — padronizar para evitar flutuação de roteamentoHá chamadas com “/api/invoice/” e “/api/invoice”. Sugiro padronizar (com ou sem “/”) para manter consistência nos testes e nos endpoints.
Also applies to: 599-601
InvoiceReminder.Application/Interfaces/IUserAppService.cs (2)
9-9: Nome do parâmetro pode refletir melhor o domínioTrocar "value" por "email" melhora a clareza sem impacto funcional.
- Task<Result<UserViewModel>> GetByEmailAsync(string value); + Task<Result<UserViewModel>> GetByEmailAsync(string email);
7-10: Considere aceitar CancellationToken nas operações async do AppServiceFacilita cancelamento e propagação de timeouts; é mudança opcional porém breaking para implementações.
- public interface IUserAppService : IBaseAppService<User, UserViewModel> + public interface IUserAppService : IBaseAppService<User, UserViewModel> { - Task<Result<UserViewModel>> GetByEmailAsync(string email); + Task<Result<UserViewModel>> GetByEmailAsync(string email, System.Threading.CancellationToken cancellationToken = default); }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (17)
Directory.Packages.props(2 hunks)InvoiceReminder.API.UnitTests/Endpoints/InvoiceEndpointsTests.cs(1 hunks)InvoiceReminder.API.UnitTests/Endpoints/JobScheduleEndPointsTests.cs(1 hunks)InvoiceReminder.API.UnitTests/Endpoints/LoginEndpointTests.cs(1 hunks)InvoiceReminder.API.UnitTests/Endpoints/ScanEmailDefinitionEndpointsTests.cs(1 hunks)InvoiceReminder.API.UnitTests/Endpoints/UserEndpointsTests.cs(1 hunks)InvoiceReminder.Application/AppServices/BaseAppService.cs(1 hunks)InvoiceReminder.Application/AppServices/InvoiceAppService.cs(1 hunks)InvoiceReminder.Application/AppServices/JobScheduleAppService.cs(1 hunks)InvoiceReminder.Application/AppServices/ScanEmailDefinitionAppService.cs(1 hunks)InvoiceReminder.Application/AppServices/UserAppService.cs(1 hunks)InvoiceReminder.Application/Interfaces/IBaseAppService.cs(1 hunks)InvoiceReminder.Application/Interfaces/IInvoiceAppService.cs(1 hunks)InvoiceReminder.Application/Interfaces/IJobScheduleAppService.cs(1 hunks)InvoiceReminder.Application/Interfaces/IScanEmailDefinitionAppService.cs(1 hunks)InvoiceReminder.Application/Interfaces/IUserAppService.cs(1 hunks)InvoiceReminder.Domain/Abstractions/Result.cs(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (13)
InvoiceReminder.Application/Interfaces/IInvoiceAppService.cs (4)
InvoiceReminder.Application.UnitTests/AppServices/InvoiceAppServiceTests.cs (1)
InvoiceAppServiceTests(11-95)InvoiceReminder.Data/Interfaces/IInvoiceRepository.cs (1)
IInvoiceRepository(5-8)InvoiceReminder.ArchitectureTests/Services/AppServicesTests.cs (1)
AppServicesTests(9-67)InvoiceReminder.Domain/Entities/Invoice.cs (1)
Invoice(3-11)
InvoiceReminder.Application/AppServices/InvoiceAppService.cs (1)
InvoiceReminder.ArchitectureTests/Services/AppServicesTests.cs (1)
AppServicesTests(9-67)
InvoiceReminder.API.UnitTests/Endpoints/JobScheduleEndPointsTests.cs (2)
InvoiceReminder.ArchitectureTests/Domain/ExtensionsTests.cs (1)
ExtensionsTests(7-28)InvoiceReminder.ArchitectureTests/Domain/EntitiesTests.cs (1)
GivenDomainLayer_ThenShouldNotHaveAnyDependencies(10-22)
InvoiceReminder.API.UnitTests/Endpoints/UserEndpointsTests.cs (1)
InvoiceReminder.ArchitectureTests/Presentation/EndpointsTests.cs (3)
EndpointsTests(7-43)GivenPresentationLayer_EndpointsMustdBeImplementedAsFollow(24-42)GivenPresentationLayer_ThenShouldNotHaveAnyDependencies(10-22)
InvoiceReminder.Application/Interfaces/IScanEmailDefinitionAppService.cs (4)
InvoiceReminder.Domain/Entities/ScanEmailDefinition.cs (1)
ScanEmailDefinition(5-13)InvoiceReminder.Data/Interfaces/IScanEmailDefinitionRepository.cs (1)
IScanEmailDefinitionRepository(5-10)InvoiceReminder.Application.UnitTests/AppServices/ScanEmailDefinitionAppServiceTests.cs (1)
ScanEmailDefinitionAppServiceTests(12-224)InvoiceReminder.Application/ViewModels/ScanEmailDefinitionViewModel.cs (1)
ScanEmailDefinitionViewModel(5-29)
InvoiceReminder.Application/Interfaces/IJobScheduleAppService.cs (1)
InvoiceReminder.Application.UnitTests/AppServices/JobScheduleAppServiceTests.cs (1)
JobScheduleAppServiceTests(13-154)
InvoiceReminder.API.UnitTests/Endpoints/LoginEndpointTests.cs (1)
InvoiceReminder.ArchitectureTests/Presentation/EndpointsTests.cs (3)
EndpointsTests(7-43)GivenPresentationLayer_ThenShouldNotHaveAnyDependencies(10-22)GivenPresentationLayer_EndpointsMustdBeImplementedAsFollow(24-42)
InvoiceReminder.API.UnitTests/Endpoints/InvoiceEndpointsTests.cs (1)
InvoiceReminder.ArchitectureTests/Presentation/EndpointsTests.cs (3)
EndpointsTests(7-43)GivenPresentationLayer_ThenShouldNotHaveAnyDependencies(10-22)GivenPresentationLayer_EndpointsMustdBeImplementedAsFollow(24-42)
Directory.Packages.props (1)
InvoiceReminder.Services/BackgroundServices/TelegramBotBackgroundService.cs (1)
TelegramUpdateHandler(65-157)
InvoiceReminder.Application/AppServices/JobScheduleAppService.cs (2)
InvoiceReminder.Data/Migrations/20250509040148_Initial_Create.Designer.cs (2)
Initial_Create(14-259)b(29-80)InvoiceReminder.Data/Persistence/CoreDbContext.cs (1)
CoreDbContext(6-49)
InvoiceReminder.Application/Interfaces/IUserAppService.cs (1)
InvoiceReminder.Data/Interfaces/IUserRepository.cs (1)
IUserRepository(5-9)
InvoiceReminder.Domain/Abstractions/Result.cs (1)
InvoiceReminder.Application/Abstractions/Result.cs (3)
Result(3-25)Success(16-19)Result(9-14)
InvoiceReminder.Application/AppServices/BaseAppService.cs (1)
InvoiceReminder.Data/Migrations/CoreDbContextModelSnapshot.cs (3)
InvoiceReminder.Data.Migrations(12-259)CoreDbContextModelSnapshot(14-258)b(171-219)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Analyze (csharp)
🔇 Additional comments (19)
InvoiceReminder.Application/Interfaces/IBaseAppService.cs (2)
1-1: Migração de namespace para Domain.Abstractions confirmada.Alinha o contrato da aplicação com o novo local do Result. Sem impacto nas assinaturas.
7-13: Sem referências remanescentes a InvoiceReminder.Application.Abstractions ou InvoiceReminder.Domain.Abstractions. Não foram encontradas correspondências na base de código nem no projeto API.Directory.Packages.props (1)
45-45: Confirmado bump do Telegram.Bot para 22.7.2
22.7.2 é a versão mais recente no NuGet (atualizada em 03/09/2025) e traz correções de tipo em TopicId, StarCount e Amount, além de ajuste na posição do parâmetro messageThreadId em SendPaidMedia.
Pode prosseguir com a atualização.InvoiceReminder.Domain/Abstractions/Result.cs (1)
1-1: Namespace movido para Domain.Abstractions — OK.Mantém API pública inalterada; mudança organizacional coerente.
InvoiceReminder.Application/AppServices/BaseAppService.cs (1)
3-3: Import atualizado para Domain.Abstractions — OK.InvoiceReminder.API.UnitTests/Endpoints/ScanEmailDefinitionEndpointsTests.cs (1)
4-4: Import trocado para Domain.Abstractions — OK.InvoiceReminder.API.UnitTests/Endpoints/LoginEndpointTests.cs (1)
8-8: Import para Domain.Abstractions atualizado — OK.InvoiceReminder.Application/AppServices/InvoiceAppService.cs (1)
4-4: Import atualizado — OK.InvoiceReminder.Application/Interfaces/IJobScheduleAppService.cs (1)
2-2: Import movido para Domain.Abstractions — OK.InvoiceReminder.API.UnitTests/Endpoints/JobScheduleEndPointsTests.cs (1)
4-4: Migração completa e verificadaNão há referências remanescentes a
InvoiceReminder.Application.Abstractions, o projetoInvoiceReminder.APInão possui usings deInvoiceReminder.Domain.*e os testes já utilizamInvoiceReminder.Domain.Abstractions.InvoiceReminder.Application/AppServices/ScanEmailDefinitionAppService.cs (1)
4-4: Import para Domain.Abstractions consistenteAlinha o AppService ao novo local de Result. Sem impactos de lógica.
InvoiceReminder.API.UnitTests/Endpoints/UserEndpointsTests.cs (1)
4-4: Import atualizado — testes continuam alinhados ao novo ResultMudança mínima e correta.
InvoiceReminder.API.UnitTests/Endpoints/InvoiceEndpointsTests.cs (2)
4-4: Import para Domain.Abstractions — OKMantém os testes compatíveis com a migração do Result.
1-1: Validar bump do Telegram.Bot (22.7.2)
Confirme que, após a atualização para a versão 22.7.2, não houve breaking changes nas integrações com o Telegram: execute testes de integração ou um teste de ponta a ponta envolvendo oTelegramMessageServicee oTelegramBotBackgroundServicepara envio e recebimento de mensagens sem erros.InvoiceReminder.Application/AppServices/JobScheduleAppService.cs (1)
4-4: Import migrado corretamenteAppService agora referencia Domain.Abstractions; compatível com o novo posicionamento do Result.
InvoiceReminder.Application/Interfaces/IInvoiceAppService.cs (1)
2-2: Interface atualizada para Domain.Abstractions — OKSem alterações de contrato público; apenas o namespace de Result.
InvoiceReminder.Application/Interfaces/IScanEmailDefinitionAppService.cs (1)
2-2: Import para Domain.Abstractions — OKCoerente com a migração do Result.
InvoiceReminder.Application/AppServices/UserAppService.cs (1)
4-4: Import migrado — OKMantém a lógica intacta e usa o novo Result do Domínio.
InvoiceReminder.Application/Interfaces/IUserAppService.cs (1)
2-2: Aprovado: nenhuma referência ao namespace antigo encontrada
Não foram encontradas referências aInvoiceReminder.Application.Abstractionsem nenhum arquivo .cs (excluindo bin/ e obj/). Mudança de namespace paraInvoiceReminder.Domain.Abstractionsestá correta.
Modifies the unit test to assert that a specific ApplicationException is thrown, providing a more accurate and reliable test case.
Moves the Result abstraction from the Application layer to the Domain layer.
This change promotes a cleaner architecture by aligning the Result type with core domain concepts, improving maintainability and reducing dependencies on the Application layer.
Updates Telegram.Bot package to version 22.7.2.
✨
Description by Callstackai
This PR refactors the application layer abstractions by moving the
Resulttype from the Application layer to the Domain layer, updates theTelegram.Botpackage to version 22.7.2, and adjusts the necessary imports in the unit tests and application services.Diagrams of code changes
sequenceDiagram participant Client participant API participant AppService participant Domain Note over Domain: New Result<T> class added Client->>API: Make API request API->>AppService: Forward request AppService->>Domain: Process using Result<T> alt Exception Case Domain-->>AppService: Throw ApplicationException AppService-->>API: Return Error Result API-->>Client: Return Error Response else Success Case Domain-->>AppService: Return Success Result AppService-->>API: Return Success Result API-->>Client: Return Success Response endFiles Changed
Telegram.Botpackage version from 22.7.1 to 22.7.2.InvoiceReminder.Application.AbstractionstoInvoiceReminder.Domain.Abstractions.InvoiceReminder.Application.AbstractionstoInvoiceReminder.Domain.Abstractions.InvoiceReminder.Application.AbstractionstoInvoiceReminder.Domain.Abstractions.InvoiceReminder.Application.AbstractionstoInvoiceReminder.Domain.Abstractions.InvoiceReminder.Application.AbstractionstoInvoiceReminder.Domain.Abstractions.InvoiceReminder.Application.AbstractionstoInvoiceReminder.Domain.Abstractions.InvoiceReminder.Application.AbstractionstoInvoiceReminder.Domain.Abstractions.InvoiceReminder.Application.AbstractionstoInvoiceReminder.Domain.Abstractions.InvoiceReminder.Application.AbstractionstoInvoiceReminder.Domain.Abstractions.InvoiceReminder.Application.AbstractionstoInvoiceReminder.Domain.Abstractions.InvoiceReminder.Application.AbstractionstoInvoiceReminder.Domain.Abstractions.InvoiceReminder.Application.AbstractionstoInvoiceReminder.Domain.Abstractions.InvoiceReminder.Application.AbstractionstoInvoiceReminder.Domain.Abstractions.InvoiceReminder.Application.AbstractionstoInvoiceReminder.Domain.Abstractions.InvoiceReminder.Application.AbstractionstoInvoiceReminder.Domain.Abstractions.InvoiceReminder.Application.AbstractionstoInvoiceReminder.Domain.Abstractions.This PR includes files in programming languages that we currently do not support. We have not reviewed files with the extensions
.props,.cs. See list of supported languages.Summary by CodeRabbit