Skip to content

Commit

Permalink
Backend optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
joaovitoriasilva committed Jan 5, 2024
1 parent 3287e82 commit ad74fd7
Show file tree
Hide file tree
Showing 18 changed files with 1,234 additions and 409 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
<div align="center">
<img src="frontend/img/logo/logo.png" width="128" height="128">

# Endurain

A self-hosted fitness tracking service

<img src="screenshot_01.png">
</div>

> [!WARNING]
> This project is currently in **Alpha** state. You can try it out at your own risk, but be aware that things might break and **DATA LOSS** may occur.
Endurain is a self-hosted fitness tracking service that operates much like Strava but allows users to have complete control over their data and the hosting environment. The application's frontend is built using a combination of PHP, HTML, basic JavaScript, and Bootstrap CSS. On the backend, it leverages Python FastAPI and stravalib for seamless integration with Strava. The MariaDB database engine is employed to efficiently store and manage user data, while Jaeger is used for basic observability.

To deploy Endurain, Docker images are readily available, and a comprehensive example can be found in the "docker-compose.yml" file provided. Configuration is facilitated through environment variables, ensuring flexibility and ease of customization.
Expand Down Expand Up @@ -35,6 +48,8 @@ To do features (not by order):
- Comments and likes logic for activities
- Notifications logic
- Activity Pub integration?

More screenshots: https://imgur.com/a/lDR0sBf
---
# Frontend
Table bellow shows supported environemnt variables. Variables marked with optional "No" should be set to avoid errors.
Expand Down
38 changes: 15 additions & 23 deletions backend/controllers/activityController.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ async def read_activities_all(

# Return the queried values using JSONResponse
return JSONResponse(
content={"metadata": metadata, "activity_records": activity_records_dict}
content={"metadata": metadata, "content": activity_records_dict}
)

except JWTError:
Expand Down Expand Up @@ -276,7 +276,7 @@ async def read_activities_useractivities(

# Return the queried values using JSONResponse
return JSONResponse(
content={"metadata": metadata, "activity_records": activity_records_dict}
content={"metadata": metadata, "content": activity_records_dict}
)

except JWTError:
Expand Down Expand Up @@ -351,7 +351,7 @@ async def read_activities_useractivities_thisweek_number(

# Return the queried values using JSONResponse
return JSONResponse(
content={"metadata": metadata, "activity_records": activity_records_dict}
content={"metadata": metadata, "content": activity_records_dict}
)

except JWTError:
Expand Down Expand Up @@ -542,7 +542,7 @@ async def read_activities_useractivities_thismonth_number(

# Return the queried values using JSONResponse
return JSONResponse(
content={"metadata": metadata, "activity_count": activity_count}
content={"metadata": metadata, "content": activity_count}
)

except JWTError:
Expand Down Expand Up @@ -599,7 +599,7 @@ async def read_activities_gearactivities(

# Return the queried values using JSONResponse
return JSONResponse(
content={"metadata": metadata, "activity_records": activity_records_dict}
content={"metadata": metadata, "content": activity_records_dict}
)

except JWTError:
Expand Down Expand Up @@ -643,7 +643,7 @@ async def read_activities_all_number(

# Return the queried values using JSONResponse
return JSONResponse(
content={"metadata": metadata, "activity_count": activity_count}
content={"metadata": metadata, "content": activity_count}
)

except JWTError:
Expand Down Expand Up @@ -689,7 +689,7 @@ async def read_activities_useractivities_number(

# Return the queried values using JSONResponse
return JSONResponse(
content={"metadata": metadata, "activity_count": activity_count}
content={"metadata": metadata, "content": activity_count}
)

except JWTError:
Expand Down Expand Up @@ -744,7 +744,7 @@ async def read_activities_followed_useractivities_number(

# Return the queried values using JSONResponse
return JSONResponse(
content={"metadata": metadata, "activity_count": activity_count}
content={"metadata": metadata, "content": activity_count}
)

except JWTError:
Expand Down Expand Up @@ -814,7 +814,7 @@ async def read_activities_all_pagination(

# Return the queried values using JSONResponse
return JSONResponse(
content={"metadata": metadata, "activity_records": activity_records_dict}
content={"metadata": metadata, "content": activity_records_dict}
)

except JWTError:
Expand Down Expand Up @@ -879,7 +879,7 @@ async def read_activities_useractivities_pagination(

# Return the queried values using JSONResponse
return JSONResponse(
content={"metadata": metadata, "activity_records": activity_records_dict}
content={"metadata": metadata, "content": activity_records_dict}
)

except JWTError:
Expand Down Expand Up @@ -954,7 +954,7 @@ async def read_activities_followed_user_activities_pagination(

# Return the queried values using JSONResponse
return JSONResponse(
content={"metadata": metadata, "activity_records": activity_records_dict}
content={"metadata": metadata, "content": activity_records_dict}
)

except JWTError:
Expand Down Expand Up @@ -1020,7 +1020,7 @@ async def read_activities_activityFromId(

# Return the queried values using JSONResponse
return JSONResponse(
content={"metadata": metadata, "activity_records": activity_records_dict}
content={"metadata": metadata, "content": activity_records_dict}
)

except JWTError:
Expand Down Expand Up @@ -1079,9 +1079,7 @@ async def activity_add_gear(
)
else:
# Return a 404 response if the activity with the given ID does not exist
return JSONResponse(
content={"message": "Activity not found"}, status_code=404
)
return create_error_response("NOT_FOUND", "Activity not found", 404)

except JWTError:
# Return an error response if the user is not authenticated
Expand Down Expand Up @@ -1233,10 +1231,7 @@ async def delete_activity_gear(
# Check if the user with the given ID exists
if not activity:
# Return a 404 response if the user with the given ID does not exist
return JSONResponse(
content={"message": "Activity not found"},
status_code=404,
)
return create_error_response("NOT_FOUND", "Activity not found", 404)

# Set the user's photo paths to None to delete the photo
activity.gear_id = None
Expand Down Expand Up @@ -1304,10 +1299,7 @@ async def delete_activity(
)
else:
# Return a 404 response if the gear with the given ID does not exist
return JSONResponse(
content={"message": "Activity not found"},
status_code=404,
)
return create_error_response("NOT_FOUND", "Activity not found", 404)

except JWTError:
# Return an error response if the user is not authenticated
Expand Down
Loading

0 comments on commit ad74fd7

Please sign in to comment.