Skip to content

Latest commit

 

History

History
1111 lines (958 loc) · 20.8 KB

README.md

File metadata and controls

1111 lines (958 loc) · 20.8 KB

In the name of ALLAH

Back-End Document

Django REST Framework

Register

URL = http://127.0.0.1:8000/users/register/

You must post this values:

{
	"password": "",
	"full_name": "",
	"email": ""
}

If registeration was alright:

status = 201_created

{
	"message": "User registered successfully."
}

If email is not valid

status = 400_bad_request

{
	"email": [
		"Enter a valid email address."
	]
}

If user already exists:

status = 400_bad_request

{
	"email": [
		"Uesr with this user email already exists."
	]
}

If the given values ​​are correct

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.

How can the user get the activation link again?

It is enough for the user to request login. If his account is not active, the server will automatically send him an email.

Login

URL = http://127.0.0.1:8000/users/login/

You must post this values:

{
	"password": "",
	"email": ""
}

If password and email is correct and account is active:

status = 200_OK

{
    "refresh": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoicmVmcmVzaCIsImV4cCI6MTcwNDM4MTUzNiwiaWF0IjoxNzA0Mjk1MTM2LCJqdGkiOiI2YWMwZWQ4NjE5MDQ0MTgyYTgwMTZmYjI4MDUyMjQ4ZiIsInVzZXJfaWQiOjYxfQ.5S7rJE9kSNg7tz0qOcFEtS2IYzO_UxFnIL-D8WRt5qs",
    "access": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNzA0Mjk1NDM2LCJpYXQiOjE3MDQyOTUxMzYsImp0aSI6IjVmNzdkMGI3MDVmNjQzNTZhYmEyMjkwZTEwYjBiMzdiIiwidXNlcl9pZCI6NjF9.bUwZzBciJP85dCjaEV9ONZBimY-Aeg_Bx3LZz8j7w8s"
}

If password and email is correct but account is not active:

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."
	]
}

If password or email is not correct:

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

Refresh Token

Endpoint

URL http://127.0.0.1:8000/users/login/refresh/

Method

POST

Parameters

{
    "refresh": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoicmVmcmVzaCIsIV4cCI6MTcxNDk5Mjg5NywiaWF0IjoxNzEyNDAwODk3LCJqdGkiOiI1ZmI0NmNhMDNiMDA0YjJiOGY0MDQzMDk4YzgxNmM2OSIsInVzZXJfaWQiOjF9.U8sSTMyj1zR9Bm-GQ4f_BgR3dBMkYuH0hH1Rrunuxpk"
}

Response

{
    "access": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoYWNjZXNzIiwiZXhwIjoxNzEzNTkzMjg3LCJpYXQiOjE3MTI0MDA4OTcsImp0aSI6ImZhOTYxNThhYWE5NTQ3M2VhMDc1OTE4ZmU0ZjUwMDI4IiwidXNlcl9pZCI6MX0.qQEUvNbv8bpoLjKiySQ5_XzCv_OaeUJiTnYcG74P-cQ"
}

Setting

Personal information

URL http://127.0.0.1:8000/users/settings/personal-info/

GET method

returns personal information

{
    "avatar": null,
    "full_name": "lashv",
    "phone_number": "0910000000",
    "email": "[email protected]"
}

PUT method

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]"
}

Logout

URL http://127.0.0.1:8000/users/logout/

Post the refresh token to the URL as bellow:

{
    "refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoicmVmcmVzaCIsImV4cCI6MTcxNDQxMzAyOSwiaWF0IjoxNzExODIxMDI5LCJqdGkiOiJmMzRiOGE4ZWZkN2I0ODU2YTZiOTg0OWQwYWIyZDNhMSIsInVzZXJfaWQiOjF9.8ONAz358PiAE52qF0snVT-JJWSSWXMoorgsuuZann9s"
}

Responses

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."
}

If it wasn't successful

{
    "message": "An error occurred during logout."
}

Address

Generate data of provinces and cities

In back-end run this command:

python manage.py generate_city Then Iran provinces and cities is added to database.

Retrieving All Provinces

To get all the provinces, send a GET request to the following url.

Endpoint

URL http://127.0.0.1:8000/users/provinces/

Method

GET

Example Response

You then get a response like this:

[
    {
        "id": 1,
        "name": "آذربایجان شرقی"
    },
    {
        "id": 2,
        "name": "آذربایجان غربی"
    },
    {
        "id": 3,
        "name": "اردبیل"
    }
]

Retrieving All Cities

You can retrieve a list of all available cities in the system using a GET or POST request.

Endpoint

URL http://127.0.0.1:8000/users/cities/

Method POST

If you want the cities of a specific province.

Request Parameters
{
    "province": "اصفهان"
}
Example Response
[
    {
        "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"
}

Method GET

If you want the list of all cities.

Address CRUD

Endpoint

URL http://127.0.0.1:8000/users/settings/address-list/

Method: GET

Response

Returns a list of user addresses.

[
    {
        "id": 2,
        "user": 1,
        "province_name": "اصفهان",
        "city_name": "اصفهان"
    }
]

Method: POST

You can create a new address for user. You just need to post following fields.

{
    "province": "اصفهان",
    "city": "اصفهان"
}
Responses

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}"
}

