-
Notifications
You must be signed in to change notification settings - Fork 1
add sort parameter to getJobs endpoint #51
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
Conversation
7eab30c to
f8af1d4
Compare
domain/sort.go
Outdated
| package domain | ||
|
|
||
| // Field represents what you are sorting by | ||
| type Field string | ||
|
|
||
| // Direction represents in which order are you sorting by | ||
| type Direction string | ||
|
|
||
| const ( | ||
| // FieldJobNumber indicates to sort via job number | ||
| FieldJobNumber Field = "job_number" | ||
| // FieldLabel indicates to sort via label | ||
| FieldLabel Field = "label" | ||
| // DirectionAsc indicates to sort in ascending order | ||
| DirectionAsc Direction = "asc" | ||
| // DirectionDesc indicates to sort in descending order | ||
| DirectionDesc Direction = "desc" | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer all of this in the api/parameters file.
api/jobs.go
Outdated
| sortParam := r.URL.Query()["sort"] | ||
| // default direction is descending | ||
| direction := domain.Direction("desc") | ||
| field := domain.Field("job_number") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would prefer these as consts as otherwise you're still using magic strings.
api/jobs.go
Outdated
| for _, s := range sortParam { | ||
| for _, p := range strings.Split(s, ",") { | ||
| part := strings.TrimSpace(p) | ||
| parts := strings.Split(part, ":") | ||
|
|
||
| field = domain.Field(strings.TrimSpace(parts[0])) | ||
| direction = domain.Direction(strings.TrimSpace(parts[1])) | ||
|
|
||
| if !domain.IsValidField(field) { | ||
| return nil, 0, appErrors.ErrSortFieldInvalid | ||
| } | ||
|
|
||
| if !domain.IsValidDirection(direction) { | ||
| return nil, 0, appErrors.ErrSortDirectionInvalid | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would recommend abstracting this as a function.
mongo/job_store.go
Outdated
| } | ||
|
|
||
| // default to field being job_number | ||
| sortField := "job_number" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no magic strings.
mongo/job_store.go
Outdated
| // default to field being job_number | ||
| sortField := "job_number" | ||
| if field == domain.FieldLabel { | ||
| sortField = "label" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no magic strings.
af8f9f1 to
6155316
Compare
6155316 to
57d6b1b
Compare
lindenmckenzie
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure the structuring is quite right here (blaming on my own feedback) but equally it's not so problematic that I think this PR should be held up anymore. We'll take forward as it is and refactor as necessary if it becomes necessary.
What
Add sort parameter to getJobs endpoint
Sort by:
Order by:
How to review
Sense check
Ensure tests pass
Ensure everything is okay/in place
Who can review
Not me.