Comments (3)
A lógica do negocio está dentro do handler (CreateItemHandler) encapsulada de forma privada.
Atualmente existem apenas duas regras para o preço do item, são elas:
-
Preço fixo
-
Preço relativo
-
solução:
Arquivo: Marketplace.App.Services.Handlers.Items.CreateItemHandler.cs
usando extension methods para facilitar a leitura e inverter a dependencia
internal static class CreateItemRequestExtension
{
public static Price GetPrice(this CreateItemRequest request) =>
request.Fixed
? CreateFixedPrice(request)
: CreateRelativePrice(request);
private static Price CreateFixedPrice(CreateItemRequest request) =>
new Price(request.Fixed, request.FixedPrice.Value);
private static IEnumerable<PriceInterval> GetPriceIntervals(this CreateItemRequest request) =>
request.RelativePrice.Table
.Select(i => new PriceInterval(i.Start, i.End, i.Value));
private static RelativePrice GetRelativePrice(this CreateItemRequest request) =>
new RelativePrice(request.GetPriceIntervals());
private static Price CreateRelativePrice(CreateItemRequest request) =>
new Price(request.GetRelativePrice());
}
from marketplace.
- Endpoint
[POST] api/Items
- Body
Exemplo para preço fixo:
{
"Name": "Nome do item",
"Price": {"Value": "10.00"},
"Fixed": true
}
from marketplace.
Designs do endpoint para criar um item com preço relativo e fixo.
- Body completo
Omitir as propriedades desnecessárias pra cada tipo de preço
[POST] api/Items
{
"name": "string",
"fixed": true,
"fixedPrice": {
"value": 0
},
"relativePrice": {
"table": [
{
"start": 0,
"end": 0,
"value": 0
}
]
}
}
- Postando apenas o necessario e emitindo o restante
[POST] api/Items/fixed-price
{
"name": "string",
"fixed": true,
"fixedPrice": {
"value": 0
}
}
[POST] api/Items/relative-price
{
"name": "string",
"fixed": false,
"relativePrice": {
"table": [
{
"start": 0,
"end": 0,
"value": 0
}
]
}
}
[POST] api/Items
- Preço fixo
{
"name": "string",
"fixed": true,
"fixedPrice": {
"value": 0
}
}
- Preço relativo
{
"name": "string",
"fixed": false,
"relativePrice": {
"table": [
{
"start": 0,
"end": 0,
"value": 0
}
]
}
}
from marketplace.
Related Issues (19)
- Implementar entidade item
- Relacionar Option com Item no EF HOT 1
- Criar Opção e associar com item existente
- Criar todos os preços como relativos
- ItemPrice: PriceRange
- IEnumerable Extension Method LINQ HOT 1
- String de conexão por ambientes
- CORS: Habilitar Headers
- Autenticação JWT HOT 2
- Jwt Identity model reference HOT 2
- Remover claims desnecessarias
- Criar politica de autorização HOT 1
- Refatorar metodos de entidades
- Refatorar CreateFullProductHandler HOT 1
- Refatorar funções pra inline
- Inverter nome dos commands ProductOption
- Associar Option com Items
- Associar Item com opção via put verb HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from marketplace.