Skip to content

AlexaH88/gamer-guild-api

Repository files navigation

Gamer Guild API

The Gamer Guild API was created to serve the Gamer Guild React app. The API includes the following apps, allowing for a rich database and a versatile front-end application:

  • profiles
  • followers
  • posts
  • likes
  • comments
  • events
  • replies
  • polls (this model could ultimately not be implemented on the front-end)

User Experience (UX)

User stories

  • In order to fulfill the User Stories created for this portfolio project, relevant apps and models were created. The following user stories relied on the API specifically: API User Stories

Entity Relationship Diagram

  • The following Entity Relationship Diagram was created to show the models used. The in-built Django User model was used for this project, and the following custom models were created:

    • Profile
    • Follower
    • Post
    • Like
    • Comment
    • Event
    • Reply
    • Poll (this model could ultimately not be implemented on the front-end)
  • Entity Relationship Diagram: Entity Relationship Diagram

Technologies Used

Languages Used

Frameworks, Libraries & Programs Used

  1. Django:

    • Django was used to create the web application.
  2. Django Rest Framework:

    • The Django rest framework was used to simplify the process between the back and front ends.
  3. PostgreSQL:

    • PostgreSQL was used as the object-relational database system.
  4. ElephantSQL:

    • ElephantSQL was used to host the database.
  5. Git:

    • Git was used for version control by utilizing the Gitpod terminal to commit to Git and Push to GitHub.
  6. GitHub:

    • GitHub is used to store the projects code after being pushed from Git.
  7. Heroku:

    • Heroku was used for the deployed application.

Testing

Python Testing

  • CI Python Linter was used to validate the Python code in this project. All code passed without errors, except settings.py and env.py which showed E501 'line too long' warnings. Results settings.py Results env.py

Manual Testing

  • Manual testing was performed throughout development, ensuring the database was being updated as expected when creating, reading, updating or deleting data, where appropriate.

  • Screenshots are provided for the Profiles app, testing was carried out equally for all other apps, and is noted below.

Profiles App

  • List View (Read if logged in): List View
  • List View (Read if not logged in): List View
  • Detail View (Read, Update if owner): Detail View
  • Detail View (Read if not owner): Detail View
  • Detail View (Read if not logged in): Detail View

Followers App

  • List View (Read, Create if logged in)
  • List View (Read if not logged in)
  • Detail View (Read, Delete if owner)
  • Detail View (Read if not owner)
  • Detail View (Read if not logged in)

Posts App

  • List View (Read, Create if logged in)
  • List View (Read if not logged in)
  • Detail View (Read, Update, Delete if owner)
  • Detail View (Read if not owner)
  • Detail View (Read if not logged in)

Likes App

  • List View (Read, Create if logged in)
  • List View (Read if not logged in)
  • Detail View (Read, Delete if owner)
  • Detail View (Read if not owner)
  • Detail View (Read if not logged in)

Comments App

  • List View (Read, Create if logged in)
  • List View (Read if not logged in)
  • Detail View (Read, Update, Delete if owner)
  • Detail View (Read if not owner)
  • Detail View (Read if not logged in)

Events App

  • List View (Read, Create if logged in)
  • List View (Read if not logged in)
  • Detail View (Read, Update, Delete if owner)
  • Detail View (Read if not owner)
  • Detail View (Read if not logged in)

Replies App

  • List View (Read, Create if logged in)
  • List View (Read if not logged in)
  • Detail View (Read, Delete if owner)
  • Detail View (Read if not owner)
  • Detail View (Read if not logged in)

Polls App

  • List View (Read, Create if logged in)
  • List View (Read if not logged in)
  • Detail View (Read, Update, Delete if owner)
  • Detail View (Read if not owner)
  • Detail View (Read if not logged in)

Fixed Bugs

