Skip to content

Gears API reference

Gears

Gear API router endpoints.

create_gear

create_gear(request, gear, token_user_id, db, response)

Create a gear for the authenticated user; Location names where it is read.

Source code in backend/app/modules/gears/gear/router.py
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
@router.post(
    "",
    response_model=gears_schema.GearRead,
    status_code=status.HTTP_201_CREATED,
    dependencies=[Security(auth_dependencies.check_scopes, scopes=["gears:write"])],
)
@core_rate_limit.limiter.limit(core_rate_limit.WRITE)
def create_gear(
    request: Request,
    gear: gears_schema.GearCreateRequest,
    token_user_id: auth_dependencies.CurrentUserId,
    db: core_dependencies.DbSession,
    response: Response,
) -> gears_schema.GearRead:
    """Create a gear for the authenticated user; ``Location`` names where it is read."""
    created = gears_service.create_gear(gear, token_user_id, db)
    core_location.set_location(response, request, "read_gear_id", gear_id=created.id)
    core_etag.set_etag(response, created.version)
    return created

delete_gear

delete_gear(request, response, gear_id, token_user_id, if_match, states, db)

Queue the deletion of one of the authenticated user's gears.

Send If-Match with the gear's version as an ETag; a stale tag is refused with 412 before anything is queued. The gear is unassigned from its activities in the background, so the response is 202 with a job: poll GET /jobs/{job_id} until it succeeds. The gear stays readable until then. A second delete while one is pending is refused with 409.

Source code in backend/app/modules/gears/gear/router.py
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
@router.delete(
    "/{gear_id}",
    response_model=gears_schema.GearDeletionStatus,
    status_code=status.HTTP_202_ACCEPTED,
    responses=core_location.ACCEPTED_RESPONSE,
    dependencies=[Security(auth_dependencies.check_scopes, scopes=["gears:write"])],
)
@core_rate_limit.limiter.limit(core_rate_limit.WRITE)
def delete_gear(
    request: Request,
    response: Response,
    gear_id: core_dependencies.UuidId,
    token_user_id: auth_dependencies.CurrentUserId,
    if_match: core_dependencies.IfMatch,
    states: gears_dependencies.GearDeletionStateStoreDep,
    db: core_dependencies.DbSession,
) -> gears_schema.GearDeletionStatus:
    """Queue the deletion of one of the authenticated user's gears.

    Send ``If-Match`` with the gear's ``version`` as an ETag; a stale tag is refused with 412 before anything is
    queued. The gear is unassigned from its activities in the background, so the response is ``202`` with a job:
    poll ``GET /jobs/{job_id}`` until it succeeds. The gear stays readable until then. A second delete while
    one is pending is refused with 409.
    """
    deletion = gears_deletion_job_service.request_gear_deletion(gear_id, token_user_id, states, db, if_match=if_match)
    core_location.set_job_location(response, request, deletion.id, gears_constants.DELETION_POLL_SECONDS)
    return deletion

edit_gear

edit_gear(request, gear_id, gear, token_user_id, db, response, if_match)

Update one of the authenticated user's gears.

Applies a partial update: omit a field to leave it untouched and send an explicit null to clear a nullable one (brand, model, purchase_value).

Send If-Match with the gear's version as an ETag to make the write conditional; a stale tag is refused with 412. Changing gear_type is refused with 409 while the gear has components that are not valid for the new type; remove them first.