Endpoint

URL http://127.0.0.1:8000/users/settings/address-edit/id

You need to add the id of that specific address in the url.

Method: GET

To get a specific address.

Response

If an address with that id doesn't exist:

[
    "Not found!"
]

Otherwise:

{
    "id": 2,
    "user": 1,
    "province_name": "اصفهان",
    "city_name": "اصفهان"
}
Method: PUT

If you want to edit a specific address. You need to add all or some of the following fields to your body.

{
    "province": "تهران",
    "city": "تهران"
}
Response

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.

Method: DELETE

If you want to delete a specific address.

Response

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.




Restore database

python manage.py dbrestore




Search User

Get User Public Information With His Email.

URL http://127.0.0.1:8000/users/search/
Method GET

Parameters

{
    "email": "[email protected]"
}

Response

{
    "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"
}

Job

Get User Job List

Endpoint

URL http://127.0.0.1:8000/jobs/user/info/
Method GET

Response
[
    {
        "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
    }
]

Get One User Job With id

Endpoint

URL http://127.0.0.1:8000/jobs/user/info/{id}/
Method GET

Response

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."
}

Create a New Job For User

URL http://127.0.0.1:8000/jobs/user/info/
Method POST

Parameters
{
    "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.

Response
{
    "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
}

Edit a User Job With id

URL http://127.0.0.1:8000/jobs/user/info/{id}/
Method PUT

Parameters
{
    "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"
        }
    ]
}
Response

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."
}

All Job List

Endpoint

URL http://127.0.0.1:8000/jobs/list/ Method GET

Response
[
    {
        "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"
    }
]

Job Picture

Add a picture for a job.

URL http://127.0.0.1:8000/jobs/user/pictures/ Method POST

Parameters
{
    "image": "Put the job file here",
    "job": 5
}
Response
{
    "id": 3,
    "image": "http://127.0.0.1:8000/media/images/job_images/wp7579146-badlands-halsey-wallpapers_ZVKx14a.png",
    "job": 5
}

Job Comments

Create a comment

URL http://127.0.0.1:8000/jobs/comment/create/
Method POST

Parameters
{
    "title": "Test cccc",
    "comment": "This is a test comcccment",
    "rating": 5,
    "job": 1
}
Response
{
    "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."
}

Edit a comment

URL http://127.0.0.1:8000/jobs/comment/edit/{id}
Method PUT

Parameters
{
    "title": "Test cccc",
    "comment": "This is a test comcccment",
    "rating": 5,
    "job": 1
}
Response
{
    "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
}

Get Skills

URL http://127.0.0.1:8000/jobs/skills/
Method GET

Response
[
    {
        "id": 1,
        "title": "Skill_1"
    },
    {
        "id": 2,
        "title": "Skill_2"
    }
]

Support

Spam Report

URL http://127.0.0.1:8000/support/spam_report/
Method POST

Parameters
{
    "message": "This shit is harsh",
    "job": 1
}
Responses

If data is valid SpamRepost is created. status = 200

{
    "message": "This shit is harsh",
    "job": 1
}

If data is not valid. status = 400

Send Message

URL http://127.0.0.1:8000/support/send_message/
Method POST

Parameters
{
    "recipient_email": "[email protected]",
    "content" : "message from postman1"
}
Response
{
    "content": "message from postman1",
    "timestamp": "2024-05-13T12:40:24.224334+03:30",
    "sender_email": "[email protected]",
    "recipient_email": "[email protected]"
}

Chat Room

URL http://127.0.0.1:8000/support/chatroom/{recipient_email}/
Method GET

Response
[
    {
        "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]"
    }
]

Cases

Get a list of all cases.

URL http://127.0.0.1:8000/support/cases/
Method GET

Responses
[
    {
        "id": 1,
        "title": "Case1"
    },
    {
        "id": 2,
        "title": "Case2"
    }
]

Case Chats

URL http://127.0.0.1:8000/support/cases/{case_id}/chats/
Method GET

Response
[
    {
        "id": 1,
        "title": "Chat1_case1",
        "last_updated": "2024-05-14T09:00:45.985757+03:30",
        "case": 1
    }
]

Get Chat Messages

URL http://127.0.0.1:8000/support/cases/chat/{chat_id}/messages/
Method GET

Response
[
    {
        "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
    }
]

Create Chat Messages

URL http://127.0.0.1:8000/support/cases/chat/create_message/
Method POST

Parameters
{
    "content": "message from postman 938492",
    "chat": 1
}
Response
{
    "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."
    ]
}

Time Table

Update time table

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"
                }
            ]
        }
    ]
}

ok

HTTP_200_OK

{
    "message": "Timetable updated successfully"
}

invalid job id

HTTP_404_NOT_FOUND

{
    "error": "Job does not exist"
}

job is not for this user

HTTP_403_FORBIDDEN

{
"messate" : "You are not allowed to change this job"
}

Get time table

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": []
            }
        ]
    }
]