diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index ddce3f9..b0bdde6 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -17,6 +17,7 @@ Coderplex web application comprises of two repositories : - [Prerequisites](#prerequisites) - [Sending a Pull Request](#sending-a-pull-request) - [Running Locally](#running-locally) + - [Notes](#notes) - [Docker Deployment in production](#docker-deployment-in-production) - [Before submitting](#before-submitting) - [Submitting PullRequest](#submitting-pullrequest) @@ -46,7 +47,7 @@ We welcome pull requests from beginners and django developers alike! ### Work on Issues -1. Find an issue that needs assistance by searching for the [open issues](https://github.com/coderplex/coderplex-backend/labels/help wanted). +1. Find an issue that needs assistance by searching for the [open issues](https://github.com/coderplex/coderplex-backend/labels/help-wanted). 1. If you decide to fix an issue, please be sure to check the comment thread in case somebody is already working on a fix. If nobody is working on it at the moment, please leave a comment stating that you intend to work on it so other people don’t accidentally duplicate your effort. 1. If somebody claims an issue but doesn’t follow up for more than a weeks, it’s fine to take over it but you should still leave a comment. @@ -130,8 +131,14 @@ We welcome pull requests from beginners and django developers alike! python webapp/manage.py runserver ``` You can now open the App at `localhost:8000` in your browser -1. You can see all the implemented APIs in [API.md](../API.md) - + +##### Notes +1. You can see all the implemented APIs in the route `/api-docs`. Any new api that you will create will be automatically appear in `/api-docs` route. +1. To get `code` that will be used to in the `GitHub Login API`, run this [url](https://github.com/login/oauth/authorize?scope=user:email&client_id=97d600c693730ed91ac0) + in the browser and authorize, then the `code` will be appended as a url param to the redirected_url +1. To get `code` that will be used to in the `LinkedIn Login API`, run this [url](https://www.linkedin.com/oauth/v2/authorization?client_id=81ptws4wm9kflx&response_type=code&redirect_uri=http://127.0.0.1:8000/callback) + in the browser and authorize, then the `code` will be appended as a url param to the redirected_url + #### For Production (Contributors can ignore this) 1. Change `client_id` and `client_secret` of social applications 1. Add environment variables `GITHUB_CALLBACK_URL` and `LINKEDIN_CALLBACK_URL` and set those with ` + "/callback"` @@ -165,9 +172,7 @@ We welcome pull requests from beginners and django developers alike! ```bash python webapp/manage.py test ``` -1. If any documentation is needed, add docs -1. If any exisitng APIs are modified, make those changes in [API.md](../API.md) -1. If any new APIs are added, make those changes in [API.md](../API.md) according to [iros's template](https://gist.github.com/iros/3426278) +1. If any documentation is needed, add docs 1. Add and commit your code. Please give meaningful commit messages. #### Submitting PullRequest diff --git a/API.md b/API.md deleted file mode 100644 index 5ef17f2..0000000 --- a/API.md +++ /dev/null @@ -1,510 +0,0 @@ -**GitHub Code** ----- - To Fetch GitHub `code` from GitHub api for oauth authorization, run the following url in browser - -* **URL** - - **`https://github.com/login/oauth/authorize?scope=user:email&client_id=97d600c693730ed91ac0`** - -* **Success Response:** - - * **Code:** 200 OK
- **Content:** `code` will be appended as param to your `callback_url` or `redirect_uri` - -**LinkedIn Code** ----- - Fetch code from **LINKEDIN** api for oauth authorization - -* **URL** - - **`https://www.linkedin.com/oauth/v2/authorization?client_id=81ptws4wm9kflx&response_type=code&redirect_uri=http://127.0.0.1:8000/callback`** - -* **Success Response:** - - * **Code:** 200 OK
- **Content:** `code` will be appended as param to your `callback_url` or `redirect_uri` - -**GitHub Login** ----- - Login to the application using **GitHub** - -* **URL** - - **`/v1/auth/github`** - -* **Method:** - - **`POST`** - -* **Data Params** - - **Required:** - - `code=[string]` - -* **Headers** - - **Required:** - - `content-type: application/json` - -* **Success Response:** - - * **Code:** 200 OK
- **Content:** - ```json - { - "token": "eyJ0eXAiOiJKV1QiLCJhbGc", - "user": { - "username": "user123", - "first_name": "P", - "last_name": "User Name", - "avatar": "http://www.sample.com/image.jpg", - "email" : "email@example.com" - } - } - ``` - - -* **Error Response:** - - * **Code:** 400 BAD REQUEST
- **Content:** `{"non_field_errors": ["Incorrect input. access_token or code is required."]}`
- **Problem:** `code is blank or code is not passed as data` - - -* **Sample Call:** - - ``` - curl -X POST \ - http://localhost:8000/v1/auth/github \ - -H 'content-type: application/json' \ - -d '{ - "code" : "e47deee658cb2c59a6" - }' - ``` - -* **Notes:** - - - You may get **500 INTERNAL SERVER ERROR** sometimes, in that case check the error content to find out the problem. - -**LinkedIn Login** ----- - Login to the application using **LinkedIn** - -* **URL** - - **`/v1/auth/linkedin`** - -* **Method:** - - **`POST`** - -* **Data Params** - - **Required:** - - `code=[string]` - -* **Headers** - - **Required:** - - `content-type: application/json` - -* **Success Response:** - - * **Code:** 200 OK
- **Content:** - ```json - { - "token": "eyJ0eXAiOiJKV1QiLCJhbGc", - "user": { - "username": "user123", - "first_name": "P", - "last_name": "User Name", - "avatar": "http://www.sample.com/image.jpg", - "email" : "email@example.com" - } - } - ``` - - -* **Error Response:** - - * **Code:** 400 BAD REQUEST
- **Content:** `{"non_field_errors": ["Incorrect input. access_token or code is required."]}`
- **Problem:** `code is blank or code is not passed in data` - - -* **Sample Call:** - - ``` - curl -X POST \ - http://localhost:8000/v1/auth/linkedin \ - -H 'content-type: application/json' \ - -d '{ - "code" : "e47deee658cb2c59a6" - }' - ``` - -* **Notes:** - - - You may get **500 INTERNAL SERVER ERROR** sometimes, in that case check the error content to find out the problem. - -**JWT Token** ----- - Fetch JWT Token using user credentials - -* **URL** - - **`/api-token-auth`** - -* **Method:** - - **`POST`** - -* **Data Params** - - **Required:** - - `username=[string]` - - `password=[string]` - -* **Headers** - - **Required:** - - `content-type: application/json` - -* **Success Response:** - - * **Code:** 200 OK
- **Content:** ` - { - "token": "eyJ0eXAiOiJKV1QiLCJhbGciO" - }` - - -* **Error Response:** - - * **Code:** 400 BAD REQUEST
- **Content:** `{ - "non_field_errors": [ - "Unable to log in with provided credentials." - ] - }` - - OR - - * **Code:** 400 BAD REQUEST
- **Content:** `{ - "password": [ - "This field may not be blank." - ] - }` - - OR - - * **Code:** 400 BAD REQUEST
- **Content:** `{ - "password": [ - "This field is required." - ] - }` - - -* **Sample Call:** - - ``` - curl -X POST \ - http://localhost:8000/api-token-auth \ - -H 'content-type: application/json' \ - -d '{ - "username": "admin", - "password" : "admin_password" - }' - ``` - -* **Notes:** - - - None - -**User View** ----- - Fetch the details of logged_in user - -* **URL** - - **`/user`** - -* **Method:** - - **`GET`** - -* **Headers** - - **Required:** - - `authorization: JWT ` - -* **Success Response:** - - * **Code:** 200 OK
- **Content:** - ```json - { - "username": "user123", - "first_name": "First", - "last_name": "Last", - "email": "email@example.com" - } - ``` - - -* **Sample Call:** - - ``` - curl -X GET \ - http://localhost:8000/user \ - -H 'authorization: JWT eyJhbGciOiJIUzI1NiIsInR5cCI6Ik' \ - ``` - -* **Notes:** - - None - -**User Update** ----- - Update the details of logged_in user - -* **URL** - - **`/user`** - -* **Method:** - - **`POST`** - -* **URL Params** - - **Optional:** - - `username=[string]` - - `email=[email]` - - `first_name=[string]` - - `last_name=[string]` - - -* **Headers** - - **Required:** - - `authorization: JWT ` - - `content-type: application/json` - -* **Success Response:** - - * **Code:** 200 OK
- **Content:** - ```json - { - "username": "user123", - "first_name": "P", - "last_name": "User Name", - "email" : "email@example.com" - } - ``` - - -* **Sample Call:** - - ``` - curl -X POST \ - http://localhost:8000/user \ - -H 'authorization: JWT eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTE0ODMzOTQsImVtYWlsIjoiIiwidXNlcm5hbWUiOiJiaGFudV90ZWphIiwidXNlcl9pZCI6NzR9.Hc1H8Tt9d2FSJkTEHKjx-fB8cblrg1yKDVK9lzuZ914' \ - -H 'content-type: application/json' \ - -d '{ - "username" : "user123", - "first_name" : "First", - "last_name" : "last", - "email" : "email@example.com" - }' - ``` - -* **Notes:** - - None - -**User Profile View** ----- - Fetch the profile of logged_in user - -* **URL** - - **`/user/profile`** - -* **Method:** - - **`GET`** - -* **Headers** - - **Required:** - - `authorization: JWT ` - -* **Success Response:** - - * **Code:** 200 OK
- **Content:** - ```json - { - "user": { - "username": "user123", - "first_name": "First", - "last_name": "Last", - "email": "email@example.com" - }, - "avatar": "https://avatars3.githubusercontent.com/u/17903466?v=4", - "mobile_number": null, - "short_bio": "This is my short bio", - "job_status": true, - "company_name": "company112", - "looking_for_job": false, - "github_profile": "https://github.com/user123", - "facebook_profile": null, - "twitter_profile": null, - "linkedin_profile": null, - "codepen_profile": null, - "discord_profile": null, - "familiar_technologies": null, - "interested_technologies": null - } - ``` - - -* **Sample Call:** - - ``` - curl -X GET \ - http://localhost:8000/user \ - -H 'authorization: JWT eyJhbGciOiJIUzI1NiIsInR5cCI6Ik' \ - ``` - -* **Notes:** - - None - -**User Profile Update** ----- - Update the profile of logged_in user - -* **URL** - - **`/user/profile`** - -* **Method:** - - **`POST`** - -* **URL Params** - - **Optional:** - - `avatar=[url]` - - `mobile_number=[string]` - - `short_bio=[string]` - - `job_status=[boolean]` - - `company_name=[string]` - - `looking_for_job=[boolean]` - - `github_profile=[url]` - - `facebook_profile=[url]` - - `twitter_profile=[url]` - - `linkedin_profile=[url]` - - `codepen_profile=[url]` - - `discord_profile=[url]` - - `familiar_technologies=[string]` - - `interested_technologies=[string]` - - -* **Headers** - - **Required:** - - `authorization: JWT ` - - `content-type: application/json` - -* **Success Response:** - - * **Code:** 200 OK
- **Content:** - ```json - { - "user": { - "username": "user123", - "first_name": "First", - "last_name": "Last", - "email": "email@example.com" - }, - "avatar": "https://avatars3.githubusercontent.com/u/17903466?v=4", - "mobile_number": null, - "short_bio": "This is my short bio", - "job_status": true, - "company_name": "company112", - "looking_for_job": false, - "github_profile": "https://github.com/user123", - "facebook_profile": null, - "twitter_profile": null, - "linkedin_profile": null, - "codepen_profile": null, - "discord_profile": null, - "familiar_technologies": null, - "interested_technologies": null - } - ``` - - -* **Sample Call:** - - ``` - curl -X POST \ - http://localhost:8000/user \ - -H 'authorization: JWT eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTE0ODMzOTQsImVtYWlsIjoiIiwidXNlcm5hbWUiOiJiaGFudV90ZWphIiwidXNlcl9pZCI6NzR9.Hc1H8Tt9d2FSJkTEHKjx-fB8cblrg1yKDVK9lzuZ914' \ - -H 'content-type: application/json' \ - -d '{ - "avatar": "https://avatars3.githubusercontent.com/u/17903466?v=4", - "mobile_number": "9854785985", - "short_bio": "This is my short bio", - "job_status": true, - "company_name": "company112", - "looking_for_job": false, - "github_profile": "https://github.com/user123", - "facebook_profile": "https://facebook.com/user123", - "twitter_profile": "https://twitter.com/user123", - "linkedin_profile": "https://linkedin.com/user123", - "codepen_profile": "https://codepen.com/user123", - "discord_profile": "https://discord.com/user123", - "familiar_technologies": "c", - "interested_technologies": "c" - }' - ``` - -* **Notes:** - - None \ No newline at end of file diff --git a/webapp/coderplex_apis/db.sqlite3 b/webapp/coderplex_apis/db.sqlite3 index 738daa1..88488e9 100644 Binary files a/webapp/coderplex_apis/db.sqlite3 and b/webapp/coderplex_apis/db.sqlite3 differ diff --git a/webapp/coderplex_apis/settings.py b/webapp/coderplex_apis/settings.py index 25858d3..5d6be5f 100644 --- a/webapp/coderplex_apis/settings.py +++ b/webapp/coderplex_apis/settings.py @@ -45,6 +45,7 @@ 'rest_framework', 'rest_framework.authtoken', 'rest_auth', + 'rest_framework_swagger', 'allauth', 'allauth.account', diff --git a/webapp/coderplex_apis/urls.py b/webapp/coderplex_apis/urls.py index 6e09c9d..a51a85f 100644 --- a/webapp/coderplex_apis/urls.py +++ b/webapp/coderplex_apis/urls.py @@ -19,11 +19,14 @@ from rest_framework_jwt.views import obtain_jwt_token from rest_framework_jwt.views import refresh_jwt_token from rest_framework_jwt.views import verify_jwt_token +from rest_framework_swagger.views import get_swagger_view +schema_view = get_swagger_view(title='CoderPlex APIs') urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^', include('books.urls')), url(r'^$', views.HelloWordView.as_view()), + url(r'^api-docs$', schema_view), url(r'^v1/', include('authentication.urls')), url(r'^callback', views.SocialCodeView.as_view()), url(r'^api-token-auth', obtain_jwt_token),