Source code in backend/app/modules/gears/gear/router.py
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
@router.patch(
    "/{gear_id}",
    response_model=gears_schema.GearRead,
    dependencies=[Security(auth_dependencies.check_scopes, scopes=["gears:write"])],
)
@core_rate_limit.limiter.limit(core_rate_limit.WRITE)
def edit_gear(
    request: Request,
    gear_id: core_dependencies.UuidId,
    gear: gears_schema.GearUpdate,
    token_user_id: auth_dependencies.CurrentUserId,
    db: core_dependencies.DbSession,
    response: Response,
    if_match: core_dependencies.IfMatch,
) -> gears_schema.GearRead:
    """Update one of the authenticated user's gears.

    Applies a partial update: omit a field to leave it untouched and send an explicit
    null to clear a nullable one (`brand`, `model`, `purchase_value`).

    Send ``If-Match`` with the gear's ``version`` as an ETag to make the write
    conditional; a stale tag is refused with 412. Changing `gear_type` is refused with 409
    while the gear has components that are not valid for the new type; remove them first.
    """
    updated = gears_service.edit_gear(gear_id, gear, token_user_id, db, if_match=if_match)
    core_etag.set_etag(response, updated.version)
    return updated

list_gears

list_gears(token_user_id, db, page, active=None, gear_type=None, nickname_contains=None)

Retrieve one page of the authenticated user's gears, with the matching total.

Source code in backend/app/modules/gears/gear/router.py
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
@router.get(
    "",
    response_model=core_pagination.Page[gears_schema.GearRead],
    dependencies=[Security(auth_dependencies.check_scopes, scopes=["gears:read"])],
)
def list_gears(
    token_user_id: auth_dependencies.CurrentUserId,
    db: core_dependencies.DbSession,
    page: core_pagination.ListPage,
    active: Annotated[bool | None, Query(description="Keep only active (true) or inactive (false) gears")] = None,
    gear_type: Annotated[gears_schema.GearType | None, Query(description="Keep only gears of this type")] = None,
    nickname_contains: Annotated[
        str | None,
        Query(min_length=1, max_length=250, description="Keep only gears whose nickname contains this text"),
    ] = None,
) -> core_pagination.Page[gears_schema.GearRead]:
    """Retrieve one page of the authenticated user's gears, with the matching total."""
    return gears_service.list_gears(
        token_user_id,
        db,
        page_number=page.page_number,
        num_records=page.num_records,
        active=active,
        gear_type=gear_type,
        nickname_contains=nickname_contains,
    )

read_gear_id

read_gear_id(gear_id, token_user_id, db, response)

Retrieve a gear by ID with its total distance, time and components cost.

Source code in backend/app/modules/gears/gear/router.py
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
@router.get(
    "/{gear_id}",
    response_model=gears_schema.GearDetailRead,
    dependencies=[Security(auth_dependencies.check_scopes, scopes=["gears:read"])],
)
def read_gear_id(
    gear_id: core_dependencies.UuidId,
    token_user_id: auth_dependencies.CurrentUserId,
    db: core_dependencies.DbSession,
    response: Response,
) -> gears_schema.GearDetailRead:
    """Retrieve a gear by ID with its total distance, time and components cost."""
    gear = gears_service.read_gear_detail(gear_id, token_user_id, db)
    # The tag the client echoes back in If-Match when it later saves.
    core_etag.set_etag(response, gear.version)
    return gear

Gear schema definitions.

GearBase

Bases: BaseModel

Fields a client may set on a gear.

Attributes:

Name Type Description
brand StrictStr | None

Gear brand name.

model StrictStr | None

Gear model name.

nickname StrictStr | None

Gear display nickname.

gear_type StrictStr | None

Gear type identifier.

acquired_on date | None

Date the user acquired the gear; today when a gear is created without one.

active StrictBool | None

Whether the gear is active.

initial_distance StrictFloat | None

Distance the gear had before it was tracked, in meters.

purchase_value Money | None

Purchase price as a decimal string in the owner's currency.

