In the name of ALLAH
Django REST Framework
You must post this values:
{
"password": "",
"full_name": "",
"email": ""
}
status = 201_created
{
"message": "User registered successfully."
}
status = 400_bad_request
{
"email": [
"Enter a valid email address."
]
}
status = 400_bad_request
{
"email": [
"Uesr with this user email already exists."
]
}
An email will be sent to the user to activate the user account. The user cannot activate his account for login until he clicks on the link sent. Sent emails have an expiration date of 2 minutes. If this time is over, the links sent in the email can no longer be used.
It is enough for the user to request login. If his account is not active, the server will automatically send him an email.
You must post this values:
{
"password": "",
"email": ""
}
status = 200_OK
{
"refresh": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoicmVmcmVzaCIsImV4cCI6MTcwNDM4MTUzNiwiaWF0IjoxNzA0Mjk1MTM2LCJqdGkiOiI2YWMwZWQ4NjE5MDQ0MTgyYTgwMTZmYjI4MDUyMjQ4ZiIsInVzZXJfaWQiOjYxfQ.5S7rJE9kSNg7tz0qOcFEtS2IYzO_UxFnIL-D8WRt5qs",
"access": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNzA0Mjk1NDM2LCJpYXQiOjE3MDQyOTUxMzYsImp0aSI6IjVmNzdkMGI3MDVmNjQzNTZhYmEyMjkwZTEwYjBiMzdiIiwidXNlcl9pZCI6NjF9.bUwZzBciJP85dCjaEV9ONZBimY-Aeg_Bx3LZz8j7w8s"
}
status = 401_Unauthorized
{
"non_field_errors": [
"Your account is not active. Please check your email for the confirmation link.We sent new link for you."
]
}
status = 401_Unauthorized
{
"non_field_errors": [
"Invalid credentials"
]
}
JWT security protocol is used for login in the above method. Therefore, the front-end can be given the value: Token = "access" In the Header, for each authenticated request, fetch the necessary information from the backend. How to place the new header in the rest of the requests is as follows:
Key | Value |
---|---|
Authorization | Bearer accesstoken |
POST
{
"refresh": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoicmVmcmVzaCIsIV4cCI6MTcxNDk5Mjg5NywiaWF0IjoxNzEyNDAwODk3LCJqdGkiOiI1ZmI0NmNhMDNiMDA0YjJiOGY0MDQzMDk4YzgxNmM2OSIsInVzZXJfaWQiOjF9.U8sSTMyj1zR9Bm-GQ4f_BgR3dBMkYuH0hH1Rrunuxpk"
}
{
"access": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoYWNjZXNzIiwiZXhwIjoxNzEzNTkzMjg3LCJpYXQiOjE3MTI0MDA4OTcsImp0aSI6ImZhOTYxNThhYWE5NTQ3M2VhMDc1OTE4ZmU0ZjUwMDI4IiwidXNlcl9pZCI6MX0.qQEUvNbv8bpoLjKiySQ5_XzCv_OaeUJiTnYcG74P-cQ"
}
returns personal information
{
"avatar": null,
"full_name": "lashv",
"phone_number": "0910000000",
"email": "[email protected]"
}
you can send some or all of the fields as follow:
{
"full_name": "ali"
}
and it returns
{
"avatar": null,
"full_name": "ali",
"phone_number": "0910000000",
"email": "[email protected]"
}
If user changes his email, an activation link will be sent to activate his email. and response would look like this:
{
"message": "Your new email address has been set, but it needs to be activated. Please check your inbox for an activation email.",
"avatar": null,
"full_name": "ali",
"phone_number": "0910000000",
"email": "[email protected]"
}
Post the refresh token to the URL as bellow:
{
"refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoicmVmcmVzaCIsImV4cCI6MTcxNDQxMzAyOSwiaWF0IjoxNzExODIxMDI5LCJqdGkiOiJmMzRiOGE4ZWZkN2I0ODU2YTZiOTg0OWQwYWIyZDNhMSIsInVzZXJfaWQiOjF9.8ONAz358PiAE52qF0snVT-JJWSSWXMoorgsuuZann9s"
}
If Refresh Token Not Provided.
{
"error": "Missing refresh token"
}
If Logout Was Successful.
{
"message": "You have been successfully logged out."
}
If Logout Was Not Successful.
{
"message": "An error occurred during logout."
}
{
"message": "An error occurred during logout."
}
In back-end run this command:
python manage.py generate_city Then Iran provinces and cities is added to database.
To get all the provinces, send a GET request to the following url.
GET
You then get a response like this:
[
{
"id": 1,
"name": "آذربایجان شرقی"
},
{
"id": 2,
"name": "آذربایجان غربی"
},
{
"id": 3,
"name": "اردبیل"
}
]
You can retrieve a list of all available cities in the system using a GET or POST request.
If you want the cities of a specific province.
{
"province": "اصفهان"
}
[
{
"id": 571,
"name": "ادیمی",
"province": 16
},
{
"id": 572,
"name": "اسپكه",
"province": 16
},
{
"id": 573,
"name": "ایرانشهر",
"province": 16
}
]
If province not found you get this error:
{
"error": "Province not found"
}
If you want the list of all cities.
Returns a list of user addresses.
[
{
"id": 2,
"user": 1,
"province_name": "اصفهان",
"city_name": "اصفهان"
}
]
You can create a new address for user. You just need to post following fields.
{
"province": "اصفهان",
"city": "اصفهان"
}
If 'province' not found or doesn't exist, you get HTTP_404_NOT_FOUND error:
{
"message": "Province does not exist."
}
If 'city' not found or doesn't exist, you get HTTP_404_NOT_FOUND error:
{
"message": "City does not exist."
}
If creating new address was successful, you get HTTP_201_CREATED:
{
"id": 4,
"user": 1,
"province_name": "اصفهان",
"city_name": "اصفهان"
}
If any other exception occurs, you get HTTP_400_BAD_REQUEST:
{
"message": "Error creating address: {e}"
}
You need to add the id of that specific address in the url.
To get a specific address.
If an address with that id doesn't exist:
[
"Not found!"
]
Otherwise:
{
"id": 2,
"user": 1,
"province_name": "اصفهان",
"city_name": "اصفهان"
}
If you want to edit a specific address. You need to add all or some of the following fields to your body.
{
"province": "تهران",
"city": "تهران"
}
If it was successful, you get the updated data:
{
"id": 2,
"user": 1,
"province_name": "تهران",
"city_name": "تهران"
}
If the province or city that was sent didn't exist, that specific field won't be updated. you'll get same data.
for example if PUT something like this:
{
"province": "fake city name",
"city": "تهران"
}
you'll get:
{
"id": 2,
"user": 1,
"province_name": "تهران",
"city_name": "تهران"
}
because "province": "fake city name" is not a province name.
If you want to delete a specific address.
If an address with that id doesn't exist, you get a HTTP_404_NOT_FOUND error:
{
"message": "Address does not exist"
}
If delete was successful: It would return null (means data is deleted) and it's status is HTTP_204_NO_CONTENT.
python manage.py dbrestore
Get User Public Information With His Email.
URL http://127.0.0.1:8000/users/search/
Method GET
{
"email": "[email protected]"
}
{
"avatar": null,
"full_name": "lashv",
"phone_number": null,
"email": "[email protected]"
}
If email not send
{
"error": "Email is required"
}
If user not found
{
"message": "User with this email not found"
}
URL http://127.0.0.1:8000/jobs/user/info/
Method GET
[
{
"id": 1,
"title": "Job1",
"SubCategory": 1,
"Sub_category_title": "Sub category",
"Main_category_title": "Main category",
"user_email": "[email protected]",
"main_picture": null,
"main_picture_url": null,
"pictures": [],
"description": "This is Job1.",
"comments": [],
"skills": [],
"experiences": "",
"approximation_cph": null,
"initial_cost": null,
"province_name": "Isfahan",
"city_name": "Isfahan",
"average_rating": 0.0
}
]
URL http://127.0.0.1:8000/jobs/user/info/{id}/
Method GET
If Job Exists.
{
"id": 12,
"title": "Job5",
"SubCategory": 1,
"Sub_category_title": "Subcat1",
"Main_category_title": "Cat1",
"user_email": "[email protected]",
"main_picture": 1,
"main_picture_url": "http://127.0.0.1:8000/media/images/job_images/%D8%A8%D8%B1%D9%86%D8%A7%D9%85%D9%87.png",
"pictures": [
{
"id": 1,
"image": "http://127.0.0.1:8000/media/images/job_images/%D8%A8%D8%B1%D9%86%D8%A7%D9%85%D9%87.png",
"job": 12
}
],
"description": "this is job5",
"comments": [
{
"id": 1,
"user_full_name": "lashv",
"user_email": "[email protected]",
"title": "Comment 1",
"comment": "This is a comment.",
"rating": 2,
"date": "2024-05-03T08:49:59+03:30",
"job": 12
}
],
"skills": [
{
"id": 1,
"title": "Skill1"
},
{
"id": 2,
"title": "Skill2"
}
],
"experiences": "experiences",
"approximation_cph": "approximation_cph",
"initial_cost": "initial_cost",
"province_name": "Tehran",
"city_name": "Tehran",
"average_rating": 2.0
}
If Job Doesn't Exist.
{
"detail": "You do not have permission to perform this action."
}
URL http://127.0.0.1:8000/jobs/user/info/
Method POST
{
"title": "Job5",
"SubCategory": 1,
"province": "Tehran",
"city": "Tehran",
"description": "this is job1",
"experiences": "experiences",
"approximation_cph": "approximation_cph",
"initial_cost": "initial_cost",
"skills": [
{
"title": "Skill1"
}
]
}
First four are required.
{
"id": 13,
"title": "Job5",
"SubCategory": 1,
"Sub_category_title": "Subcat1",
"Main_category_title": "Cat1",
"user_email": "[email protected]",
"main_picture": null,
"main_picture_url": null,
"pictures": [],
"description": "this is job1",
"comments": [],
"skills": [
{
"id": 1,
"title": "Skill1"
}
],
"experiences": "experiences",
"approximation_cph": "approximation_cph",
"initial_cost": "initial_cost",
"province_name": "Tehran",
"city_name": "Tehran",
"average_rating": 0.0
}
URL http://127.0.0.1:8000/jobs/user/info/{id}/
Method PUT
{
"title": "Job5",
"SubCategory": 1,
"province": "Tehran",
"city": "Tehran",
"description": "this is job1",
"experiences": "experiences",
"approximation_cph": "approximation_cph",
"initial_cost": "initial_cost",
"skills": [
{
"title": "Skill1"
}
]
}
If Job Exists.
{
"id": 13,
"title": "Job5",
"SubCategory": 1,
"Sub_category_title": "Subcat1",
"Main_category_title": "Cat1",
"user_email": "[email protected]",
"main_picture": null,
"main_picture_url": null,
"pictures": [],
"description": "this is job1",
"comments": [],
"skills": [
{
"id": 1,
"title": "Skill1"
}
],
"experiences": "experiences",
"approximation_cph": "approximation_cph",
"initial_cost": "initial_cost",
"province_name": "Tehran",
"city_name": "Tehran",
"average_rating": 0.0
}
If Job Doesn't Exist.
{
"detail": "You do not have permission to perform this action."
}
URL http://127.0.0.1:8000/jobs/list/ Method GET
[
{
"id": 3,
"title": "Job1",
"description": null,
"average_rating": 0.0,
"main_picture_url": null,
"province_name": "Tehran",
"city_name": "Tehran"
},
{
"id": 4,
"title": "Job1",
"description": "this is job1",
"average_rating": 0.0,
"main_picture_url": null,
"province_name": "Tehran",
"city_name": "Tehran"
}
]
Add a picture for a job.
URL http://127.0.0.1:8000/jobs/user/pictures/ Method POST
{
"image": "Put the job file here",
"job": 5
}
{
"id": 3,
"image": "http://127.0.0.1:8000/media/images/job_images/wp7579146-badlands-halsey-wallpapers_ZVKx14a.png",
"job": 5
}
URL http://127.0.0.1:8000/jobs/comment/create/
Method POST
{
"title": "Test cccc",
"comment": "This is a test comcccment",
"rating": 5,
"job": 1
}
{
"id": 2,
"user_full_name": "lashv",
"user_email": "[email protected]",
"title": "Test Comment",
"comment": "This is a test comment",
"rating": 1,
"date": "2024-05-03T08:55:59.218925+03:30",
"job": 1
}
If you already have a comment for this job:
{
"error": "You have already commented on this job."
}
URL http://127.0.0.1:8000/jobs/comment/edit/{id}
Method PUT
{
"title": "Test cccc",
"comment": "This is a test comcccment",
"rating": 5,
"job": 1
}
{
"id": 3,
"user_full_name": "lashv",
"user_email": "[email protected]",
"title": "Test cccc",
"comment": "This is a test comcccment",
"rating": 5,
"date": "2024-05-03T09:00:57.283926+03:30",
"job": 1
}
URL http://127.0.0.1:8000/jobs/skills/
Method GET
[
{
"id": 1,
"title": "Skill_1"
},
{
"id": 2,
"title": "Skill_2"
}
]
URL http://127.0.0.1:8000/support/spam_report/
Method POST
{
"message": "This shit is harsh",
"job": 1
}
If data is valid SpamRepost is created. status = 200
{
"message": "This shit is harsh",
"job": 1
}
If data is not valid. status = 400
URL http://127.0.0.1:8000/support/send_message/
Method POST
{
"recipient_email": "[email protected]",
"content" : "message from postman1"
}
{
"content": "message from postman1",
"timestamp": "2024-05-13T12:40:24.224334+03:30",
"sender_email": "[email protected]",
"recipient_email": "[email protected]"
}
URL http://127.0.0.1:8000/support/chatroom/{recipient_email}/
Method GET
[
{
"content": "M1",
"timestamp": "2024-05-13T11:05:54.070741+03:30",
"sender_email": "[email protected]",
"recipient_email": "[email protected]"
},
{
"content": "M2",
"timestamp": "2024-05-13T11:06:00.656018+03:30",
"sender_email": "[email protected]",
"recipient_email": "[email protected]"
},
{
"content": "M3",
"timestamp": "2024-05-13T11:06:07.543466+03:30",
"sender_email": "[email protected]",
"recipient_email": "[email protected]"
}
]
Get a list of all cases.
URL http://127.0.0.1:8000/support/cases/
Method GET
[
{
"id": 1,
"title": "Case1"
},
{
"id": 2,
"title": "Case2"
}
]
URL http://127.0.0.1:8000/support/cases/{case_id}/chats/
Method GET
[
{
"id": 1,
"title": "Chat1_case1",
"last_updated": "2024-05-14T09:00:45.985757+03:30",
"case": 1
}
]
URL http://127.0.0.1:8000/support/cases/chat/{chat_id}/messages/
Method GET
[
{
"content": "This m1",
"timestamp": "2024-05-14T12:22:49.995461+03:30",
"chat": 1
},
{
"content": "fasdfad",
"timestamp": "2024-05-14T12:26:52.803369+03:30",
"chat": 1
}
]
URL http://127.0.0.1:8000/support/cases/chat/create_message/
Method POST
{
"content": "message from postman 938492",
"chat": 1
}
{
"content": "message from postman 938492",
"timestamp": "2024-05-14T17:12:16.901707+03:30",
"chat": 1
}
If Chat Doesn't Exist!
{
"chat": [
"Invalid pk \"133\" - object does not exist."
]
}
URL http://127.0.0.1:8000/jobs/timetable/{job_id} Method POST
{
"timetable": [
{
"day_of_week": "friday",
"time_slots": [
{
"start_time": "11:00:00",
"end_time": "12:00:00"
},
{
"start_time": "15:00:00",
"end_time": "17:00:00"
}
]
},
{
"day_of_week": "saturday",
"time_slots": [
{
"start_time": "11:00:00",
"end_time": "12:00:00"
}
]
}
]
}
HTTP_200_OK
{
"message": "Timetable updated successfully"
}
HTTP_404_NOT_FOUND
{
"error": "Job does not exist"
}
HTTP_403_FORBIDDEN
{
"messate" : "You are not allowed to change this job"
}
URL http://127.0.0.1:8000/jobs/user/info/ Method GET
[
{
"id": 1,
"title": "Jobb",
"SubCategory": 1,
"Sub_category_title": "subcat",
"Main_category_title": "maincat",
"user_email": "[email protected]",
"main_picture": null,
"main_picture_url": null,
"pictures": [],
"description": "this is job1",
"comments": [],
"skills": [
{
"id": 1,
"title": "skill1"
}
],
"experiences": "experiences",
"approximation_cph": "approximation_cph",
"initial_cost": "initial_cost",
"province_name": "Tehran",
"city_name": "Tehran",
"average_rating": 0.0,
"timetable": [
{
"id": 1,
"day_of_week": "friday",
"time_slots": []
},
{
"id": 2,
"day_of_week": "saturday",
"time_slots": []
}
]
}
]