Code Monkey home page Code Monkey logo

Comments (3)

roxdavirox avatar roxdavirox commented on June 15, 2024 1

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.

roxdavirox avatar roxdavirox commented on June 15, 2024
  • Endpoint

[POST] api/Items

  • Body

Exemplo para preço fixo:

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

from marketplace.

roxdavirox avatar roxdavirox commented on June 15, 2024

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
      }
    ]
  }
}

from marketplace.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.