Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for featured artworks #1

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

jonallured
Copy link
Owner

This PR is meant to simulate what happens on software projects: things change and new features are added. In this case the idea is that we're going to add a boolean to Artwork called featured and use that to sort featured artworks to the top of our list endpoint. Our requirements include that only admins should be able to set this field and thus it should not be allowed to be set from the API.

In order to do this we start by adding a sort by newest first. Then we add the new property and then update the sort to prioritize featured artworks.

GET /api/using_grape/artworks

[
  { "title": "oldest artwork", "featured": true, "created_at": "2020-01-01 BLAH" },
  { "title": "newest artwork", "featured": false, "created_at": "2024-03-07 BLAH" },
  { "title": "middle artwork", "featured": false, "created_at": "2024-01-01 BLAH" }
]

Here oldest artwork comes first because it's featured and then the next two follow from that sorted by newest first.

The final two commits are adding tests that assert about whether this new field can be set via the API. The ones for Grape fail and demonstrate how it is weak on mass assignment protections by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant