adapter-priority
Priority: adapter-provided values and comparator helpers
Overview
Project.Priority is intentionally a free-form string. Upstream systems use
different vocabularies for priority (for example: P1, critical, high,
1, urgent), so adapters should map their upstream priority into a meaningful
string for the normalized model and not attempt to coerce into a single
repo-wide enum.
The generic in-memory adapter treats the Priority value as opaque for
filtering and will use lexicographic ordering by default when sorting by
sort=priority.
Comparator helpers
The internal/adapter/memory package exposes small helpers to make it easy to
install a semantic ordering for priority values.
SemanticPriorityComparator(order []string) func(a,b string) bool- Returns a comparator that orders priorities according to
order. The first element is considered highest priority. Unknown values are considered lower priority than any known value.
- Returns a comparator that orders priorities according to
DefaultPriorityOrderandDefaultSemanticPriorityComparator- A common ordering:
critical, high, medium, low.
- A common ordering:
InstallDefaultPriorityComparator()- Convenience function that sets the package-wide comparator to the default semantic ordering.
SetPriorityComparator(cmp func(a,b string) bool)- Set the package-wide comparator to a custom function. Passing
nilrestores default lexicographic behavior.
- Set the package-wide comparator to a custom function. Passing
How adapters should use priority
- Map upstream priority to a stable, human-meaningful string when building
the normalized
model.Project(for example:critical,high,low, or an upstream raw value likeP1). - If you want semantic sorting across projects from multiple upstream
systems, either call
InstallDefaultPriorityComparator()at startup or supply your own ordering viaSetPriorityComparator(SemanticPriorityComparator(...)).
Example
In your adapter or server initialization code:
Notes and edge-cases
- Unknown or adapter-specific priority values sort after known values when using the semantic comparator. If you need a different policy for unknown values, provide a custom comparator.
SetPriorityComparator(nil)restores the default lexicographic ordering.- The comparator is package-global (process-wide). If you run multiple adapters with different desired orderings in the same process, install the comparator that makes sense for your global view or provide adapter-specific sorting in handlers instead of relying on the package-wide comparator.
Troubleshooting
- If sorting by priority gives an unexpected order, print the
Project.Priorityvalues of the returned projects to check mapping consistency across adapters.
API: /statuses
The example server exposes a convenience endpoint to list known project status strings discovered in the adapter’s current in-memory store.
- GET /statuses
- Response: 200 OK
- Body: JSON object with
statusesarray, e.g.{ "statuses": ["active", "planned"] }
This endpoint is meant to help frontends discover the set of status values returned by upstream adapters. The order is the sequence in which the values were first encountered in the adapter’s dataset. If you need a canonical ordering, sort the array on the client or request an API change.
API: /priorities
The example server exposes a convenience endpoint to list known project priority strings discovered in the adapter’s current in-memory store.
- GET /priorities
- Response: 200 OK
- Body: JSON object with
prioritiesarray, e.g.{ "priorities": ["critical", "high", "medium"] }
Like /statuses, the order is the sequence in which priority values were
first encountered. Clients should sort or apply semantic comparators as needed.
Examples
Use these examples against the example service started from cmd/exampleservice.
Query projects with a single priority:
Query projects with multiple priorities (OR semantics):
Discover available priorities and statuses:
Note: use jq to pretty-print JSON; these commands assume the example server is
running on port 8080.
Multi-field examples
Filter by a single status:
Filter by multiple statuses (OR semantics within the field):
Filter by a single person (team member):
Filter by multiple persons (OR semantics within the field):
Combine fields (AND across different fields). For example, projects that are
either active or planned and have priority high or critical:
Semantics:
- Multiple values in a single query parameter (comma-separated) are treated as
OR (match any). For example,
status=active,plannedreturns projects whose status is eitheractiveorplanned. - Different query parameters combine with AND. For example,
status=active&person_id=person-1returns projects that areactiveand haveperson-1on the team.