Momentum logo
Team 13 Classroom

๐Ÿป Search & Automatic Deploys ๐Ÿป

Posted on Aug 1st, 2022

Todayโ€™s Topics

  • Implementing search, including Postgres full-text search

๐ŸŽฏ Project due on Thursday afternoon

Please include a README in your project repo. The README should be:

  • written in Markdown
  • include a link to your production application
  • shave instructions for getting your application running locally, so that any developer could pull it down and run it. If your setup makes any assumptions about the environment (e.g., you have Python 3.10.2 installed locally), you should state them in the README.

Your README should include documentation for your APIโ€™s available endpoints.

๐Ÿ‘‰ If your project meets minimum requirements today, HUZZAH! That is awesome. You should be working on at least one additional or spicy feature.

๐Ÿ‘‰ If your project does not yet meet minimum requirements, you should aim for meeting them by the end of the day Wednesday.

Note

Depending on how youโ€™ve constructed your API, you might have separate endpoints for all of the below, or you might have fewer endpoints (for instance, if you nested answers in the question detail endpoint, like questions/4/answers). What matters is that you have endpoints that your front-end team can use to perform all the necessary actions they need and that are documented in your README.

Requirements for QuestionBox, Back End

โš ๏ธ Be sure to test that you have implemented permissions-checking correctly for these endpoints. For example, your API should not allow a user who is not the question-asker to mark an answer as accepted.

  • token login, logout, and register (i.e., create a new user)
  • list all questions
  • list answers to a specific question
  • show details about a specific question
  • create a question if logged in
  • create an answer to a question (if you are not the question owner) if logged in
  • mark an answer as โ€œacceptedโ€ (if you are the question owner)
  • list of own questions for an authenticated user
  • list of own answers for an authenticated user
  • star/favorite questions or answers
  • unstar/unfavorite questions or answers
  • search questions (possibly both questions and answers)
  • A README with endpoints documented

Requirements for Social Cards, Back End

โš ๏ธ Be sure to test that you have implemented permissions-checking correctly for these endpoints. For example, your API should not allow a user who is not the creator of a card to update a card.

  • token login, logout, and register (i.e., create a new user)
  • list all cards
  • list all cards youโ€™ve created (you, the logged in user)
  • list all cards that a user you follow has created
  • show details of one card
  • create a new card
  • update a card
  • delete a card
  • follow another user
  • unfollow another user
  • list all the users you follow
  • A README with endpoints documented

๐Ÿ“– Read | ๐Ÿ“บ Watch | ๐ŸŽง Listen

๐Ÿ”– Resources

@action decorator in ViewSets

๐Ÿฆ‰ Code & Notes

  • DRF Library API
  • Notes on Django Queries These are the same notes you may have seen at the beginning of the Phase. Iโ€™m including them here for easy reference, as they show examples of queries and filters that might come in handy for search endpoints.

๐ŸฆŠ URL Routing in React ๐ŸฆŠ

Posted on Jul 29th, 2022

Todayโ€™s topics

  • Review Login and add Logout
  • Using local storage with state to store an auth token
  • React Router

๐ŸŽฏ Project

You should have detailed wireframes and a user flow outline, and components for at least the initial โ€œpageโ€ your user is going to see when they arrive at your site. By today, you should be able to make GET requests for questions and their answers (if you are working on Questionbox) or for cards (if you are working on Social E-Cards).

Deploy to Netlify today if you havenโ€™t already!

๐Ÿ“– Read | ๐Ÿ“บ Watch | ๐ŸŽง Listen

โš ๏ธ These two resources are for older versions of React Router, so you will see some outdated syntax. For instance Switch, Redirect, and the component prop on Route exist only in versions of React Router earlier than version 6. However, the main concepts are the same, so these resources can still help you understand the context and usage of React Router.

๐Ÿ”– Resources

๐Ÿ‘พ Code

๐Ÿป File Upload with Django and DRF ๐Ÿป

Posted on Jul 28th, 2022

๐Ÿ—“๏ธ Todayโ€™s Topics

  • How are the projects coming along? ๐Ÿ‘€
  • Letting users upload files/images using AWS S3

๐ŸŽฏ Project

Keep on going. ๐Ÿ’ช ๐Ÿš€

Today letโ€™s get you past any blockers you may be experiencing and talk through next steps.

By now you should have provided your front end with a way to log in and log out, and endpoints to see at least some data. You can create some data via the Django admin so that you can see your GET requests working. By tomorrow you should be able to create (at least some)resources via POST requests.

๐Ÿ“– Read | ๐Ÿ“บ Watch | ๐ŸŽง Listen

File Upload

On Monday weโ€™ll be covering full-text search in your API, but if you have time you can check these resources out in advance.

๐Ÿ”– Resources

File uploads

A request with a file attachment using Insomnia

  • Select the right HTTP method for your endpoint.
  • Choose binary file attachment from the JSON menu (where you normally put the body of a request)
  • Set headers on the Headers tab (this example assumes an image file in jpeg format, named profile-photo.jpg):

    Content-Type: image/jpeg
    Content-Disposition: attachment; filename=profile-photo.jpg
    

For more information on the values for Content-Type:

CORS for file upload

Assuming you are using django-cors-headers, youโ€™ll need to add the following to settings.py to allow the request headers necessary for file attachments:

# in settings.py

from corsheaders.defaults import default_headers

CORS_ALLOW_HEADERS = list(default_headers) + [
    'content-disposition',
]

Authentication

Make sure you are sharing the Djoser information with your front end. You should include the authentication endpoints in your API documentation or project README.

Creating a properly hashed password

In order to save a properly hashed password when you create a new user in the Django Admin, make sure you are using UserAdmin in admin.py so that you have that option in the admin interface. If you donโ€™t do this and save an unhashed password, you will run into authentication errors.

from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
...
admin.site.register(User, UserAdmin)

You can also change a password from the command line:

๐Ÿ‘พ Code

๐ŸฆŠ Authentication in a React App ๐ŸฆŠ

Posted on Jul 26th, 2022

๐Ÿ—“๏ธ Todayโ€™s topics

  • Using Forms in React
  • Revisit โ€œWhat is logged in?โ€ in code
  • Requesting an auth token for login

๐ŸŽฏ Project

Work with your team to get the initial components in place for the QuestionBox or Social E-cards project.

By Friday

  • be able to make GET requests for questions and answers / cards and friends
  • show them on the page
  • have a solid start on POST requests
  • deploy to Netlify as soon as possible (TIP โญ Your code needs to run locally with no errors before you can deploy it!)

๐Ÿ”– Resources