Source code in backend/app/modules/gears/gear/schema.py
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
class GearBase(BaseModel):
    """Fields a client may set on a gear.

    Attributes:
        brand: Gear brand name.
        model: Gear model name.
        nickname: Gear display nickname.
        gear_type: Gear type identifier.
        acquired_on: Date the user acquired the gear; today when a gear is created without one.
        active: Whether the gear is active.
        initial_distance: Distance the gear had before it was tracked, in meters.
        purchase_value: Purchase price as a decimal string in the owner's currency.
    """

    brand: StrictStr | None = Field(
        default=None,
        max_length=250,
        description="Gear brand name",
    )
    model: StrictStr | None = Field(
        default=None,
        max_length=250,
        description="Gear model name",
    )
    acquired_on: date | None = Field(
        default=None,
        description="Date the user acquired the gear",
    )
    active: StrictBool | None = Field(
        default=None,
        description="Whether the gear is active",
    )
    initial_distance: StrictFloat | None = Field(
        default=None,
        ge=0,
        le=MAX_INITIAL_DISTANCE,
        description="Distance the gear had before it was tracked, in meters, the unit of total_distance",
    )
    purchase_value: core_types.Money | None = Field(
        default=None,
        description=(
            "Purchase price as a decimal string with two decimals, in the owner's currency "
            "(the `currency` user setting), such as 129.90"
        ),
    )

    model_config = ConfigDict(
        from_attributes=True,
        extra="forbid",
        validate_assignment=True,
    )

GearCreate

Bases: GearStored

A gear to create, as built by the provider syncs and the profile import.

Attributes:

Name Type Description
user_id UUID | None

Foreign key to user; ignored on write, the owner is passed explicitly.

Source code in backend/app/modules/gears/gear/schema.py
198
199
200
201
202
203
204
205
206
207
208
class GearCreate(GearStored):
    """A gear to create, as built by the provider syncs and the profile import.

    Attributes:
        user_id: Foreign key to user; ignored on write, the owner is passed explicitly.
    """

    user_id: uuid.UUID | None = Field(
        default=None,
        description="Foreign key to user",
    )

GearCreateRequest

Bases: GearBase

Request body for creating a gear.

Provider gear IDs are not accepted: only the Strava and Garmin Connect syncs and the profile import set them, so a client cannot forge a provider link.

Source code in backend/app/modules/gears/gear/schema.py
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
class GearCreateRequest(GearBase):
    """Request body for creating a gear.

    Provider gear IDs are not accepted: only the Strava and Garmin Connect syncs and
    the profile import set them, so a client cannot forge a provider link.
    """

    nickname: RequiredNickname = Field(
        ...,
        max_length=250,
        description="Gear display nickname",
    )
    gear_type: GearType = Field(
        ...,
        description="Gear type identifier",
    )
    acquired_on: core_types.RecordDate | None = Field(
        default=None,
        description="Date the user acquired the gear",
    )

GearDeletionStatus

Bases: JobStatusOpenFailure

Where a queued gear deletion is.

Source code in backend/app/modules/gears/gear/schema.py
292
293
294
295
class GearDeletionStatus(core_job_status.JobStatusOpenFailure):
    """Where a queued gear deletion is."""

    kind: Literal["gear_deletion"]

GearDetailRead

Bases: GearRead

Extended gear with computed stats.

Attributes:

Name Type Description
total_distance StrictFloat

Total distance (m).

total_time StrictFloat

Total time (seconds).

total_components_cost MoneyTotal

Sum of the component purchase values as a decimal string in the owner's currency.

Source code in backend/app/modules/gears/gear/schema.py
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
class GearDetailRead(GearRead):
    """Extended gear with computed stats.

    Attributes:
        total_distance: Total distance (m).
        total_time: Total time (seconds).
        total_components_cost: Sum of the component purchase values as a decimal string in the owner's currency.
    """

    total_distance: StrictFloat = Field(
        default=0,
        ge=0,
        description=("Total activity distance in meters"),
    )
    total_time: StrictFloat = Field(
        default=0,
        ge=0,
        description=("Total activity time in seconds"),
    )
    total_components_cost: core_types.MoneyTotal = Field(
        default="0.00",
        description=(
            "Sum of the component purchase values as a decimal string with two decimals, in the owner's "
            "currency (the `currency` user setting)"
        ),
    )

