Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.AspNetCore.Mvc;
using System.Diagnostics.CodeAnalysis;
using UserTransactions.Application.UseCases.User.Create;
using UserTransactions.Application.UseCases.User.ListAll;
using UserTransactions.Application.UseCases.User.ListTotal;
using UserTransactions.Communication.Dtos.Errors.Response;
using UserTransactions.Communication.Dtos.User.Request;
Expand All @@ -23,10 +24,18 @@ public class UserController : ControllerBase
public async Task<IActionResult> RegisterUser([FromBody] RequestCreateUserDto request, [FromServices] ICreateUserUseCase useCase)
{
var result = await useCase.ExecuteAsync(request);

return CreatedAtAction(nameof(RegisterUser), new { id = result.Id }, result);
}

[HttpGet("list-all")]
[ProducesResponseType(typeof(ResponseListAllUsersDto), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ResponseErrorDto), StatusCodes.Status400BadRequest)]
public async Task<IActionResult> ListAllUsers([FromServices] IListAllUsersUseCase useCase)
{
var result = await useCase.ExecuteAsync();
return Ok(result);
}

[HttpGet("list-total-quantity")]
[ProducesResponseType(typeof(ResponseListTotalQuantityUserDto), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ResponseErrorDto), StatusCodes.Status400BadRequest)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
using Microsoft.AspNetCore.Mvc;
using System.Diagnostics.CodeAnalysis;
using UserTransactions.Application.UseCases.Wallet.Create;
using UserTransactions.Application.UseCases.Wallet.ListAll;
using UserTransactions.Application.UseCases.Wallet.ListTotal;
using UserTransactions.Communication.Dtos.Errors.Response;
using UserTransactions.Communication.Dtos.User.Response;
using UserTransactions.Communication.Dtos.Wallet.Request;
using UserTransactions.Communication.Dtos.Wallet.Response;

Expand All @@ -28,6 +28,15 @@ public async Task<IActionResult> RegisterWallet([FromBody] RequestCreateWalletDt
return CreatedAtAction(nameof(RegisterWallet), new { id = result.Id }, result);
}

[HttpGet("list-all")]
[ProducesResponseType(typeof(ResponseListAllWalletsDto), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ResponseErrorDto), StatusCodes.Status400BadRequest)]
public async Task<IActionResult> ListAllWallets([FromServices] IListAllWalletsUseCase useCase)
{
var result = await useCase.ExecuteAsync();
return Ok(result);
}

[HttpGet("list-total-quantity")]
[ProducesResponseType(typeof(ResponseListTotalQuantityWalletDto), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ResponseErrorDto), StatusCodes.Status400BadRequest)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
using UserTransactions.Application.UseCases.Transaction.ListTotal;
using UserTransactions.Application.UseCases.Transaction.ListTotalAmount;
using UserTransactions.Application.UseCases.User.Create;
using UserTransactions.Application.UseCases.User.ListAll;
using UserTransactions.Application.UseCases.User.ListTotal;
using UserTransactions.Application.UseCases.Wallet.Create;
using UserTransactions.Application.UseCases.Wallet.ListAll;
using UserTransactions.Application.UseCases.Wallet.ListTotal;
using UserTransactions.Communication.Dtos.Errors.Response;

Expand Down Expand Up @@ -41,9 +43,11 @@ public static void AddUseCases(this IServiceCollection services)


services.AddScoped<IListTotalQuantityUserUseCase, ListTotalQuantityUserUseCase>();
services.AddScoped<IListAllUsersUseCase, ListAllUsersUseCase>();


services.AddScoped<IListTotalQuantityWalletUseCase, ListTotalQuantityWalletUseCase>();
services.AddScoped<IListAllWalletsUseCase, ListAllWalletsUseCase>();

services.AddScoped<IGetOverallHealthUseCase, GetOverallHealthUseCase>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,16 @@ public static ResponseCreateUserDto MapFromUser(this UserEntity user)
Email = user.Email,
};
}

public static IList<ResponseListAllUsersDto> MapListAllFromUser(this IList<UserEntity> users)
{
return users.Select(user => new ResponseListAllUsersDto
{
FullName = user.FullName,
Email = user.Email,
CPF = user.CPF,
UserType = user.UserType
}).ToList();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,16 @@ public static ResponseCreateWalletDto MapFromWallet(this WalletEntity wallet)
Balance = wallet.Balance
};
}

