Skip to content

Conversation

@aqdas0307
Copy link
Contributor

What

Add sort parameter to getJobs endpoint

Sort by:

Order by:

  • ascending
  • descending

How to review

Sense check
Ensure tests pass
Ensure everything is okay/in place

Who can review

Not me.

@aqdas0307 aqdas0307 requested a review from a team as a code owner January 14, 2026 15:36
@aqdas0307 aqdas0307 force-pushed the feature/add-sorting-parameter-get-job branch 3 times, most recently from 7eab30c to f8af1d4 Compare January 15, 2026 14:14
domain/sort.go Outdated
Comment on lines 1 to 18
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"
)
Copy link
Contributor

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
Comment on lines 70 to 73
sortParam := r.URL.Query()["sort"]
// default direction is descending
direction := domain.Direction("desc")
field := domain.Field("job_number")
Copy link
Contributor

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
Comment on lines 75 to 91
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
}
}
}
Copy link
Contributor

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.

}

// default to field being job_number
sortField := "job_number"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no magic strings.

// default to field being job_number
sortField := "job_number"
if field == domain.FieldLabel {
sortField = "label"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no magic strings.

@aqdas0307 aqdas0307 force-pushed the feature/add-sorting-parameter-get-job branch 5 times, most recently from af8f9f1 to 6155316 Compare January 22, 2026 15:45
@aqdas0307 aqdas0307 force-pushed the feature/add-sorting-parameter-get-job branch from 6155316 to 57d6b1b Compare January 22, 2026 16:36
Copy link
Contributor

@lindenmckenzie lindenmckenzie left a 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.

@aqdas0307 aqdas0307 merged commit 57d6b1b into main Jan 23, 2026
17 of 18 checks passed
@aqdas0307 aqdas0307 deleted the feature/add-sorting-parameter-get-job branch January 23, 2026 10:09
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.

3 participants