Coder Social home page Coder Social logo

teste_vaga_rails's Introduction

Projeto ProductManager

O objetivo deste mini projeto é fornecer uma api restfull para gerenciar o catálogo de produtos de um ecommerce.

O que já está pronto:

A api de produtos conforme a documentação abaixo

Tarefas:

  1. Adicionar paginação a api de produtos com o valor padrão de 20 itens por página, podendo ser alterado via parâmetros até o máximo de 100

  2. Permitir ordenar por qualquer uma das colunas de forma crescente ou decrescente

  3. Permitir filtrar por qualquer uma das colunas, podendo usar todas as comparações possíveis (contém, igual, diferente, maior, maior ou igual, menor...)

  4. Criar api de produtos relacionados, em uma relação de n..n, onde um produto pode ter um ou mais produtos relacionados, sendo necessário validar que um produto não pode ser linkado a ele próprio. a api permitirá adicionar e remover uma relações de produtos

    POST /products/:product_id/related_products

    // request body
    {
      "related_product_id": 22
    }
    // response body, status: 201
    {
      "id": 22,
      "name": "Product test",
      "price": "10.99"
    }
    // response body, status: 404|422
    {
      "errors": ["Mensagem de erro"]
    }

    DELETE /products/:product_id/related_products/:related_product_id

    // response body, status: 204
    null
    // response body, status: 404
    {
      "errors": ["Mensagem de erro"]
    }
  5. Adicionar produtos relacionados ao json do produto apenas no endpoint de detalhes do produto, ficando no formato abaixo:

     // response body, status: 200
     {
       "id": 1,
       "name": "Product test",
       "description": "Description of product test",
       "price": "10.99",
       "quantity": 50,
       "created_at": "2021-07-05T23:13:17.383Z",
       "created_at": "2021-07-05T23:13:17.383Z",
       "related_prooducts": [
         {
           "id": 22,
           "name": "Product test",
           "price": "10.99"
         }
       ]
     }
    
  6. Atualizar a documentação com as alterações nos endpoints existentes e os novos

OBS:

  • Nas tarefas 2 e 3 pode ser usado uma gem para facilitar o trabalho
  • Já existem specs para o código atual, o candidato deverá adaptalas as mudanças solicitadas e adicionar novas quando necessário.

Rodando o projeto:

Requisitos:

  • Ruby 3.0.1
  • Rails 6.1.4
  • Postgresql

Comandos:

git clone https://github.com/WallasFaria/teste_vaga_rails.git
cd teste_vaga_rails
bundle install
rails db:create db:migrate db:seed && RAILS_ENV=test rails db:migrate

Rodando os testes:

rspec -f doc

OBS: Após finalizado o teste, o candidato deverá subir o projeto em seu github e nos enviar o link

API Documentation

List Products

GET /products
// response body, status: 200
[
  {
    "id": 1,
    "name": "Product test",
    "description": "Description of product test",
    "price": "10.99",
    "quantity": 50,
    "created_at": "2021-07-05T23:13:17.383Z",
    "created_at": "2021-07-05T23:13:17.383Z"
  }
]

Get Product details

GET /products/:id
// response body, status: 200
{
  "id": 1,
  "name": "Product test",
  "description": "Description of product test",
  "price": "10.99",
  "quantity": 50,
  "created_at": "2021-07-05T23:13:17.383Z",
  "created_at": "2021-07-05T23:13:17.383Z"
}
// response body, status: 404
{
  "errors": ["Couldn't find Product with 'id'=22"]
}

Create a Product

POST /products
// request body
{
  "name": "Product test",
  "description": "Description of product test",
  "price": "10.99",
  "quantity": 50,
}
// response body, status: 201
{
  "id": 1,
  "name": "Product test",
  "description": "Description of product test",
  "price": "10.99",
  "quantity": 50,
  "created_at": "2021-07-05T23:13:17.383Z",
  "created_at": "2021-07-05T23:13:17.383Z"
}
// response body, status: 422
{
  "errors": ["Name has already been taken"]
}

Update a Product

PUT/PATCH /products
// request body
{
  "description": "NEW Description of product test",
}
// response body, status: 201
{
  "id": 1,
  "name": "Product test",
  "description": "NEW Description of product test",
  "price": "10.99",
  "quantity": 50,
  "created_at": "2021-07-05T23:13:17.383Z",
  "created_at": "2021-07-05T23:13:17.383Z"
}
// response body, status: 422
{
  "errors": ["Description can't be blank"]
}

Delete a Product

DELETE /products/:id
// response body, status: 204
null
// response body, status: 404
{
  "errors": ["Couldn't find Product with 'id'=22"]
}

teste_vaga_rails's People

Contributors

wallasfaria avatar

Watchers

 avatar James Cloos avatar

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.