GearRead

Bases: GearStored

Schema for reading a gear record.

Attributes:

Name Type Description
id UUID

Unique identifier.

user_id UUID

Foreign key to user.

version StrictInt

Optimistic-concurrency counter, also sent as the ETag.

updated_at datetime

When the gear last changed; set by the server.

Source code in backend/app/modules/gears/gear/schema.py
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
class GearRead(GearStored):
    """Schema for reading a gear record.

    Attributes:
        id: Unique identifier.
        user_id: Foreign key to user.
        version: Optimistic-concurrency counter, also sent as the ``ETag``.
        updated_at: When the gear last changed; set by the server.
    """

    id: uuid.UUID = Field(
        ...,
        description="Unique identifier",
    )
    user_id: uuid.UUID = Field(
        ...,
        description="Foreign key to user",
    )
    version: StrictInt = Field(
        default=1,
        ge=1,
        description="Optimistic-concurrency counter",
    )
    updated_at: datetime = Field(
        ...,
        description="When the gear last changed",
    )

GearStored

Bases: GearBase

The fields a stored gear always has: a nickname, a type and the provider gear IDs.

Attributes:

Name Type Description
strava_gear_id StrictStr | None

Strava gear ID.

garminconnect_gear_id StrictStr | None

Garmin Connect gear ID.

Source code in backend/app/modules/gears/gear/schema.py
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
class GearStored(GearBase):
    """The fields a stored gear always has: a nickname, a type and the provider gear IDs.

    Attributes:
        strava_gear_id: Strava gear ID.
        garminconnect_gear_id: Garmin Connect gear ID.
    """

    nickname: StrictStr = Field(
        ...,
        max_length=250,
        description="Gear display nickname",
    )
    gear_type: StoredGearType = Field(
        ...,
        description="Gear type identifier",
    )
    strava_gear_id: StrictStr | None = Field(
        default=None,
        max_length=45,
        description="Strava gear ID",
    )
    garminconnect_gear_id: StrictStr | None = Field(
        default=None,
        max_length=45,
        description="Garmin Connect gear ID",
    )

GearType

Bases: StoredStrEnum

Supported gear types; stored is the integer in gears.gear_type.

Attributes:

Name Type Description
BIKE

Bicycle.

SHOES

Running or walking shoes.

WETSUIT

Wetsuit.

RACQUET

Racquet.

SKI

Skis.

SNOWBOARD

Snowboard.

WINDSURF

Windsurf board.

WATER_SPORTS_BOARD

Water sports board.

Source code in backend/app/modules/gears/gear/schema.py
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
class GearType(StoredStrEnum):
    """Supported gear types; ``stored`` is the integer in ``gears.gear_type``.

    Attributes:
        BIKE: Bicycle.
        SHOES: Running or walking shoes.
        WETSUIT: Wetsuit.
        RACQUET: Racquet.
        SKI: Skis.
        SNOWBOARD: Snowboard.
        WINDSURF: Windsurf board.
        WATER_SPORTS_BOARD: Water sports board.
    """

    BIKE = ("bike", 1)
    SHOES = ("shoes", 2)
    WETSUIT = ("wetsuit", 3)
    RACQUET = ("racquet", 4)
    SKI = ("ski", 5)
    SNOWBOARD = ("snowboard", 6)
    WINDSURF = ("windsurf", 7)
    WATER_SPORTS_BOARD = ("water_sports_board", 8)

GearUpdate

Bases: NotClearable, GearBase

Partial update of a gear: omit a field to keep it, send null to clear a nullable one.

The gear comes from the path; provider gear IDs cannot be changed.

