Git Product home page Git Product logo

amazing-co's Introduction

Prompt:

We in Amazing Co need to model how our company is structured so we can do awesome stuff.

We have a root node (only one) and several children nodes,each one with its own children as well. It's a tree-based structure.

Something like:

     root

    /    \

   a      b

   |

   c

We need two HTTP APIs that will serve the two basic operations:

  1. Get all descendant nodes of a given node (the given node can be anyone in the tree structure).

Example request: GET http://127.0.0.1:5000/nodes/a

  1. Change the parent node of a given node (the given node can be anyone in the tree structure).

Example request: PUT http://127.0.0.1:5000/nodes/c?new_parent=b

They need to answer quickly, even with tons of nodes. Also,we can't afford to lose this information, so some sort of persistence is required.

Each node should have the following info:

  1. node identification

  2. who is the parent node

  3. who is the root node

  4. the height of the node. In the above example,height(root) = 0 and height(a) == 1.

We can only have docker and docker-compose on our machines, so your server needs to be run, using them.

Overall Design:

SQL Lite database table node for persistence data store. More information are located in app/setup.py

API endpoints are located in app/api.py

Running the app with Docker

Build the docker image: docker build -t docker-flask:latest .

Run the app: docker run --name flaskapp -dt -v$PWD/app:/app -p5000:5000 docker-flask:latest

Example API calls:

vannguyen@MacBook-Pro ~ % curl --location --request GET 'http://0.0.0.0:5000/nodes/b'
{
  "code": 200, 
  "response": "Descendant node(s) of b: c ", 
  "success": "true"
}
vannguyen@MacBook-Pro ~ % curl --location --request GET 'http://0.0.0.0:5000/nodes/a'
{
  "code": 200, 
  "response": "Node a does not have any descendant node.", 
  "success": "true"
}
vannguyen@MacBook-Pro ~ % curl --location --request PUT 'http://127.0.0.1:5000/nodes/c?new_parent=b'
{
  "code": 200, 
  "response": "Updated node c to new parent node b", 
  "success": "true"
}

amazing-co's People

Watchers

 avatar  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.