Skip to content

(Task 2) Feature: order races by advertised start time - #2

Open
Cuttsy27 wants to merge 3 commits into
feature/filter-races-by-visibilityfrom
feature/order-races-by-advertised-start-time
Open

(Task 2) Feature: order races by advertised start time#2
Cuttsy27 wants to merge 3 commits into
feature/filter-races-by-visibilityfrom
feature/order-races-by-advertised-start-time

Conversation

@Cuttsy27

@Cuttsy27 Cuttsy27 commented Aug 2, 2025

Copy link
Copy Markdown
Owner

Changes

  • added order_by string property to ListRacesRequest message
  • added applyOrderBy method to the races repo
  • added utils.Contains to test if a given string exists in a slice of strings
  • added tests for applyOrderBy method
  • added tests for ordering to the racing service

Summary

A new order_by string property should be added to the ListRacesRequest protobuf message, which can be used by the application to determine if any sorting should be done to races before returning them to the client.
According to Google AIP 132, ordering should be specified by a comma-separated list of properties to order by, optionally followed by the direction e.g. "advertised_start_time desc, name". Ascending should be the default order and can be omitted from the string.
Races are ordered by advertised_start_time in ascending order by default, even when no order_by is specified.

To check the provided order_by string for valid properties to order by, we split the string by comma into a slice. A Contains utility function was added to the codebase to help test if a given string exists in a slice of strings. We use this to compare each property in the order_by string to a predetermined list of valid fields. If the order_by property is not a valid field, we ignore it.

Example

curl -X "POST" "http://localhost:8000/v1/list-races" \
    -H 'Content-Type: application/json' \
    -d $'{
        "order_by": "advertised_start_time desc"
    }'

Tests

  • We test the new Contains function for 100% coverage.
  • We test the applyOrderBy method for 100% coverage.
  • We test the racing service by mocking the race repo to ensure the service handles sorted data as expected.

…o pass order-by string to request. added applyOrder method to races repo
…od. added tests for applyOrderBy. added ordering tests for racing service
@Cuttsy27 Cuttsy27 changed the title Feature: order races by advertised start time (Task 2) Feature: order races by advertised start time Aug 4, 2025
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