-
Sample API for unity interview process.
-
-
For the below objective.
Build a premium game listing feature that allows users from the Unity app to unlock premium game tiles.I have implemented a basic authentication mechanism, where authentication would mean that a user has a premium subscription and can view premium listings.
To segregate premium listings from normal ones I have added a new flag in json responseisPremiumwhich when set would mean that a listing is premium and only authenticated users can see these.
- Create a user using ceate user API.
-
Add two listing one with `isPremium` flag set to true and another with default `isPremium` value which is false.
-
Make the get request to listings api `api/games` and see the response it will not show listing with `isPremium` true.
-
Authorize using email id and pass of the user we created on above step.
-
Again make the get request to listings api `/api/games` and see the response. Now we will be able to see 2 listings. One with `isPremium` set to true and another with `isPremium` set to false.
- Create a user using ceate user API.
-
Git Commit Reference for integration of [Unity App with Web API](https://github.com/ktandon91/unity_challenge/commit/265ec14ced41b1b7141d064a4ee14484f777ad9c)
-
Swagger Documention of the project can be found on root url or on `http://localhost:8000/docs`
>Note: Make sure project is up and running to view swagger documentation.
-
For the below objective.
-
├───screenshots ├───src │ ├───api │ │ ├───fixtures │ │ ├───repository │ │ ├───routes │ │ ├───schemas │ │ ├───services │ │ ├───oauth2.py │ │ ├───utils.py │ │ ├───config.py │ └───app.py ├───unityapp ├───docker-compose.yml ├───Dockerfile ├───README.md ├───requirements.txt ├───.env -
- Follows layered architecture approach
- Uses Repository design pattern.
- Database design follows simple - MongoDB embeded document design
{ "id": "string" "category": "string", "title": "string", "subtitle": "string", "description": "string", "type": int, "tags": [ "string" ], "author": "string", "replayBundleUrlJson": "string", "isDownloadable": bool, "isStreamable": bool, "isPremium": bool, "version": int, "images": [ { "id": "string" "url": "string", "type": int } ] }
-
- app.py is the entry point of the application
- Request will first go to app.py
- From app.py, request will be forwarded to appropriate route handlers from routes directory
- Route handlers will validate the structure of the request using schema from schemas directory, and then from route handler appropriate service from services directory will be called
- Services will interact with the database and return the data to route handlers
Tried implementing a self documenting code approach where all variables and function names are denoting what they are actually doing.
API documentation can be accessed on /docs endpoint when the project is up and running.
For instructions on how to run the project navigate to Getting Started
Technologies used.
To get a local copy up and running follow these simple steps.
Make sure you have Docker installed on your system.
-
Clone the repo
git clone https://github.com/ktandon91/unity_challenge.git
-
Build and run docker images using below command.
docker-compose up --build
- Run the above command inside of project directory where
Dockerfileanddocker-composefile is residing.
- Run the above command inside of project directory where
-
Access the API on
http://localhost:8000/ -
To load sample data
UITest.json, make a simple get request to/load.http://localhost:8000/load
All the APIs can be tested from swagger on below url.
http://localhost:8000/docs
Below are the request/response structure to test APIs from postman/CURL.
- To get all the listings, make a get request on
Resonse JSON
http://localhost:8000/api/games{ "listings": [ { "category": "string", "title": "string", "subtitle": "string", "description": "string", "type": 0, "tags": [ "string" ], "author": "string", "replayBundleUrlJson": "string", "isDownloadable": false, "isStreamable": false, "isPremium": false, "version": 0, "id": "string", "images": [ { "url": "string", "type": 0, "id": "string" } ] } ] } - To add a game listing, make a post request on
Request JSON
http://localhost:8000/api/gamesResonse{ "category": "sample category", "title": "sample title", "subtitle": "sample subtitle", "description": "sample desc", "type": 0, "tags": [ "tag 1" ], "author": "Dummy", "replayBundleUrlJson": "example.com/dummy.json", "isDownloadable": false, "isStreamable": false, "isPremium": false, "version": 0, "images": [ { "url": "example.com/abc.jpeg", "type": 0 } ] }Status Code: 201 Created - To view a single game listing, make a get request using game_id on.
Resonse JSON
http://localhost:8000/api/games/{game_id}{ "category": "sample category", "title": "sample title", "subtitle": "sample subtitle", "description": "sample desc", "type": 0, "tags": [ "tag 1" ], "author": "Dummy", "replayBundleUrlJson": "example.com/dummy.json", "isDownloadable": false, "isStreamable": false, "isPremium": false, "version": 0, "id": "61e40b59bd01170bc41c32eb", "images": [ { "url": "example.com/abc.jpeg", "type": 0, "id": "61e40b59bd01170bc41c32ea" } ] } - To update a game listing, make a put request using game_id on.
Request JSON
http://localhost:8000/api/games/{game_id}Resonse{ "category": "sample category", "title": "sample title", "subtitle": "sample subtitle", "description": "sample desc", "type": 0, "tags": [ "tag 1" ], "author": "Dummy", "replayBundleUrlJson": "example.com/dummy.json", "isDownloadable": false, "isStreamable": false, "isPremium": false, "version": 0, "id": "61e40b59bd01170bc41c32eb", "images": [ { "url": "example.com/abc.jpeg", "type": 0, "id": "61e40b59bd01170bc41c32ea" } ] }Status Code: 200 OK - To delete a game listing, make a delete request using game_id request on.
Resonse
http://localhost:8000/api/games/{game_id}Status Code: 204 No Content - To create a user, make a post request on.
Request JSON
http://localhost:8000/api/users/{ "email": "user@example.com", "password": "string" } - To obtain a token to access token for premium listings, make a post requst on.
Request
http://localhost:8000/loginResponsecurl -X 'POST' \ 'http://localhost:8000/login' \ -H 'accept: application/json' \ -H 'Content-Type: application/x-www-form-urlencoded' \ -d 'grant_type=&username=user%40example.com&password=string&scope=&client_id=&client_secret='{ "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9. eyJlbWFpbCI6InVzZXJAZXhhbXBsZS5jb20iLCJleHAiOjE2NDIzODE3Njd9.eOVNKAyuQ7nTpe5hROX_Uag9P9MF32xAiCPZr9_kfCA", "token_type": "bearer" }