Source code in backend/app/modules/gears/gear/schema.py
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
class GearUpdate(core_partial_update.NotClearable, GearBase):
    """Partial update of a gear: omit a field to keep it, send null to clear a nullable one.

    The gear comes from the path; provider gear IDs cannot be changed.
    """

    not_clearable = ("nickname", "gear_type", "acquired_on", "active", "initial_distance")

    acquired_on: core_types.RecordDate | None = Field(
        default=None,
        description="Date the user acquired the gear",
    )

    nickname: RequiredNickname | None = Field(
        default=None,
        max_length=250,
        description="Gear display nickname",
    )
    gear_type: GearType | None = Field(
        default=None,
        description="Gear type identifier",
    )

normalize_nickname

normalize_nickname(nickname)

Normalize a nickname for case-insensitive comparison.

Parameters:

Name Type Description Default
nickname str

The nickname to compare.

required

Returns:

Type Description
str

The nickname trimmed and lower-cased, as the unique index compares it.

Source code in backend/app/modules/gears/gear/schema.py
78
79
80
81
82
83
84
85
86
87
def normalize_nickname(nickname: str) -> str:
    """Normalize a nickname for case-insensitive comparison.

    Args:
        nickname: The nickname to compare.

    Returns:
        The nickname trimmed and lower-cased, as the unique index compares it.
    """
    return str(nickname).lower().strip()

Gear components

Gear components API router endpoints.

create_gear_component

create_gear_component(request, gear_component, token_user_id, db, response)

Create a component on one of the authenticated user's gears; Location names where it is read.

Source code in backend/app/modules/gears/gear_components/router.py
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
@router.post(
    "",
    response_model=gear_components_schema.GearComponentRead,
    status_code=status.HTTP_201_CREATED,
    dependencies=[Security(auth_dependencies.check_scopes, scopes=["gears:write"])],
)
@core_rate_limit.limiter.limit(core_rate_limit.WRITE)
def create_gear_component(
    request: Request,
    gear_component: gear_components_schema.GearComponentCreate,
    token_user_id: auth_dependencies.CurrentUserId,
    db: core_dependencies.DbSession,
    response: Response,
) -> gear_components_schema.GearComponentRead:
    """Create a component on one of the authenticated user's gears; ``Location`` names where it is read."""
    created = gear_components_service.create_gear_component(gear_component, token_user_id, db)
    core_location.set_location(response, request, "read_gear_component_by_id", gear_component_id=created.id)
    core_etag.set_etag(response, created.version)
    return created

delete_component_gear

delete_component_gear(request, gear_component_id, token_user_id, if_match, db)

Delete one of the authenticated user's gear components.

Send If-Match with the component's version as an ETag; a stale tag is refused with 412.

Source code in backend/app/modules/gears/gear_components/router.py
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
@router.delete(
    "/{gear_component_id}",
    response_model=None,
    status_code=status.HTTP_204_NO_CONTENT,
    dependencies=[Security(auth_dependencies.check_scopes, scopes=["gears:write"])],
)
@core_rate_limit.limiter.limit(core_rate_limit.WRITE)
def delete_component_gear(
    request: Request,
    gear_component_id: core_dependencies.UuidId,
    token_user_id: auth_dependencies.CurrentUserId,
    if_match: core_dependencies.IfMatch,
    db: core_dependencies.DbSession,
) -> None:
    """Delete one of the authenticated user's gear components.

    Send ``If-Match`` with the component's ``version`` as an ETag; a stale tag is refused with 412.
    """
    gear_components_service.delete_gear_component(token_user_id, gear_component_id, db, if_match=if_match)

edit_gear_component

edit_gear_component(request, gear_component_id, gear_component, token_user_id, db, response, if_match)

Update one of the authenticated user's gear components.

Applies a partial update: only fields present in the request body are changed, so omit a field to leave it untouched and send an explicit null to clear a nullable field (e.g. retired_date).

The retired/active invariant is enforced server-side: while retired_date is set the component is always inactive (active is forced to false); while it is null the submitted active value is honoured. Reactivating a retired component therefore requires clearing retired_date and setting active to true in the same request.

