-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from soat-fiap/1-create-endpoint-to-register-c…
…ustomers feat: create endpoint to register customers
- Loading branch information
Showing
14 changed files
with
270 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 1 addition & 32 deletions
33
src/FIAP.TechChallenge.ByteMeBurger.Api/Model/CreateOrderCommandDto.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,7 @@ | ||
using FIAP.TechChallenge.ByteMeBurger.Domain.Entities; | ||
|
||
namespace FIAP.TechChallenge.ByteMeBurger.Api.Model; | ||
|
||
public class CreateOrderCommandDto | ||
{ | ||
public string? CustomerId { get; set; } | ||
public List<OrderItemDto> Items { get; set; } | ||
} | ||
|
||
public class OrderItemDto | ||
{ | ||
public Guid Id { get; set; } | ||
|
||
public Guid OrderId { get; set; } | ||
|
||
public Guid ProductId { get; set; } | ||
|
||
public int Quantity { get; set; } | ||
|
||
public decimal UnitPrice { get; set; } | ||
|
||
public string ProductName { get; set; } | ||
|
||
public OrderItemDto() | ||
{ | ||
} | ||
|
||
public OrderItemDto(OrderItem orderItem) | ||
{ | ||
Id = orderItem.Id; | ||
OrderId = orderItem.OrderId; | ||
ProductId = orderItem.ProductId; | ||
Quantity = orderItem.Quantity; | ||
UnitPrice = orderItem.UnitPrice; | ||
ProductName = orderItem.ProductName; | ||
} | ||
public List<OrderItemDto> Items { get; set; } = new(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/FIAP.TechChallenge.ByteMeBurger.Api/Model/OrderItemDto.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using FIAP.TechChallenge.ByteMeBurger.Domain.Entities; | ||
|
||
namespace FIAP.TechChallenge.ByteMeBurger.Api.Model; | ||
|
||
public class OrderItemDto | ||
{ | ||
public Guid Id { get; set; } | ||
|
||
public Guid OrderId { get; set; } | ||
|
||
public Guid ProductId { get; set; } | ||
|
||
public int Quantity { get; set; } | ||
|
||
public decimal UnitPrice { get; set; } | ||
|
||
public string ProductName { get; set; } | ||
|
||
public OrderItemDto() | ||
{ | ||
} | ||
|
||
public OrderItemDto(OrderItem orderItem) | ||
{ | ||
Id = orderItem.Id; | ||
OrderId = orderItem.OrderId; | ||
ProductId = orderItem.ProductId; | ||
Quantity = orderItem.Quantity; | ||
UnitPrice = orderItem.UnitPrice; | ||
ProductName = orderItem.ProductName; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/FIAP.TechChallenge.ByteMeBurger.Api/ServiceCollectionExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using FIAP.TechChallenge.ByteMeBurger.Application.Services; | ||
using FIAP.TechChallenge.ByteMeBurger.Domain.Entities; | ||
using FIAP.TechChallenge.ByteMeBurger.Domain.Ports.Ingoing; | ||
using FIAP.TechChallenge.ByteMeBurger.Domain.Ports.Outgoing; | ||
using FIAP.TechChallenge.ByteMeBurger.Domain.ValueObjects; | ||
using FIAP.TechChallenge.ByteMeBurger.Infrastructure.Repository; | ||
|
||
namespace FIAP.TechChallenge.ByteMeBurger.Api; | ||
|
||
internal static class ServiceCollectionExtensions | ||
{ | ||
internal static void RegisterServices(this IServiceCollection services) | ||
{ | ||
services.AddScoped<ICustomerService, CustomerService>(); | ||
services.AddScoped<IProductService, ProductService>(); | ||
services.AddScoped<IOrderService, OrderService>(); | ||
services.AddScoped<IOrderRepository, OrderRepositoryDapper>(); | ||
services.AddScoped<ICustomerRepository, CustomerRepositoryDapper>(); | ||
services.AddSingleton<ICustomerRepository>(new InMemoryCustomerRepository(new[] | ||
{ | ||
new Customer("663.781.241-24", "Pietro Thales Anderson Rodrigues", "pietro_thales_rodrigues@silicotex.net") | ||
})); | ||
|
||
services.AddSingleton<IProductRepository>(new InMemoryProductRepository(new[] | ||
{ | ||
new Product("pao com ovo", "pao com ovo", ProductCategory.Meal, 2.5m, []), | ||
new Product("milkshake chocrante", "milkshake tijolo do bob'as", ProductCategory.SweatsNTreats, 2.5m, []), | ||
new Product("h20", "h20", ProductCategory.Beverage, 2.5m, []), | ||
new Product("batata frita", "batata frita", ProductCategory.FriesAndSides, 2.5m, []) | ||
})); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/FIAP.TechChallenge.ByteMeBurger.Api/WebApplicationBuilderExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Data; | ||
using System.Data.Common; | ||
using FIAP.TechChallenge.ByteMeBurger.Api.Configuration; | ||
using Microsoft.Extensions.Options; | ||
using MySql.Data.MySqlClient; | ||
|
||
namespace FIAP.TechChallenge.ByteMeBurger.Api; | ||
|
||
internal static class WebApplicationBuilderExtensions | ||
{ | ||
internal static void ConfigServicesDependencies(this WebApplicationBuilder builder) | ||
{ | ||
builder.Services.AddSingleton<DbConnectionStringBuilder>(provider => | ||
{ | ||
var mySqlOptions = provider.GetService<IOptions<MySqlSettings>>(); | ||
return new MySqlConnectionStringBuilder() | ||
{ | ||
Server = mySqlOptions!.Value.Server, | ||
Database = mySqlOptions.Value.Database, | ||
Port = mySqlOptions.Value.Port, | ||
Password = mySqlOptions.Value.Password, | ||
UserID = mySqlOptions.Value.UserId | ||
}; | ||
}); | ||
builder.Services.AddTransient<IDbConnection>(provider => | ||
{ | ||
DbProviderFactories.RegisterFactory("MySql.Data.MySqlClient", MySqlClientFactory.Instance); | ||
var requiredService = provider.GetRequiredService<DbConnectionStringBuilder>(); | ||
var providerFactory = DbProviderFactories.GetFactory("MySql.Data.MySqlClient"); | ||
var conn = providerFactory.CreateConnection(); | ||
conn.ConnectionString = requiredService.ConnectionString; | ||
return conn; | ||
}); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/FIAP.TechChallenge.ByteMeBurger.Infrastructure/Repository/CustomerRepositoryDapper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System.Data; | ||
using Dapper; | ||
using FIAP.TechChallenge.ByteMeBurger.Domain.Entities; | ||
using FIAP.TechChallenge.ByteMeBurger.Domain.Ports.Outgoing; | ||
|
||
namespace FIAP.TechChallenge.ByteMeBurger.Infrastructure.Repository; | ||
|
||
public class CustomerRepositoryDapper : ICustomerRepository | ||
{ | ||
private readonly IDbConnection _dbConnection; | ||
|
||
public CustomerRepositoryDapper(IDbConnection dbConnection) | ||
{ | ||
_dbConnection = dbConnection; | ||
} | ||
|
||
public async Task<Customer?> FindByCpfAsync(string cpf) | ||
{ | ||
return await _dbConnection.QuerySingleOrDefaultAsync<Customer>("SELECT * FROM Customer WHERE Id=@Id", | ||
new { Id = cpf }); | ||
} | ||
|
||
public async Task<Customer> CreateAsync(Customer customer) | ||
{ | ||
var rowsAffected = await _dbConnection.ExecuteAsync( | ||
"insert into Customer (Id, Name, Email) values (@Id, @Name, @Email);", | ||
customer); | ||
|
||
return customer; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.