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

Create Category Endpoint #259

Open
Tracked by #258
TheTedder opened this issue Jan 4, 2025 · 1 comment · May be fixed by #266
Open
Tracked by #258

Create Category Endpoint #259

TheTedder opened this issue Jan 4, 2025 · 1 comment · May be fixed by #266
Assignees
Labels
enhancement New feature or request high priority

Comments

@TheTedder
Copy link
Contributor

TheTedder commented Jan 4, 2025

POST /leaderboard/{id}/categories/create.

The request body must include the following fields:

  • Name: string
  • Slug: string
  • Info: string?
  • SortDirection: 'Ascending' | 'Descending'
  • RunType: 'Time' | 'Score'

If the client is not authenticated, the server must return a 401 error .

If the current user's role is not ADMIN, the server must return a 403 error.

If the specified ID does not correspond to a leaderboard in the database, the server must return a 404 error.

If the leaderboard identified by the specified ID already contains a non-deleted category with the specified slug, the server must return a 409 error and return the conflicting category in the response body.

If any of the following conditions are met, the server must return a 422 error.

  • Slug is not between 2 and 80 characters inclusive.
  • Slug is not comprised solely of alphanumeric digits, hyphens, and underscores.
  • Name is absent or null.
  • Slug is absent or null.
  • SortDirection is absent or an invalid value.
  • RunType is absent or an invalid value.

Upon successful category creation, the server must return a 201 CREATED status with a response body that includes the newly-created category as well as its location on the server.

@TheTedder TheTedder added enhancement New feature or request high priority labels Jan 4, 2025
@zysim zysim self-assigned this Jan 6, 2025
@zysim
Copy link
Collaborator

zysim commented Jan 6, 2025

SortDirection and RunType validation's a little weird to implement. To obey the rules we've set; we need to add a FluentValidation rule to catch absent cases, and the best candidate is the NotEmpty() method (otherwise; an absent field will trigger a 400, instead). However; that method also triggers for default values, and both SortDirection and RunType's enums start from the default enum value. In other words; submitting a valid request can still trigger a validation error. So we've got three choices:

  1. Create a custom validation rule (frankly don't know how to do this)
  2. Make the fields in the request body nullable (ew)

Not sure what to go for here. What do you think?

Also; how do we want to represent the cat's location on the server? The CategoryViewModel returns its ID and slug; admins should already know the path for it, as well. Do we want to return a field for a cat's full qualified path? I don't think that's necessary, right?

@zysim zysim linked a pull request Jan 6, 2025 that will close this issue
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request high priority
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants