by Rosie Maguire
She Codes crowdfunding project - DRF Backend.
Explore the docs »
View Demo
·
Report Bug
·
Request Feature
Table of Contents
This project is the back end of a crowdfunding website which has been created to support people with raising funds for their furry children's medical expenses. You can find the front end repository here.
- User Log in/Out
- Project creation (must be logged in user)
- Project owner can update project
- Pledge creation (must be logged in as user)
- Pledge supporter can update pledge
- Pledges able to be created without comment (optional field)
- User able to update own details (and Admins able to update any user's details)
- Created date field for projects and pledges are automatically set based on when the pledge/project was created
- Last modified date for projects and pledges are automatically updated with each PUT request
- Pledge put request does not allow any modification of which project it is attached to
- Pledges cannot be created or modified for projects that are set to closed
- Project owner only able to update open/closed and deleted field if project has been set to closed
- Users able to "soft delete" projects and pledges they own (e.g. set deleted field to 1 which hides in front end) own pledges/projects
- Put restrictions around user creation
- Validation to ensure at least one field is modified in PUT Request (rather than just updating the last_modified date because PUT request fields are identical to data in table)
See the open issues for a full list of proposed features (and known issues).
To get a local copy up and running follow these simple example steps.
Deployed Project: Deployed website
python
pip
- unrestricted execution policy (Windows requirement)
-
Clone a copy of this repo to your local machine. This can be done in the command line by navigating to the desired directory, then running:
git clone https://github.com/rosiemaguire/Django-crowd-funding-project.git
-
Once you have a local version of this repository, you'll need to set up your virtual environment:
-
navigate to the folder that contains the
requirements.txt
file -
If you're on a windows machine, run the command . venv/Scripts/activate
-
If you're on a mac, run the command source venv/bin/activate
-
Install the Django library: python -m pip install -r requirements.txt
-
Check installation was successful:
python -m pip freeze
-
Change directory to where manage.py is located: cd crowdfunding
-
Make the inital migrations:
python manage.py migrate
-
Now with everything set up, you'll just need to run the server!
python manage.py runserver
-
Use the url http://127.0.0.1:8000/, your favourite API Tool (e.g. Insomnia, Postman) and refer to the API Specifications to create HTTP requests
-
When you're finished press CTRL+C to quit the server
-
Deactivate the virtual environment by either using the command
deactivate
or terminate your terminal session.
-
HTTP Method | Url | Purpose | Request Body | Successful Response Code | Authentication Authorization |
---|---|---|---|---|---|
GET | projects/ | Return all projects | N/A | 200 | N/A |
GET | pledges/ | Return all pledges | N/A | 200 | N/A |
GET | users/ | Return all users | N/A | 200 | Bearer Token authentication. Administrator user can view list of all users. Non administrator user will only return own user object. |
POST | projects/ | Create a new project | project object | 201 | Bearer Token authentication. User must be logged in. |
POST | pledges/ | Create a new pledge | pledge object | 201 | Bearer Token authentication. User must be logged in. |
POST | users/ | Create a new user | user object | 201 | N/A |
POST | api-token-auth/ | Obtain Bearer Token for Authorisation | username and password | 200 | N/A |
PUT | projects/< int:pk >/ | Update project | project object or project field | 201 | Bearer Token authentication. User must be logged in. Must be the owner of the project. |
PUT | pledges/< int:pk >/ | Update pledge | pledge object or pledge field | 201 | Bearer Token authentication. User must be logged in. Must be the owner of the pledge. |
PUT | users/< int:pk >/ | Update user | user object or user field | 201 | Bearer Token authentication. User must be logged in. Must be the user that is being updated or a user with Administrator permissions. |
DEL | projects/< int:pk >/ | Delete Project | N/A | 204 | Bearer Token authentication. User must be logged in. Must be a user with Administrator permissions. |
DEL | projects/< int:pk >/ | Delete Project | N/A | 204 | Bearer Token authentication. User must be logged in as administrator. |
-
Create a new HTTP Request in your favourite API Tool (e.g. Postman, Insomnia)
- Use the endpoint https://advocat.fly.dev/users/
-
Choose the POST method
-
Change the body type to JSON
-
Minimum fields required to create a new user:
- username
- password
-
Example request body:
{ "username": "janedoe", "password": "strongrandompassword", "email": "[email protected]" }
-
-
A successful request will return a 200 response and return the user object
{ "username": "janedoe", "first_name": "", "last_name": "", "email": "[email protected]", "date_joined": "2023-08-12T12:45:29.767395+10:00" }
-
Create a new HTTP POST Request using the endpoint https://advocat.fly.dev/api-token-auth/
-
Change the body type to JSON
-
Provide the username and password in the body
-
Example request body:
{ "username": "janedoe", "password": "strongrandompassword" }
-
-
A successful request will return a 200 response along with the token you will need to make requests that require authentication
{ "token": "c07f7a567c5f29db440bfbd2846b97ffe34f0088" }
-
Create a new HTTP POST Request using the endpoint https://advocat.fly.dev/projects/
-
Change the body type to JSON
-
Minimum fields required:
- title
- description
- goal
-
Example request body:
{ "title": "Test Project", "description": "This is a test project", "goal": 150, "image": "https://picsum.photos/600", "is_open": true }
-
-
A successful request will return a 201 response and the project object just created
{ "id": 1, "owner": "admin", "title": "Test Project", "description": "This is a test project", "goal": 150, "image": "https://picsum.photos/600", "is_open": true, "date_created": "2023-08-12T14:58:21.824004+10:00", "last_modified": "2023-08-12T14:58:21.824028+10:00" }
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Rosie Maguire - @rosie_maguire
Project Link: https://github.com/rosiemaguire/Django-crowd-funding-project