adnanioricce / dhsys Goto Github PK
View Code? Open in Web Editor NEWA .net core Inventory Web API playground to try some things
License: MIT License
A .net core Inventory Web API playground to try some things
License: MIT License
it's common to have to manage the amount that gets in and out of this kind of business, to know how much you spend and earn, how much change is still remaining and probably will need, and so on. Because of this, would be useful to add a transaction entity, that keeps track of this kind of data flowing in the business.
it would be needed to keep track of the amount of cash available, and validate operations that impact it, a payment may be cancelled, if there is no change to return to the user, or no change at all, in the case of accept payment later.
Maybe, a way to keep track of the notes is also important, but this problem would be a different problem from a transaction entity, despite related.
The payments operations are planned to be handled by the following constructs:
Payment
,PaymentMethod
(payment method info and behavior),PaymentMethods
(enum with the allowed payment methods)IPaymentMethodService
and IPaymentProcessor
the names don't seem obvious so I will explain
Payment
represent the Intent of a customer to pay for something, with a certain amount on a certain methodPaymentMethod
represent the The process and rules that are performed to handle a paymentPaymentMethods
(need better name) represent the set of payment methods allowedIPaymentMethodService
represent the set of operations that connect the domain context and the external concernsIPaymentProcessor
represent the the translation of a set of operations of a payment provider to the domain context, a abstraction of the API of a payment provider(eg: PayPal, Stripe...)the first thing to notice is that the IPaymentMethodService
have a purpose of mediator in the system, but this don't seem to be necessary, this is the code of the InHandsPaymentService
to issue payments
protected readonly IPaymentProcessor _processor;
public async Task<PaymentResult> IssuePaymentAsync(Payment payment)
{
var result = await _processor.ProcessAsync(new PaymentRequest(payment));
_paymentRepository.Add(payment);
await _paymentRepository.SaveChangesAsync();
return result;
}
and the method ProcessAsync
of InHandsProcessor
public Task<PaymentResult> ProcessAsync(IPaymentRequest request)
{
return request.SendAsync();
}
the PaymentRequest
object has a class that implements the interface IPaymentRequest
, in this implementation, it receives a payment and has a method ```SendAsync``, that evaluates if it should be considered, paid, partially paid and so on.
public async Task<PaymentResult> SendAsync()
{
await Task.Delay(0);//yes, this shouldn't happen
return PaymentResult.Create(Payment);
}
there is also a coupling with other parts that I think that actually aren't necessary, and will probably be a source of issues. This is a entity on the system, so it's persisted on database, so it will need more work to handle conversion from domain to DB and vice versa
public class CreditCard : PaymentMethod
{
protected readonly IPaymentProcessor _paymentProcessor;
protected CreditCard()
{
}
public CreditCard(IPaymentProcessor paymentProcessor)
{
_paymentProcessor = paymentProcessor;
Name = "CreditCard";
}
}
The solution that I think till now, is to remove the need for the IPaymentMethodService
, and handle the abstraction and mediation between the payment provider and domain context with the IPaymentRequest
and IPaymentProcessor
only, using the IPaymentRequest
to represent the operations of the payment provider and wire things with IPaymentProcessor
and PaymentMethod
. Make all this decoupled should be kept in mind
For now the Core library don't provide any restriction or guideline on how to use it or interact with the domain model
instead of using the entities this way:
var product = new Product {
Name = "Generic Cosmetic Product",
ProductPrices = new List<ProductPrice>{
new ProductPrice {
EndCustomerValue = 12.99m,
CostPrice = 10.99m
}
},
ProductCategory = new List<ProductCategory>{
new ProductCategory{
Category = new Category {
Name = "Cosmetics",
Description = "Cosmetic Products"
}
}
}
}
would be better use them in a more specific way like this:
var product = new Product();
product.AddToCategory(Category.Create("Cosmetics","Cosmetic Products"));
product.SetNewPrice(endCustomerValue:12.99m,costPrice:10.99m);
//restrict unexpected use from api caller
product.ProductPrices[0].EndCustomerValue = 0.0m; //compile error
if I combine this with some unit tests I can provide some usable API for anyone who come back here(probably me after some months).
Currently there is no data to make simple demonstrations on the application.
For now, thinking in add a procedure to seed the application with some data for demo with the Migrator console App(at the momento, just on the development branch).
This will probably take some time
There is currently a Payment entity type that can be created with Payment method, that process the operations related with the payment entity, so that different payment methods, could have different ways to handle payments, and so, each external service that needed to be integrated in the system would be handled in a way that it don't needed to be too much coupled in the solution.
Besides that, the solution seem to be over engineered, but this I want to address in another issue( #16 ).
The project get bigger and bigger and still there is no way to use it.
Need to define some basic goals and have at least one feature working.
Recently, I decided to limit all the Remote and Local syncronization to a different Web Api (Api.Windows), so now I am only using the LocalContext, but the migrations methods that I define will try to find the Migrations of the wrong context.
I think this will be the most painful part of the project, wpf is not very friendly with CI and CD processes. CI/CD will be necessary if I want that the software updates don't break everything and that I can deliver something without too much pain.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.