Skip to content

Commit

Permalink
feat: implement basic query and add (#65)
Browse files Browse the repository at this point in the history
* refactor: move pages out of WASM project

* refactor: move pages out of WASM project

rebase main

* rename bank into account

* refactor: merge tiny modules into a single file

* refactor: make folder structure more clear by grouping commands&queries by its function rather than its fields

* feat: remove test queries in test.razor

* feat: working on wallet.razor

* fix

* refactor: Code Format

* refactor: Code cleanup

* Rename

* Refactor: Implement Dto patterns in all queries and commands

* rename: Remove Command/Query from filename as the file contains all relevant stuff of the action

* fix: File structural scoped namespace

* feat: Wallet Page

* feat: Add Transaction

* refactor: merge tiny modules into a single file

* refactor: make folder structure more clear by grouping commands&queries by its function rather than its fields

* feat: remove test queries in test.razor

* refactor: move pages out of WASM project

rebase main

* refactor: move pages out of WASM project

* rename bank into account

* feat: working on wallet.razor

* fix

* refactor: Code Format

* refactor: Code cleanup

* Rename

* Refactor: Implement Dto patterns in all queries and commands

* rename: Remove Command/Query from filename as the file contains all relevant stuff of the action

* fix: File structural scoped namespace

* feat: Wallet Page

* feat: Add Transaction
  • Loading branch information
Shirasagi0012 authored Sep 7, 2024
1 parent 9e8d1e6 commit 3bb27e1
Show file tree
Hide file tree
Showing 173 changed files with 1,822 additions and 1,654 deletions.
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ FodyWeavers.xsd
/src/BerryJuice/appsettings.Development.json
/src/BerryJuice/appsettings.Production.json

/src/Backend/Accounts.Infrastructure/Persistence/Migrations
/src/Backend/Asset.Infrastructure/Persistence/Migrations
/src/Backend/Budget.Infrastructure/Persistence/Migrations
/src/Backend/BerryJuice.Infrastructure/Persistence/Migrations
src/Backend/BerryJuice.Infrastructure/Persistence/Migrations/*
src/Backend/Accounts.Infrastructure/Persistence/Migrations/*
src/Backend/Budget.Infrastructure/Persistence/Migrations/*
src/Backend/Asset.Infrastructure/Persistence/Migrations/*
3 changes: 0 additions & 3 deletions src/Backend/Accounts.Application/AccountService/AccountDto.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Accounts.Domain.AccountAggregate;
using Accounts.Domain.AccountAggregate.AccountEntity;
using JetBrains.Annotations;
using Microsoft.Extensions.DependencyInjection;
using Primitives;
using Primitives.Command;

namespace Accounts.Application.AccountService.Commands;

public sealed class CreateAccountCommand(
string description
) : ICommandRequest<CreateAccountDto>
{
public AccountDescription Description { get; } = new(description);
}

public record CreateAccountDto(
long Id
);

[UsedImplicitly]
internal sealed class CreateAccountCommandHandler(
IAccountRepository accountRepository,
[FromKeyedServices(key: "accounts")] IUnitOfWork unitOfWork
) : ICommandRequestHandler<CreateAccountCommand, CreateAccountDto>
{
public async Task<CreateAccountDto> Handle(CreateAccountCommand request, CancellationToken cancellationToken)
{
var account = Account.CreateNewAccount(request.Description);
var newId = await accountRepository.AddAccountAsync(account, cancellationToken);

await unitOfWork.CommitChangesAsync(cancellationToken);
return new CreateAccountDto(newId.Value);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Accounts.Domain.AccountAggregate.AccountEntity;

namespace Accounts.Application.AccountService.Commands;

public sealed class DeleteAccountCommand(
long id
)
{
public AccountId Id { get; } = new(id);
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Accounts.Application.AccountService.Models;

public record AccountModel(
long Id,
string Description
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Accounts.Application.AccountService.Models;
using JetBrains.Annotations;
using Primitives.Query;

namespace Accounts.Application.AccountService.Queries;

public sealed class GetAccountsQuery : IQueryRequest<GetAccountsDto> { }

public record GetAccountsDto(
IEnumerable<AccountModel> Accounts
);

public interface IGetAccountsRepository
{
public Task<IEnumerable<AccountModel>> GetAccountsByAdminAsync(CancellationToken cancellationToken = default);
}

[UsedImplicitly]
public sealed class GetAccountsQueryHandler(
IGetAccountsRepository getAccountsRepository
) : IQueryRequestHandler<GetAccountsQuery, GetAccountsDto>
{
public async Task<GetAccountsDto> Handle(GetAccountsQuery request, CancellationToken cancellationToken)
{
return new GetAccountsDto(await getAccountsRepository.GetAccountsByAdminAsync(cancellationToken));
}
}
33 changes: 21 additions & 12 deletions src/Backend/Accounts.Application/Accounts.Application.csproj
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\Shared\Exceptions\Exceptions.csproj" />
<ProjectReference Include="..\Accounts.Domain\Accounts.Domain.csproj" />
<ProjectReference Include="..\Accounts.IntegrationEvent\Accounts.IntegrationEvent.csproj" />
<ProjectReference Include="..\Asset.IntegrationEvent\Asset.IntegrationEvent.csproj" />
<ProjectReference Include="..\Budget.IntegrationEvent\Budget.IntegrationEvent.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Shared\Exceptions\Exceptions.csproj"/>
<ProjectReference Include="..\Accounts.Domain\Accounts.Domain.csproj"/>
<ProjectReference Include="..\Accounts.IntegrationEvent\Accounts.IntegrationEvent.csproj"/>
<ProjectReference Include="..\Asset.IntegrationEvent\Asset.IntegrationEvent.csproj"/>
<ProjectReference Include="..\Budget.IntegrationEvent\Budget.IntegrationEvent.csproj"/>
</ItemGroup>

<ItemGroup>
<Folder Include="TagService\Commands\"/>
<Folder Include="TagService\Queries\"/>
</ItemGroup>

<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2024.2.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Accounts.Application.TagService.Models;

public record TagModel(
long TagId,
string TagName
);
3 changes: 0 additions & 3 deletions src/Backend/Accounts.Application/TagService/TagDto.cs

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using Accounts.Domain.AccountAggregate;
using Accounts.Domain.AccountAggregate.AccountEntity;
using Accounts.Domain.AccountAggregate.TransactionEntity;
using Accounts.Domain.TagEntity;
using Enums;
using JetBrains.Annotations;
using Microsoft.Extensions.DependencyInjection;
using Primitives;
using Primitives.Command;

namespace Accounts.Application.TransactionService.Commands;

public sealed class AddTransactionCommand(
long id,
CurrencyType currency,
decimal amount,
long[] tags,
string description
) : ICommandRequest<AddTransactionDto>
{
public AccountId AccountId { get; } = new(id);

public TransactionAmount TransactionAmount { get; } = new(currency, amount);

public TagId[] Tags { get; } = Array.ConvertAll(tags, converter: t => new TagId(t));

public TransactionDescription Description { get; } = new(description);
}

public record AddTransactionDto(
long Id
);

[UsedImplicitly]
public sealed class AddTransactionCommandHandler(
IAccountRepository accountRepo,
ITagRepository tagRepo,
[FromKeyedServices(key: "accounts")] IUnitOfWork unitOfWork
) : ICommandRequestHandler<AddTransactionCommand, AddTransactionDto>
{
public async Task<AddTransactionDto> Handle(AddTransactionCommand request, CancellationToken cancellationToken)
{
var account = await accountRepo.GetAccountAsync(request.AccountId, cancellationToken);

List<Tag> tags = [];

foreach (var t in request.Tags)
{
var tag = await tagRepo.GetTagAsync(t, cancellationToken);
tags.Add(tag);
}

var id = account.AddTransaction(request.TransactionAmount, DateTime.UtcNow, request.Description, tags);

await unitOfWork.CommitChangesAsync(cancellationToken);

return new AddTransactionDto(id.Value);
}
}
Loading

0 comments on commit 3bb27e1

Please sign in to comment.