public static IList<ResponseListAllWalletsDto> MapListAllFromWallet(this IList<WalletEntity> wallets)
{
return wallets.Select(wallet => new ResponseListAllWalletsDto
{
FullName = wallet.User!.FullName,
Email = wallet.User!.Email,
UserType = wallet.User.UserType,
Balance = wallet.Balance
}).ToList();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public async Task<IList<ResponseListTransactionsDto>> ExecuteAsync()
{
var transactions = await _transactionRepository.ListAllAsync();

var ResponseListTransactionsDto = transactions.MapListAllFromTransactions();
var responseListTransactionsDto = transactions.MapListAllFromTransactions();

return ResponseListTransactionsDto;
return responseListTransactionsDto;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using UserTransactions.Communication.Dtos.User.Response;

namespace UserTransactions.Application.UseCases.User.ListAll
{
public interface IListAllUsersUseCase
{
Task<IList<ResponseListAllUsersDto>> ExecuteAsync();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using UserTransactions.Application.Mappers.User;
using UserTransactions.Communication.Dtos.User.Response;
using UserTransactions.Domain.Repositories.User;

namespace UserTransactions.Application.UseCases.User.ListAll
{
public class ListAllUsersUseCase : IListAllUsersUseCase
{
private readonly IUserRepository _userRepository;

public ListAllUsersUseCase(IUserRepository userRepository)
{
_userRepository = userRepository;
}

public async Task<IList<ResponseListAllUsersDto>> ExecuteAsync()
{
var users = await _userRepository.ListAllAsync();

var responseListAllUsersDto = users.MapListAllFromUser();

return responseListAllUsersDto;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using UserTransactions.Communication.Dtos.Wallet.Response;

namespace UserTransactions.Application.UseCases.Wallet.ListAll
{
public interface IListAllWalletsUseCase
{
Task<IList<ResponseListAllWalletsDto>> ExecuteAsync();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using UserTransactions.Application.Mappers.Wallet;
using UserTransactions.Communication.Dtos.Wallet.Response;
using UserTransactions.Domain.Repositories.Wallet;

namespace UserTransactions.Application.UseCases.Wallet.ListAll
{
public class ListAllWalletsUseCase : IListAllWalletsUseCase
{
private readonly IWalletRepository _walletRepository;

public ListAllWalletsUseCase(IWalletRepository walletRepository)
{
_walletRepository = walletRepository;
}

public async Task<IList<ResponseListAllWalletsDto>> ExecuteAsync()
{
var wallets = await _walletRepository.ListAllAsync();

var responseListAllWalletsDto = wallets.MapListAllFromWallet();

return responseListAllWalletsDto;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using UserTransactions.Communication.Dtos.User.Response;
using UserTransactions.Communication.Dtos.Wallet.Response;

namespace UserTransactions.Application.UseCases.Wallet.ListTotal
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using UserTransactions.Communication.Dtos.User.Response;
using UserTransactions.Communication.Dtos.Wallet.Response;
using UserTransactions.Domain.Repositories.Wallet;

namespace UserTransactions.Application.UseCases.Wallet.ListTotal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ public interface IUserRepository
Task<bool> IsCpfAlreadyRegistered(string cpf);
Task<bool> ExistsAndIsActiveAsync(Guid userId);
Task<int> ListTotalQuantityAsync();
Task<IList<UserEntity>> ListAllAsync();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ public interface IWalletRepository
Task<WalletEntity?> GetByIdAsync(Guid id);
Task UpdateAsync(WalletEntity wallet);
Task<int> ListTotalQuantityAsync();
Task<IList<WalletEntity>> ListAllAsync();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,9 @@ public async Task<IList<Transaction>> ListAllAsync()
.ToListAsync();
}

public async Task<int> ListTotalAsync()
{
return await _dbContext.Transactions.CountAsync();
}
public async Task<int> ListTotalAsync() => await _dbContext.Transactions.CountAsync();

public async Task<decimal> ListTotalAmountAsync()
{
return await _dbContext.Transactions.SumAsync(t => t.Amount);
}
public async Task<decimal> ListTotalAmountAsync() => await _dbContext.Transactions.SumAsync(t => t.Amount);

public async Task<IList<Transaction>> ListLatestFourAsync()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace UserTransactions.Infrastructure.Persistance.Repositories
{
//Todo: Implementar testes unitários, fazendo in memory database para o DbContext e mockando o repositório.

Check warning on line 8 in src/Backend/UserTransactions.Infrastructure/Persistance/Repositories/UserRepository.cs

View workflow job for this annotation

GitHub Actions / build-test-analyze

Complete the task associated to this 'TODO' comment. (https://rules.sonarsource.com/csharp/RSPEC-1135)
[ExcludeFromCodeCoverage]
public class UserRepository : IUserRepository
{
Expand All @@ -22,24 +22,14 @@
await _dbContext.SaveChangesAsync();
}

public async Task<bool> IsCpfAlreadyRegistered(string cpf)
{
return await _dbContext.Users.AnyAsync(u => u.CPF == cpf);
}
public async Task<bool> IsCpfAlreadyRegistered(string cpf) => await _dbContext.Users.AnyAsync(u => u.CPF == cpf);

public async Task<bool> IsEmailAlreadyRegistered(string email)
{
return await _dbContext.Users.AnyAsync(u => u.Email == email);
}
public async Task<bool> IsEmailAlreadyRegistered(string email) => await _dbContext.Users.AnyAsync(u => u.Email == email);

public async Task<bool> ExistsAndIsActiveAsync(Guid userId)
{
return await _dbContext.Users.AnyAsync(u => u.Id == userId && u.IsActive);
}
public async Task<bool> ExistsAndIsActiveAsync(Guid userId) => await _dbContext.Users.AnyAsync(u => u.Id == userId && u.IsActive);

public async Task<int> ListTotalQuantityAsync()
{
return await _dbContext.Users.CountAsync();
}
public async Task<int> ListTotalQuantityAsync() => await _dbContext.Users.CountAsync();

public async Task<IList<User>> ListAllAsync() => await _dbContext.Users.ToListAsync();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace UserTransactions.Infrastructure.Persistance.Repositories
{
//Todo: Implementar testes unitários, fazendo in memory database para o DbContext e mockando o repositório.

Check warning on line 8 in src/Backend/UserTransactions.Infrastructure/Persistance/Repositories/WalletRepository.cs

View workflow job for this annotation

GitHub Actions / build-test-analyze

Complete the task associated to this 'TODO' comment. (https://rules.sonarsource.com/csharp/RSPEC-1135)
[ExcludeFromCodeCoverage]
public class WalletRepository : IWalletRepository
{
Expand All @@ -22,17 +22,9 @@
await _dbContext.SaveChangesAsync();
}

public async Task<bool> ExistsByUserIdAsync(Guid userId)
{
return await _dbContext.Wallets
.AnyAsync(w => w.UserId == userId && w.IsActive);
}
public async Task<bool> ExistsByUserIdAsync(Guid userId) => await _dbContext.Wallets.AnyAsync(w => w.UserId == userId && w.IsActive);

public async Task<bool> ExistsByIdAsync(Guid id)
{
return await _dbContext.Wallets
.AnyAsync(w => w.Id == id && w.IsActive);
}
public async Task<bool> ExistsByIdAsync(Guid id) => await _dbContext.Wallets.AnyAsync(w => w.Id == id && w.IsActive);

public async Task<Wallet?> GetByIdAsync(Guid id)
{
Expand All @@ -48,9 +40,8 @@
await _dbContext.SaveChangesAsync();
}

public async Task<int> ListTotalQuantityAsync()
{
return await _dbContext.Wallets.CountAsync();
}
public async Task<int> ListTotalQuantityAsync() => await _dbContext.Wallets.CountAsync();

public async Task<IList<Wallet>> ListAllAsync() => await _dbContext.Wallets.Include(w => w.User).ToListAsync();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using UserTransactions.Domain.Enum;

namespace UserTransactions.Communication.Dtos.User.Response
{
public class ResponseListAllUsersDto
{
public string FullName { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;
public string CPF { get; set; } = string.Empty;
public UserType UserType { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using UserTransactions.Domain.Enum;

namespace UserTransactions.Communication.Dtos.Wallet.Response
{
public class ResponseListAllWalletsDto
{
public string FullName { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;
public decimal Balance { get; set; }
public UserType UserType { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace UserTransactions.Communication.Dtos.User.Response
namespace UserTransactions.Communication.Dtos.Wallet.Response
{
public class ResponseListTotalQuantityWalletDto
{
Expand Down
Loading
Loading