0x213F / jukebox-radio-django

Part Jukebox. Part Radio.
Other
1 stars 0 forks source link

Add "name" to marker #72

Closed 0x213F closed 3 years ago

0x213F commented 3 years ago

Summary

As per the new spec, when a user creates a marker on a track, they should be able to name that marker.

Definition of "marker."

Screen Shot 2021-03-29 at 4 31 22 PM

The back-end must support this change by updating:

  1. The model (jukebox_radio.streams.models.marker)
  2. The API (jukebox_radio.streams.views.marker.create_view)
  3. The test (jukebox_radio.streams.tests.views.marker.test_create_view)

1. The model

The Marker model (inside the streams app) needs to be modified. A new field needs to be added:

name = models.CharField(max_length=32)

After adding the new field, you will have to makemigrations. To do this, go to the terminal and run:

docker-compose -f local.yml run --rm django python manage.py makemigrations

Now since the field you added requires a value for all Marker entries, and there are existing Marker entries, all existing entries will have to be backfilled with a default value. As such, you will want to set the default for existing values as the following string: "Default".

2. The API

All the changes for the API will be made inside jukebox_radio.streams.models.marker.

The application will send the backend a new parameter: name. The code should read this value and then make sure to pass it inside Marker.objects.create(... name=name) so that the name is actually saved in the database.

2. The test

Try running this in the terminal:

docker-compose -f local.yml run --rm django pytest

You'll notice that it fails - which is good! If you are wondering why this is good, let me know and I can further explain.

So, you're going to want to open up the test that is failing and fix it. To do this, you will need to add to data a test name. You also will want to add 2 assertions to the bottom of the test: one to verify the behavior for the API response, and one to verify the DB state.

0x213F commented 3 years ago

One more thing: the serialize method for Marker will need to be updated.

0x213F commented 3 years ago

@Avillameza, reassigning to @fpjhannan since she completed the ticket.