Improve gear nickname parsing and update Strava import docs

Enhanced gear nickname parsing by stripping whitespace after decoding in gear CRUD functions. Updated documentation for Strava bulk import to clarify import steps, note removal of '+' and whitespace, and correct development timelines for shoes and activity metadata imports.
This commit is contained in:
João Vitória Silva
2025-10-04 21:11:01 +01:00
parent 7ebd829cf0
commit 90cdae9072
2 changed files with 44 additions and 8 deletions

View File

@@ -111,9 +111,23 @@ def get_gear_user(user_id: int, db: Session) -> list[gears_schema.Gear] | None:
def get_gear_user_contains_nickname(
user_id: int, nickname: str, db: Session
) -> list[gears_schema.Gear] | None:
"""
Retrieve a list of gear objects for a given user where the gear's nickname contains the specified substring.
Args:
user_id (int): The ID of the user whose gear is being queried.
nickname (str): The substring to search for within gear nicknames. URL-encoded strings are supported.
db (Session): The SQLAlchemy database session.
Returns:
list[gears_schema.Gear] | None: A list of gear objects matching the criteria, or None if no gear is found.
Raises:
HTTPException: If an unexpected error occurs during the database query or processing.
"""
try:
# Unquote the nickname and change "+" to whitespace
parsed_nickname = unquote(nickname).replace("+", " ").lower()
parsed_nickname = unquote(nickname).replace("+", " ").lower().strip()
# Get the gear by user ID and nickname from the database
gears = (
@@ -151,9 +165,28 @@ def get_gear_user_contains_nickname(
def get_gear_user_by_nickname(
user_id: int, nickname: str, db: Session
) -> gears_schema.Gear | None:
"""
Retrieve a gear belonging to a user by its nickname.
This function attempts to find a gear in the database that matches the given user ID and nickname.
The nickname is URL-decoded, "+" characters are replaced with spaces, and the result is lowercased and stripped of whitespace before querying.
If a matching gear is found, it is serialized and returned; otherwise, None is returned.
In case of any exception, an error is logged and an HTTP 500 Internal Server Error is raised.
Args:
user_id (int): The ID of the user who owns the gear.
nickname (str): The nickname of the gear to retrieve.
db (Session): The SQLAlchemy database session.
Returns:
gears_schema.Gear | None: The serialized gear object if found, otherwise None.
Raises:
HTTPException: If an internal server error occurs during the process.
"""
try:
# Unquote the nickname and change "+" to whitespace
parsed_nickname = unquote(nickname).replace("+", " ").lower()
parsed_nickname = unquote(nickname).replace("+", " ").lower().strip()
# Get the gear by user ID and nickname from the database
gear = (

View File

@@ -105,21 +105,24 @@ Strava allows users to create a bulk export of their historical activity on the
### Importing gear from a Strava bulk import
At the present time, importing bikes from a Strava bulk export is implemented as a beta feature - use with caution. Components of bikes are not imported - just the bikes themselves.
At the present time, importing bikes from a Strava bulk export is implemented as a beta feature - use with caution. Components of bikes are not imported - just the bikes themselves. There is no mechanism present to undo an import.
To perform an import of bikes:
- Place the bikes.csv file from a Strava bulk export into the data/activity_files/bulk_import folder. Create the folder if needed.
- In the "Settings" menu select "Import".
- Click "Bikes Import" next to "Strava import".
- Place the bikes.csv file from a Strava bulk export into the data/activity_files/bulk_import folder. Create the folder if needed;
- In the "Settings" menu select "Import";
- Click "Import Strava Bikes" next to "Strava gear import";
- Upon successful import, the bikes.csv file is copied to /data/activity_files/processed folder;
- Status messages about the import, including why any gear was not imported, can be found in the logs.
Ensure the file is named "bikes.csv" and has a header row with at least the fields 'Bike Name', 'Bike Brand', and 'Bike Model'.
Note: All "+" characters will be stripped from all fields on import, along with any beginning and ending space (" ") characters.
### Importing other items from a Strava bulk import
Importing of shoes is under development in September 2025.
Importing of shoes is under development in October 2025.
Importing activity metadata and media is under development in September 2025.
Importing activity metadata and media is under development in October 2025.
## Image personalization