Send If-Match with the component's version as an ETag to make the write conditional; a stale tag is refused with 412.

Source code in backend/app/modules/gears/gear_components/router.py
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
@router.patch(
    "/{gear_component_id}",
    response_model=gear_components_schema.GearComponentRead,
    dependencies=[Security(auth_dependencies.check_scopes, scopes=["gears:write"])],
)
@core_rate_limit.limiter.limit(core_rate_limit.WRITE)
def edit_gear_component(
    request: Request,
    gear_component_id: core_dependencies.UuidId,
    gear_component: gear_components_schema.GearComponentUpdate,
    token_user_id: auth_dependencies.CurrentUserId,
    db: core_dependencies.DbSession,
    response: Response,
    if_match: core_dependencies.IfMatch,
) -> gear_components_schema.GearComponentRead:
    """Update one of the authenticated user's gear components.

    Applies a partial update: only fields present in the request body are
    changed, so omit a field to leave it untouched and send an explicit
    null to clear a nullable field (e.g. `retired_date`).

    The retired/active invariant is enforced server-side: while
    `retired_date` is set the component is always inactive (`active` is
    forced to false); while it is null the submitted `active` value is
    honoured. Reactivating a retired component therefore requires clearing
    `retired_date` and setting `active` to true in the same request.

    Send ``If-Match`` with the component's ``version`` as an ETag to make the write
    conditional; a stale tag is refused with 412.
    """
    updated = gear_components_service.edit_gear_component(
        gear_component_id, gear_component, token_user_id, db, if_match=if_match
    )
    core_etag.set_etag(response, updated.version)
    return updated

read_gear_component_by_id

read_gear_component_by_id(gear_component_id, token_user_id, db, response)

Retrieve one of the authenticated user's gear components; its ETag is the version for If-Match.

Source code in backend/app/modules/gears/gear_components/router.py
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
@router.get(
    "/{gear_component_id}",
    response_model=gear_components_schema.GearComponentRead,
    dependencies=[Security(auth_dependencies.check_scopes, scopes=["gears:read"])],
)
def read_gear_component_by_id(
    gear_component_id: core_dependencies.UuidId,
    token_user_id: auth_dependencies.CurrentUserId,
    db: core_dependencies.DbSession,
    response: Response,
) -> gear_components_schema.GearComponentRead:
    """Retrieve one of the authenticated user's gear components; its ``ETag`` is the version for ``If-Match``."""
    component = gear_components_service.get_gear_component(token_user_id, gear_component_id, db)
    core_etag.set_etag(response, component.version)
    return component

read_gear_component_types

read_gear_component_types()

Retrieve the valid component types, grouped by gear type.

Source code in backend/app/modules/gears/gear_components/router.py
17
18
19
20
21
22
23
24
@router.get(
    "/types",
    response_model=gear_components_schema.GearComponentTypesRead,
    dependencies=[Security(auth_dependencies.check_scopes, scopes=["gears:read"])],
)
def read_gear_component_types() -> gear_components_schema.GearComponentTypesRead:
    """Retrieve the valid component types, grouped by gear type."""
    return gear_components_service.read_component_types()

read_gear_components

read_gear_components(token_user_id, db, page)

Retrieve one page of the authenticated user's gear components, with the total.

Source code in backend/app/modules/gears/gear_components/router.py
27
28
29
30
31
32
33
34
35
36
37
38
39
40
@router.get(
    "",
    response_model=core_pagination.Page[gear_components_schema.GearComponentRead],
    dependencies=[Security(auth_dependencies.check_scopes, scopes=["gears:read"])],
)
def read_gear_components(
    token_user_id: auth_dependencies.CurrentUserId,
    db: core_dependencies.DbSession,
    page: core_pagination.ListPage,
) -> core_pagination.Page[gear_components_schema.GearComponentRead]:
    """Retrieve one page of the authenticated user's gear components, with the total."""
    return gear_components_service.list_gear_components(
        token_user_id, db, page_number=page.page_number, num_records=page.num_records
    )