Event Date Bug:

  • When editing an event on the front-end app via the EventEditForm the date field was not populated with the existing date previously created by the user via the EventCreateForm.

  • On further inspection in the console, this error was caused by the date format not being the same as the form required, as I had applied a DATE_FORMAT in the back-end API settings to make the date more human-friendly and readable e.g. 01/05/2023. Event Dates Bug

  • As MDN Web Docs states, this format comes from the browser and can not be changed.

  • In order to avoid this issue, the date format was reverted to the required yyyy-MM-dd format. As a future implementation, a workaround could be to convert the format from one to the other with JavaScript as required.

Database Bugs:

  • I had recurring bugs with my database, with there being a disconnect between the migrated models and existing data in the database.

  • As an example, I would get a ProgrammingError, saying that content on polls didn't exist: Programming Error Bug

  • However, when checking the database, the content field on polls did indeed exist: Database Existing Fields

  • The solution ultimately was to either reset the database on Elephant SQL or delete it entirely, create a new instance and connect it up to the API via env.py and Heroku config vars. Followed by migrating all the models again, and deploying to Heroku.

  • This re-ocurring issue caused a lot of time to be wasted both on having to reset the database and recreate the lost data.

Known Bugs

Default Image Bug

  • When creating an event there is an error on the front-end regarding the default image. When a user tries to create an event but doesn't upload an image, the default image specified on the back-end should apply. However, the form throws an error: Default Image Bug Front End

  • However, this error doesn't occur on the back-end and the default image is applied without issue: Default Image Bug Back End

  • Despite using the identical code as on the Moments Walkthrough on posts, checking that Cloudinary was connected up properly, searching on Google and Slack, and asking tutor support, no solution was found.

  • The workaround was to include an image required info text on the form to ensure users would always select an image.

Poll and Discussion Bug

  • A poll and discussion model were created on the back-end to be used with events. Though the back-end functionality exists and doesn't cause any issues, the front-end functionality was impossible to implement. My assumption was that the choice fields on polls was causing an issue and that my front-end code was not correct. However, when implementing the discussion on events, which is identical to comments on posts, the same error appeared and nothing could be done about it.

  • Recurring front-end TypeError: Poll Bug Error

  • Front-end displaying data correctly when created in the back-end: Poll Bug Back End Data

  • Ability to create the data in the back-end: Poll Bug Back End Functionality

  • Ultimately the poll and discussion functionality was therefore removed.

Deployment

Heroku

  1. Navigate to your Heroku dashboard
  2. Click "New" and select "Create new app".
    New heroku
  3. Input a meaningful name for your app and choose the region best suited to your location.
    Create new app
  4. Select "Settings" from the tabs.
    Settings tab
  5. Click "Reveal Config Vars".
    Config vars button
  6. Input all key-value pairs as necessary from the .env file. Ensure DEBUG and DEVELOPMENT are not included. Config vars
  7. Click "Add buildpack".
    Add buildpack
  8. Add "python" from the list or search if necessary, remember to click save.
    Select buildpacks
  9. Select "Deploy" from the tabs.
    Settings tab
  10. Select "GitHub - Connect to GitHub" from deployment methods.
    Select GitHub
  11. Click "Connect to GitHub" in the created section.
    Connect to GitHub
  12. Search for the GitHub repository by name.
  13. Click to connect to the relevant repo.
  14. Either click Enable Automatic Deploys for automatic deploys or Deploy Branch to deploy manually. Manually deployed branches will need re-deploying each time the repo is updated.
    Heroku deploy branch
  15. Click View to view the deployed site.
    Heroku view
  16. The live site can also be accessed from your repo in GitHub from the environments section of the repo.

The site is now live and operational

Credits

Code

Content

  • The Deployment section in the README was taken from the masterful Dave Horrocks, who put it so much better than I could!

Acknowledgements

Massive thanks to:

About

Portfolio Project 5 for the Code Institute Full-Stack Software Development Course: Advanced Frontend (React JS)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors