Skip to content

API set up using Django REST Framework for the SnapFood Front-End application

Notifications You must be signed in to change notification settings

aleksandrajh/snapfood-drf-api

Repository files navigation

SnapFood API in DRF

Developer: Aleksandra Haniok

💻 Live link

This repository contains the API set up using Django REST Framework for the SnapFood front-end application (repository here and live website here)

Table of Contents

User Stories

The back-end section of the project focuses on its administration side and covers one user story:

  • As an admin, I want to be able to create, edit and delete the users, posts, comments and likes, so that I can have a control over the content of the application and remove any potential inappropriate content

Database

The following models were created to represent the database model structure of the application:

User Model

  • The User model contains information about the user. It is part of the Django allauth library.
  • One-to-one relation with the Profile model owner field
  • ForeignKey relation with the Follower model owner and followed fields
  • ForeignKey relation with the Post model owner field
  • ForeignKey relation with the Comment model owner field
  • ForeignKey relation with the Like model owner field

Profile Model

  • The Profile model contains the following fields: owner, name, description, created_on, updated_on and image
  • One-to-one relation between the owner field and the User model id field

Post Model

  • The Post model contains the following fields: owner, created_on, updated_on, title, description, category and image
  • ForeignKey relation with the Comment model post field
  • ForeignKey relation with the Like model post field

Follower Model

  • The Follower model contains the following fields: owner, followed and created_on
  • ForeignKey relation between the owner field and the User model id field
  • ForeignKey relation between the followed field and the User model post field

Comment Model

  • The Comment model contains the following fields: owner, post, created_on, updated_on and content
  • ForeignKey relation between the owner field and the User model id field
  • ForeignKey relation between the post field and the User model post field

Like Model

  • The Like model contains the following fields: owner, post and created_on
  • ForeignKey relation between to the User model id field
  • ForeignKey relation between the owner field and the User model id field
  • ForeignKey relation between the post field and the Post model post field
Back to top

Technologies Used

Languages & Frameworks

  • Python
  • Django

Libraries & Tools

  • APITestCase - Django Rest Framework APITestCase was used for automated testing
  • Cloudinary to store static files
  • Coverage used to produce automated testing report
  • Dbdiagram.io used for the database schema diagram
  • Git was used for version control via Gitpod terminal to push the code to GitHub
  • GitHub was used as a remote repository to store project code
  • Gitpod) - a virtual IDE workspace used to build this site
  • Render Platform was used to deploy the project into live environment
  • Django REST Framework was used to build the back-end API
  • Django AllAuth was used for user authentication
  • Pillow was used for image processing and validation
  • Psycopg2 was used as a PostgreSQL database adapter for Python
  • PostgreSQL – deployed project on Render uses a PostgreSQL database
Back to top

Validation

PEP8 Validation

PEP8 Validation Service was used to check the code for PEP8 requirements. All the code passes with no errors or warnings.

Testing

The following tests were carried out on the app:

  1. Manual testing of user stories
  2. Automated testing

Manual testing of user stories

  • As an admin, I want to be able to create, edit and delete the users, posts, comments and likes, so that I can have a control over the content of the application and remove any potential inappropriate content
Test Action Expected Result Actual Result
User Create, update & delete user A user can be created, edited or deleted Works as expected
User Change permissions User permissions can be updated Works as expected
Profile Create, update & delete User profile can be created, edited or deleted Works as expected
Post Create, update & delete A post can be created, edited or deleted Works as expected
Comment Create, update & delete A comment can be created, edited or deleted Works as expected
Like Create & delete A like can be created or deleted (like / unlike post) Works as expected
Follower Create & delete Follow or unfollow user Works as expected

In addition, posts, comments, likes and following can be created by logged-in users only. Users can only update or delete the content which was created by themselves.

Screenshots - USER
Create user
Change user permissions
Screenshots - PROFILE
Update profile
Delete profile
Screenshots - POST
Create post
Update post
Delete post
Screenshots - COMMENT
Create comment
Update comment
Delete comment
Screenshots - LIKE
Create like - like post
Delete like - unlike post
Screenshots - FOLLOWER
Create - Follow user
Delete - Unfollow user

Automated testing

Automated testing was done using the Django Rest Framework APITestCase (a very similar to Django's TestCase). The report of overall testing was produced using the coverage tool ($ coverage report & $ coverage html commands)

  • Tests summary

Detailed coverage report
Back to top

Credits

Images

  • User avatar default image taken from here and colors changed using Paint
  • Default post image found here and tweaked with Paint

Code

This project was created based on the Code Institute's Django REST API walkthrough project 'Moments' which was a great learning experience.

Back to top

About

API set up using Django REST Framework for the SnapFood Front-End application

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published