Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adicionar Item com preço fixo #17

Closed
roxdavirox opened this issue Jan 24, 2019 · 3 comments
Closed

Adicionar Item com preço fixo #17

roxdavirox opened this issue Jan 24, 2019 · 3 comments

Comments

@roxdavirox
Copy link
Owner

Criar um endpoint que seja relacionado com um preço fixo

Um item pode conter preço fixo, relativo ou sem preço

@roxdavirox
Copy link
Owner Author

roxdavirox commented Jan 24, 2019

  • Endpoint

[POST] api/Items

  • Body

Exemplo para preço fixo:

{
 "Name": "Nome do item",
 "Price": {"Value": "10.00"},
 "Fixed": true 
}

@roxdavirox
Copy link
Owner Author

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

  1. Preço fixo
{
  "name": "string",
  "fixed": true,
  "fixedPrice": {
    "value": 0
   }
}
  1. Preço relativo
{
  "name": "string",
  "fixed": false,
  "relativePrice": {
    "table": [
      {
        "start": 0,
        "end": 0,
        "value": 0
      }
    ]
  }
}

@roxdavirox
Copy link
Owner Author

roxdavirox commented Jan 24, 2019

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());
}

roxdavirox pushed a commit that referenced this issue Jan 24, 2019
…ro do service handler do create item request (#17)
roxdavirox pushed a commit that referenced this issue Jan 24, 2019
roxdavirox pushed a commit that referenced this issue Jan 24, 2019
roxdavirox pushed a commit that referenced this issue Jan 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant