Momentum logo
Team 14 Classroom

🐻 Full-text Search & File Upload 🐻

Posted on Sep 26th, 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 your production application’s URL
  • have 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 clear 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.

Requirements for QuestionBox, Back End

Note: Depending on how you’ve constructed your API, you might have separate endpoints for all of the below, or some of the functionality might be combined in a single endpoint (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.

⚠️ 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 authenticated)
  • create an answer to a question (if authenticated and if you are not the question asker)
  • mark an answer as “accepted” (if you are the question asker)
  • 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 authenticated user)
  • list all cards created by a user that you follow
  • show details of one card
  • create a new card (if authenticated)
  • update a card (if authenticated and it’s your card)
  • delete a card (if authenticated and it’s your card)
  • follow another user (if authenticated)
  • unfollow another user (if authenticated)
  • list all the users you follow
  • A README with endpoints documented

Handling requests that include attached files

Using Insomnia

  • Select the right HTTP method for your endpoint.
  • Choose binary file attachment from the body 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',
]

📖 Read | 📺 Watch | 🎧 Listen

File Upload

🔖 Resources

📁 Creating a README

@action decorator in ViewSets

File uploads

👾 Code & Notes

🦊 URL Routing in React 🦊

Posted on Sep 22nd, 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

🐻 API Progress Check-In 🐻

Posted on Sep 22nd, 2022

🗓️ Today’s Topics

  • How are the projects coming along? 👀
  • Automatic deploys from GitHub
  • Paginating your API

🎯 Project

Keep on going. 💪 🚀

We will use class time today to get you past any blockers you may be experiencing and to talk through next steps.

By now you should have provided your front end with endpoints to see data and gotten djoser installed so that your log in and log out endpoints are working.

By tomorrow you should have the ability to create at least questions or cards via POST requests, and maybe more.

📖 Read | 📺 Watch | 🎧 Listen

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

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:

Pagination

🦊 Authentication in a React App 🦊

Posted on Sep 20th, 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.

Optional prep for Thursday

On Thursday we’ll be covering a way to add routing to our application with ReactRouter. If you want to get a head start, there’s a brand new React Router tutorial.

By Friday

  • Your app can make GET requests for questions and answers OR cards and friends
  • Show questions or cards on the page
  • Have a solid start on POST requests for creating questions or cards
  • Deploy to Netlify as soon as possible (TIP ⭐ Your code needs to run locally with no errors before you can deploy it!)

🔖 Resources

##