Gear components schema definitions.

GearComponentBase

Bases: BaseModel

Base model for the gear component fields a client may set.

Attributes:

Name Type Description
type

Type of gear component.

brand

Gear component brand.

model

Gear component model name.

purchase_date date | None

Purchase date (calendar date, no time of day).

retired_date date | None

Retired date (calendar date, no time of day).

active StrictBool | None

Whether component is active.

expected_usage StrictInt | None

Wear threshold in meters for a distance-tracked gear and in seconds for a time-tracked one.

purchase_value Money | None

Purchase price as a decimal string in the owner's currency.

Source code in backend/app/modules/gears/gear_components/schema.py
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
class GearComponentBase(BaseModel):
    """Base model for the gear component fields a client may set.

    Attributes:
        type: Type of gear component.
        brand: Gear component brand.
        model: Gear component model name.
        purchase_date: Purchase date (calendar date, no time of day).
        retired_date: Retired date (calendar date, no time of day).
        active: Whether component is active.
        expected_usage: Wear threshold in meters for a distance-tracked gear and in seconds for a time-tracked one.
        purchase_value: Purchase price as a decimal string in the owner's currency.
    """

    purchase_date: date | None = Field(
        default=None,
        description="Purchase date",
    )
    retired_date: date | None = Field(
        default=None,
        description="Retired date",
    )
    active: StrictBool | None = Field(
        default=None,
        description=("Whether the component is active"),
    )
    expected_usage: StrictInt | None = Field(
        default=None,
        ge=0,
        le=MAX_EXPECTED_USAGE,
        description=(
            "Wear threshold: meters of activity distance for a distance-tracked gear, seconds of activity time "
            "for a time-tracked one (racquet)"
        ),
    )
    purchase_value: core_types.Money | None = Field(
        default=None,
        description=(
            "Purchase price as a decimal string with two decimals, in the owner's currency "
            "(the `currency` user setting), such as 129.90"
        ),
    )

    model_config = ConfigDict(
        from_attributes=True,
        extra="forbid",
        validate_assignment=True,
    )

GearComponentCreate

Bases: GearComponentBase

Schema for creating a gear component.

Attributes:

Name Type Description
gear_id UUID

Foreign key to gear table.

Source code in backend/app/modules/gears/gear_components/schema.py
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
class GearComponentCreate(GearComponentBase):
    """Schema for creating a gear component.

    Attributes:
        gear_id: Foreign key to gear table.
    """

    type: StrictStr = Field(
        ...,
        max_length=250,
        description="Type of gear component",
    )
    brand: StrictStr = Field(
        ...,
        max_length=250,
        description="Gear component brand",
    )
    model: StrictStr = Field(
        ...,
        max_length=250,
        description="Gear component model",
    )
    gear_id: uuid.UUID = Field(
        ...,
        description="Foreign key to gear",
    )

GearComponentRead

Bases: GearComponentCreate

Schema for reading a gear component.

Attributes:

Name Type Description
id UUID

Unique identifier.

user_id UUID

Foreign key to user.

version StrictInt

Optimistic-concurrency counter, also sent as the ETag.

updated_at datetime

When the component last changed; set by the server.

Source code in backend/app/modules/gears/gear_components/schema.py
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
class GearComponentRead(GearComponentCreate):
    """Schema for reading a gear component.

    Attributes:
        id: Unique identifier.
        user_id: Foreign key to user.
        version: Optimistic-concurrency counter, also sent as the ``ETag``.
        updated_at: When the component last changed; set by the server.
    """

    version: StrictInt = Field(
        default=1,
        ge=1,
        description="Optimistic-concurrency counter",
    )
    id: uuid.UUID = Field(
        ...,
        description="Unique identifier",
    )
    user_id: uuid.UUID = Field(
        ...,
        description="Foreign key to user",
    )
    updated_at: datetime = Field(
        ...,
        description="When the component last changed",
    )

