plusminuschirag / fanztar-test

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Mobile Component APIs

The idea is to address the problem listed here.

How to run the code.

Code is dockerized, make sure you have docker installed in your system and make sure it is running before proceeding.

  • docker build -t fanztar-test .
  • docker run -d --name fanztar-test-container -p 5002:80 fanztar-test

How to verify if it's running?

  • Open terminal and run the following command : curl -X 'GET' \ 'http://localhost:5002/' \ -H 'accept: application/json'

  • You should get following message in terminal : { "message": "Hello World" }

How this works?

  • Directly you can use swagger docs url
    • Click the POST /orders/ tab.
    • Click on the try it out button just at the middle of right edge.
    • Update the request body:
      • From { "components": [ "string" ] }
      • To Something of your choice or try this one : { "components": ["I","A","D","F","K"] }
      • Click the execute button and scroll down to see the results.
  • You can run any of the following curls to see variation of results.
    • All unique parts.

      • Curl : curl -X 'POST' \ 'http://localhost:5002/orders/' \ -H 'accept: application/json' \ -H 'Content-Type: application/json' \ -d '{ "components": ["I","A","D","F","K"] }'
      • Output : { "order_id": "a6059358-fba4-46ea-9218-896e60d43917", "total": 142.3, "parts": [ "Android OS", "LED Screen", "Wide-Angle Camera", "USB-C Port", "Metallic Body" ] }
    • Unknown part present.

      • Curl : curl -X 'POST' \ 'http://localhost:5002/orders/' \ -H 'accept: application/json' \ -H 'Content-Type: application/json' \ -d '{ "components": ["I","A","D","F","Z"] }'
      • Output : { "detail": "Component-Id : Z not found." }
    • Repeated part present.

      • Curl : curl -X 'POST' \ 'http://localhost:5002/orders/' \ -H 'accept: application/json' \ -H 'Content-Type: application/json' \ -d '{ "components": ["I","A","D","F","B"] }'
      • Output : { "detail": { "reason": "part : Screen(2) has more than 1 asked component, please check and make sure you have only one component for each of the following parts : Port, OS, Body, Camera, Screen" } }

Architectural Overview

Fanztar-Test-Architecture

Ideas & Assumptions behind the choice.

Ideas

  • Following are the sub-modules of the code:

    • middleware : This sub-modules deals acts as intermediate point between the request and raw resources.
    • resources : To store raw-resources of the project.
    • routers : routers to define set of endpoints. routers/order : contains routers regarding the order related items.
      • Similarly different routers can be defined.
    • schemas : contains schemas for request-bodies for the requests.
  • Classes are used in middleware to save on-demand computer, multiple resources might need pre-computation to read resources or process them and then keep them in memory, assuming that the classes have static variable and methods to pre-calculate operations.

  • Functions are constructed in a way to have full control over each step, assuming there might be some more configurable changes in the future for ex : change the total calculating mechanism by adding 10% hike charge to OS parts only. This can be achieved on multiple levels and will still leave scope for other set of changes.

  • Idea is to entertain request only till it makes sense to, meaning in case error is encountered, other succeeding operations are not done, exception is raised without proceeding to any try-except block.

Assumptions

  • Number of parts(screen, os etc) will not grow as fast as the components themselves.
  • Details for component-list provided in the test are added to resources/constants/CODE_2_PRICE-PART.json and assumed to be in this chosen format.
  • Some exception handlings are overlooked in light of tight-knit resources.
    • Json Reading in middleware/components.py can also be improved to handle file-reading.
    • Logging can also be added using LoggingConfig and calling via proper channels.

About


Languages

Language:Python 95.4%Language:Dockerfile 4.6%