Code Monkey home page Code Monkey logo

labcodes_challenge's Introduction

Dev Setup

Backend

The project needs a .env file with all the environment variables expected by the project. To do so you can copy the env.example file and edit your own .env.

We're using docker compose to manage all the required infra (Postgres and Redis) for the application to run. To create all the images and run them as a daemon, you have to have docker-compose installed and run:

$ docker-compose up -d

We highly recommend you to create a Python virtual environment to the project. You may create it whatever way you want, but at Labcodes, we mostly use virtualenvwrapper to manage virtual environments. Assuming you already have virtualenvwrapper installed, the commands to run the projects are:

$ mkvirtualenv labcodes_challenge -p /usr/bin/python3
$ pip install -r dev-requirements.txt
$ cd project
$ python manage.py test
$ python manage.py migrate
$ python manage.py runserver

We've already prepared a valid DB with pre-populated products. If you want to load it, just run:

$ python manage.py loaddata categories products

If you want to create your own products, you can do so via http://localhost:8000/admin but you have to create a super user to access it.

Frontend

Before running anything, be sure to have node and npm installed. On Ubuntu 18.04, you may follow this guide.

After that, run make node_setup or use n to set up the current node and npm lts versions. The make node_setup command will install nvm, so you may need to reset your terminal

Making sure you're using node's LTS version, install all the dependencies:

npm i

Then, you'll need to run it together with the backend. We created a make command to deal with running both in parallel:

make dev or make rundev (this second running the virtualenvwrapper directly)

Our basic react app lies inside the project/assets/src/ folder.

Before deploying, make sure you have created a proper build by running:

make build_frontend

Tests

To run all tests:

make alltest

To run api/backend tests:

make apitest

To run app/frontend tests:

make apptest

API Docs

The current API has only 3 valid endpoints and none of they requires a logged user.

/api/inventory/

The endpoint is only accessible via GET and it lists the products in the inventory. A valid 200 response will have the following JSON body:

[
  {
    "name": "Pencil",
    "description": "Graffiti Pencil",
    "code": "P-0142",
    "available_quantity": 150,
    "category": "Pens and Pencils"
  },
  {
    "name": "Pen 0.4",
    "description": "0.40mm Ink Pen",
    "code": "P-0156",
    "available_quantity": 40,
    "category":"Pens and Pencils"
  }
]

/api/inventory/category

The endpoint is only accessible via GET and it lists the categories in the inventory. A valid 200 response will have the following JSON body:

[
  {
    "name": "Pens and Pencils",
    "code": 2
  },
  {
    "name": "Reams",
    "code": 3
  }
]

/api/inventory/<code>/

The endpoint is only accessible via GET and it returns the detail of the product in the inventory with the corresponding code. A valid 200 response for the url /api/inventory/P-0142/ will have the following JSON as its body:

{
  "name": "Pencil",
  "description": "Graffiti Pencil",
  "code": "P-0142",
  "available_quantity": 150,
  "category": "Pens and Pencils"
}

If the code doesn't exist in the database, the endpoint will return a 404 response.

/api/inventory/<code>/update-quantity/

The endpoint is only accessible via POST and it adds or withdrawl a specific amount from the product available quantity. The valid 200 response depends on a valid request body, {"quantity": -50} for example, and it will have the following JSON as its body:

{
  "available_quantity": 100,  # this is the updated value for the product available quantity
}

If the code doesn't exist in the database, the endpoint will return a 404 response.

If the request is using an invalid JSON as data, {} for example, the endpoint will return a 400 response with the following JSON as its body:

{
  "quantity": ["This field is required."]
}

labcodes_challenge's People

Contributors

osmanrodrigues avatar

Stargazers

Roman avatar  avatar

Watchers

James Cloos avatar  avatar

labcodes_challenge's Issues

Add Category field to Product model

Relationship:

  • Product -> Category (one-to-one);
  • Category => Product (one-to-many);

Setup:

  • Category: Printer Cartridges

  • Products: P-1000, P-1005;

  • Category: Pens and Pencils

  • Products: P-0142, P-0156, P-0157;

  • Category: Reams

  • Products: P-0010, P-0110;

  • Category: Erasers

  • Products: P-0005.

Develop site layout - part 3

Product page

  • Fixed header
  • Hero and return section
  • Product details section
  • Product analytics section

==========
Sub-task of #4

Develop site layout - part 1

Atomic

  • Typhography

  • H1, H2, H3, p, p, dl, dd, dt

  • Button

  • Idle, Hover, Focused

  • Icon Button

  • Idle, Hover, Focused

  • Card

  • Idle, Hover, Focused

  • Card Mobile

  • Idle, Focused

  • Layout

  • Separator

==========
Sub-task of #4

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.