GearComponentTypesRead

Bases: BaseModel

Schema for reading component type lists.

Attributes:

Name Type Description
bike list[str]

Valid bike component types.

shoes list[str]

Valid shoes component types.

racquet list[str]

Valid racquet component types.

windsurf list[str]

Valid windsurf component types.

Source code in backend/app/modules/gears/gear_components/schema.py
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
class GearComponentTypesRead(BaseModel):
    """Schema for reading component type lists.

    Attributes:
        bike: Valid bike component types.
        shoes: Valid shoes component types.
        racquet: Valid racquet component types.
        windsurf: Valid windsurf component types.
    """

    bike: list[str] = Field(
        ...,
        description=("Valid bike component types"),
    )
    shoes: list[str] = Field(
        ...,
        description=("Valid shoes component types"),
    )
    racquet: list[str] = Field(
        ...,
        description=("Valid racquet component types"),
    )
    windsurf: list[str] = Field(
        ...,
        description=("Valid windsurf component types"),
    )

    model_config = ConfigDict(
        extra="forbid",
    )

GearComponentUpdate

Bases: NotClearable, GearComponentBase

Partial update of a gear component: omit a field to keep it, send null to clear a nullable one.

The component and its gear come from the path and cannot be changed.

Source code in backend/app/modules/gears/gear_components/schema.py
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
class GearComponentUpdate(core_partial_update.NotClearable, GearComponentBase):
    """Partial update of a gear component: omit a field to keep it, send null to clear a nullable one.

    The component and its gear come from the path and cannot be changed.
    """

    not_clearable = ("type", "brand", "model", "purchase_date", "active")

    type: StrictStr | None = Field(
        default=None,
        max_length=250,
        description="Type of gear component",
    )
    brand: StrictStr | None = Field(
        default=None,
        max_length=250,
        description="Gear component brand",
    )
    model: StrictStr | None = Field(
        default=None,
        max_length=250,
        description="Gear component model",
    )

GearComponentUsageRead

Bases: GearComponentRead

A gear component with the usage it has accumulated, served by the per-gear list only.

Attributes:

Name Type Description
current_distance StrictFloat

Accumulated distance in meters.

current_time StrictFloat

Accumulated time in seconds.

Source code in backend/app/modules/gears/gear_components/schema.py
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
class GearComponentUsageRead(GearComponentRead):
    """A gear component with the usage it has accumulated, served by the per-gear list only.

    Attributes:
        current_distance: Accumulated distance in meters.
        current_time: Accumulated time in seconds.
    """

    current_distance: StrictFloat = Field(
        default=0,
        ge=0,
        description=("Accumulated activity distance in meters"),
    )
    current_time: StrictFloat = Field(
        default=0,
        ge=0,
        description=("Accumulated activity time in seconds"),
    )

is_retired_after_purchase

is_retired_after_purchase(purchase_date, retired_date)

Whether a retired date is acceptable next to a purchase date.

Parameters:

Name Type Description Default
purchase_date date | None

The purchase date, if given.

required
retired_date date | None

The retired date, if given.

required

Returns:

Type Description
bool

False only when both are given and the retired date is not later.

Source code in backend/app/modules/gears/gear_components/schema.py
23
24
25
26
27
28
29
30
31
32
33
def is_retired_after_purchase(purchase_date: date | None, retired_date: date | None) -> bool:
    """Whether a retired date is acceptable next to a purchase date.

    Args:
        purchase_date: The purchase date, if given.
        retired_date: The retired date, if given.

    Returns:
        False only when both are given and the retired date is not later.
    """
    return retired_date is None or purchase_date is None or retired_date > purchase_date