Skip to content

Add registration validation and more activities - #2

Merged
pmca31 merged 55 commits into
mainfrom
build-octofit-app
Feb 11, 2026
Merged

Add registration validation and more activities#2
pmca31 merged 55 commits into
mainfrom
build-octofit-app

Conversation

@pmca31

@pmca31 pmca31 commented Feb 11, 2026

Copy link
Copy Markdown
Owner

This pull request introduces the foundational backend for the OctoFit Tracker Django application, including core models, serializers, admin configuration, management commands, and developer documentation. The changes establish support for users, teams, activities, leaderboards, and workouts, and provide utilities for local development and testing, especially in GitHub Codespaces.

Core application structure and models:

  • Added Django models for User, Team, Activity, Leaderboard, and Workout in models.py, with appropriate fields and database table names to represent the application's main entities.
  • Implemented corresponding serializers in serializers.py for all models, including a computed member_count field for teams.

Admin and management utilities:

  • Configured Django admin classes for all models in admin.py, enabling advanced filtering, search, and display options in the admin interface.
  • Added a custom management command populate_db.py to seed the database with sample data for users, teams, activities, leaderboard entries, and workouts, including unique index creation for user emails.
  • Initialized management command packages with __init__.py files. [1] [2]

Project setup and developer experience:

  • Added manage.py and asgi.py to enable standard Django project execution and ASGI configuration. [1] [2]
  • Provided a comprehensive CODESPACE_SETUP.md guide for running and testing the backend in GitHub Codespaces, detailing configuration, port forwarding, API endpoints, and troubleshooting steps.

Documentation and prompts:

  • Added a high-level prompt and description for the OctoFit Tracker Django app, summarizing the main updates and directory structure. (.github/prompts/update-octofit-tracker-app.prompt.md)

…iews, and API endpoints for octofit_tracker application. Add management command to populate the database with test data, and implement tests for models and API endpoints.
- Added main App component with routing for Users, Activities, Teams, Leaderboard, and Workouts.
- Created individual components for Activities, Leaderboard, Teams, Users, and Workouts with data fetching and error handling.
- Implemented loading states and error messages for better user experience.
- Added a simple CSS file for basic styling.
- Included a test file for the App component.
- Created scripts for restarting the backend and testing API endpoints.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR bootstraps the OctoFit Tracker application by adding a Django REST backend (models/viewsets/admin/tests + local dev tooling) and a Create React App frontend that consumes the API.

Changes:

  • Adds Django models/serializers/viewsets + a populate_db management command for seeding MongoDB via Djongo.
  • Adds a CRA-based React UI with pages for Users/Teams/Activities/Leaderboard/Workouts and app styling/docs.
  • Adds developer scripts/docs for Codespaces/local verification and API testing.

Reviewed changes

Copilot reviewed 44 out of 51 changed files in this pull request and generated 23 comments.

Show a summary per file
File Description
verify_setup.sh Adds an environment/config verification script for backend + MongoDB.
restart-backend.sh Adds a helper script to restart the Django dev server.
test_api.sh Adds a curl-based script to test backend REST endpoints.
test-teams-api.sh Adds a small script to inspect Teams/Users endpoints for member_count.
CODESPACE_SETUP.md Adds Codespaces/local setup and testing documentation.
octofit-tracker/backend/manage.py Adds Django management entrypoint.
octofit-tracker/backend/requirements.txt Adds backend Python dependencies for Django/DRF/Djongo.
octofit-tracker/backend/octofit_tracker/settings.py Configures Django for Djongo/MongoDB + Codespaces + CORS.
octofit-tracker/backend/octofit_tracker/urls.py Wires DRF router and API root routing.
octofit-tracker/backend/octofit_tracker/views.py Adds DRF ModelViewSets and an API root view helper.
octofit-tracker/backend/octofit_tracker/models.py Defines core domain models (User/Team/Activity/Leaderboard/Workout).
octofit-tracker/backend/octofit_tracker/serializers.py Adds DRF serializers + computed member_count.
octofit-tracker/backend/octofit_tracker/admin.py Registers models in Django admin with list/search configs.
octofit-tracker/backend/octofit_tracker/tests.py Adds basic model and API endpoint tests.
octofit-tracker/backend/octofit_tracker/asgi.py Adds ASGI config for deployments.
octofit-tracker/backend/octofit_tracker/wsgi.py Adds WSGI config for deployments.
octofit-tracker/backend/octofit_tracker/management/init.py Initializes management package.
octofit-tracker/backend/octofit_tracker/management/commands/init.py Initializes commands package.
octofit-tracker/backend/octofit_tracker/management/commands/populate_db.py Adds a database seeding command.
.github/prompts/update-octofit-tracker-app.prompt.md Adds a prompt doc describing expected Django file updates.
octofit-tracker/frontend/package.json Adds frontend dependencies/scripts (CRA + router + bootstrap).
octofit-tracker/frontend/package-lock.json Locks frontend dependency versions.
octofit-tracker/frontend/.gitignore Adds CRA-standard ignores.
octofit-tracker/frontend/.env.example Adds example env configuration for Codespaces name.
octofit-tracker/frontend/.env Adds a concrete env file with a specific Codespace name.
octofit-tracker/frontend/setup.sh Adds a frontend setup script (env + logo copying).
octofit-tracker/frontend/copy-logo.sh Adds a helper script to copy branding assets into CRA folders.
octofit-tracker/frontend/FRONTEND_README.md Adds app-specific frontend docs (setup, endpoints, troubleshooting).
octofit-tracker/frontend/STYLE_GUIDE.md Adds UI styling/design guide.
octofit-tracker/frontend/README.md Adds CRA default README.
octofit-tracker/frontend/public/index.html Adds CRA HTML template + branding.
octofit-tracker/frontend/public/manifest.json Adds PWA manifest updated for OctoFit branding.
octofit-tracker/frontend/public/robots.txt Adds robots.txt template.
octofit-tracker/frontend/public/favicon.ico Adds favicon asset.
octofit-tracker/frontend/public/logo192.png Adds app icon asset.
octofit-tracker/frontend/public/logo512.png Adds app icon asset.
octofit-tracker/frontend/src/index.js Adds CRA entrypoint wiring App + Bootstrap CSS.
octofit-tracker/frontend/src/index.css Adds baseline CSS.
octofit-tracker/frontend/src/App.js Adds routed UI shell and home page.
octofit-tracker/frontend/src/App.css Adds main UI styling.
octofit-tracker/frontend/src/App.test.js Adds CRA default test.
octofit-tracker/frontend/src/setupTests.js Adds jest-dom setup.
octofit-tracker/frontend/src/reportWebVitals.js Adds CRA web-vitals hook.
octofit-tracker/frontend/src/logo.svg Adds CRA default logo asset.
octofit-tracker/frontend/src/components/Users.js Adds Users page + edit modal + PATCH update call.
octofit-tracker/frontend/src/components/Teams.js Adds Teams list page consuming /api/teams/.
octofit-tracker/frontend/src/components/Activities.js Adds Activities list page consuming /api/activities/.
octofit-tracker/frontend/src/components/Leaderboard.js Adds Leaderboard page consuming /api/leaderboard/.
octofit-tracker/frontend/src/components/Workouts.js Adds Workouts page consuming /api/workouts/.

Comment thread restart-backend.sh

# Stop any running Django processes
echo "Stopping existing Django processes..."
pkill -f "python.*manage.py runserver" 2>/dev/null || echo "No existing process found"

Copilot AI Feb 11, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pkill -f "python.*manage.py runserver" can terminate unrelated Django runservers (or other python processes that match) on the machine. Consider writing the server PID to a file and killing that PID, or using a more targeted match (e.g., include the backend path).

Copilot uses AI. Check for mistakes.
Comment thread test-teams-api.sh Outdated
Comment on lines +5 to +6
BASE_URL="http://localhost:8000"

Copilot AI Feb 11, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This script is hard-coded to http://localhost:8000, so it won't work in Codespaces where the backend is accessed via the https://{CODESPACE_NAME}-8000.app.github.dev URL. Consider detecting CODESPACE_NAME (like test_api.sh) and selecting the correct base URL.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot open a new pull request to apply changes based on this feedback

Comment on lines +4 to +8
test('renders learn react link', () => {
render(<App />);
const linkElement = screen.getByText(/learn react/i);
expect(linkElement).toBeInTheDocument();
});

Copilot AI Feb 11, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test asserts a "learn react" link exists, but App no longer renders that text. As written, npm test will fail. Update the test to match the current UI (e.g., assert on the navbar brand or the welcome heading) or remove it if it's just CRA scaffolding.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot open a new pull request to apply changes based on this feedback

Comment on lines +33 to +60
@api_view(['GET'])
def api_root_codespace(request, format=None):
"""
API root endpoint that returns full URLs for codespace environment.
"""
codespace_name = os.environ.get('CODESPACE_NAME')

if codespace_name:
# Running in GitHub Codespaces
base_url = f'https://{codespace_name}-8000.app.github.dev'
else:
# Running locally
base_url = f'{request.scheme}://{request.get_host()}'

return Response({
'users': f'{base_url}/api/users/',
'teams': f'{base_url}/api/teams/',
'activities': f'{base_url}/api/activities/',
'leaderboard': f'{base_url}/api/leaderboard/',
'workouts': f'{base_url}/api/workouts/',
})


urlpatterns = [
path('', api_root_codespace, name='api-root'),
path('api/', include(router.urls)),
path('admin/', admin.site.urls),
]

Copilot AI Feb 11, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

urls.py defines an API root at / (named api-root) while the rest of the docs/scripts describe the API root as /api/ (and DefaultRouter already serves a root view at /api/). This split is confusing for clients and makes it easy to document/test the wrong URL. Consider moving api_root_codespace to path('api/', ...) and reserving / for a non-API landing page (or redirect).

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot open a new pull request to apply changes based on this feedback

Comment thread octofit-tracker/backend/octofit_tracker/settings.py Outdated
Comment thread octofit-tracker/frontend/.env Outdated
@@ -0,0 +1 @@
REACT_APP_CODESPACE_NAME=bug-free-goldfish-pqgxwp57wvc6q9q

Copilot AI Feb 11, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Committing .env bakes in a specific Codespace name and encourages storing environment-specific (potentially sensitive) config in git. Consider removing this file from version control, adding .env to .gitignore, and relying on .env.example/frontend/setup.sh to generate it locally.

Suggested change
REACT_APP_CODESPACE_NAME=bug-free-goldfish-pqgxwp57wvc6q9q
REACT_APP_CODESPACE_NAME=your-codespace-name-here

Copilot uses AI. Check for mistakes.
Comment on lines +17 to +23
<img
src="%PUBLIC_URL%/octofitapp-small.png"
alt="OctoFit Logo"
height="40"
className="me-2"
onError={(e) => { e.target.style.display = 'none'; }}
/>

Copilot AI Feb 11, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The navbar logo src is set to the literal string %PUBLIC_URL%/octofitapp-small.png. %PUBLIC_URL% substitution only happens in public/index.html, not inside JS/JSX, so the image URL will be invalid at runtime. Use process.env.PUBLIC_URL + '/octofitapp-small.png' or import the image from src.

Copilot uses AI. Check for mistakes.
Comment on lines +81 to +84
npm build

# Run linter
npm run lint

Copilot AI Feb 11, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The README lists npm build and npm run lint, but package.json defines build as npm run build and does not define a lint script. Update the doc to match the actual scripts (or add the missing script).

Suggested change
npm build
# Run linter
npm run lint
npm run build

Copilot uses AI. Check for mistakes.
Comment on lines +21 to +24
"""Calculate the number of users in this team."""
return User.objects.filter(team=obj.name).count()


Copilot AI Feb 11, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeamSerializer.get_member_count() runs a separate User.objects.filter(...).count() query per team. On the teams list endpoint this becomes an N+1 query pattern and will slow down as the number of teams grows. Consider annotating the Team queryset with a count (or denormalizing member_count) so it can be fetched in one query.

Suggested change
"""Calculate the number of users in this team."""
return User.objects.filter(team=obj.name).count()
"""Calculate the number of users in this team.
If the Team queryset has been annotated with `member_count`, use that
value to avoid N+1 queries. Otherwise, fall back to counting users
for this specific team.
"""
annotated_count = getattr(obj, 'member_count', None)
if annotated_count is not None:
return annotated_count
return User.objects.filter(team=obj).count()

Copilot uses AI. Check for mistakes.
Comment on lines +21 to +25
# Create unique index on email field using pymongo
client = MongoClient('localhost', 27017)
db = client['octofit_db']
db.users.create_index('email', unique=True)
self.stdout.write(self.style.SUCCESS('Created unique index on email field'))

Copilot AI Feb 11, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This management command uses pymongo.MongoClient to create an index directly in MongoDB. This bypasses Django's ORM/migrations and can drift from the model definition (the User.email field is already unique=True). Consider removing the direct MongoDB call and relying on the model constraint / Django index definitions; also ensure any created Mongo client is closed to avoid resource leaks.

Copilot uses AI. Check for mistakes.

Copilot AI commented Feb 11, 2026

Copy link
Copy Markdown
Contributor

@pmca31 I've opened a new pull request, #3, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI commented Feb 11, 2026

Copy link
Copy Markdown
Contributor

@pmca31 I've opened a new pull request, #4, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI commented Feb 11, 2026

Copy link
Copy Markdown
Contributor

@pmca31 I've opened a new pull request, #5, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI and others added 4 commits February 11, 2026 19:19
Co-authored-by: pmca31 <6774003+pmca31@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: pmca31 <6774003+pmca31@users.noreply.github.com>

Copilot AI commented Feb 11, 2026

Copy link
Copy Markdown
Contributor

@pmca31 I've opened a new pull request, #6, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI commented Feb 11, 2026

Copy link
Copy Markdown
Contributor

@pmca31 I've opened a new pull request, #7, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI and others added 2 commits February 11, 2026 19:21
Co-authored-by: pmca31 <6774003+pmca31@users.noreply.github.com>

Copilot AI commented Feb 11, 2026

Copy link
Copy Markdown
Contributor

@pmca31 I've opened a new pull request, #8, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI and others added 29 commits February 11, 2026 19:24
Co-authored-by: pmca31 <6774003+pmca31@users.noreply.github.com>
Co-authored-by: pmca31 <6774003+pmca31@users.noreply.github.com>
[WIP] Update registration validation and activities based on feedback
…ute path

Co-authored-by: pmca31 <6774003+pmca31@users.noreply.github.com>
Co-authored-by: pmca31 <6774003+pmca31@users.noreply.github.com>
Co-authored-by: pmca31 <6774003+pmca31@users.noreply.github.com>
Co-authored-by: pmca31 <6774003+pmca31@users.noreply.github.com>
Co-authored-by: pmca31 <6774003+pmca31@users.noreply.github.com>
- Create config/api.js with getApiUrl utility
- Update all components to use centralized API config
- Add REACT_APP_API_BASE_URL env var support
- Maintain backward compatibility with REACT_APP_CODESPACE_NAME
- Update .env and .env.example with new configuration docs

Co-authored-by: pmca31 <6774003+pmca31@users.noreply.github.com>
Co-authored-by: pmca31 <6774003+pmca31@users.noreply.github.com>
- Document REACT_APP_API_BASE_URL as recommended approach
- Explain configuration priority and fallback behavior
- Update setup instructions for local development
- Add examples for different environments

Co-authored-by: pmca31 <6774003+pmca31@users.noreply.github.com>
Co-authored-by: pmca31 <6774003+pmca31@users.noreply.github.com>
When both REACT_APP_API_BASE_URL and REACT_APP_CODESPACE_NAME are set,
only the first is used due to priority. Commenting out the Codespaces
variable to make it clear that the localhost config is active.

Co-authored-by: pmca31 <6774003+pmca31@users.noreply.github.com>
Co-authored-by: pmca31 <6774003+pmca31@users.noreply.github.com>
…4-90d2-c6738f3f4294

Centralize API URL configuration with localhost fallback
…c-b8ef-75364c55a593

Add centralized API configuration with localhost fallback
Fix test-teams-api.sh to support GitHub Codespaces
Fix failing App.test.js after UI migration to OctoFit Tracker
Consolidate API root to /api/ path, remove duplicate endpoint at /
Fix copy-logo.sh to work from any directory
…3-8edc-1fe3ffaf6ce0

Use python3 explicitly in shell scripts
…-a848-9fcba8ef2395

Fix hard-coded workspace path in verify_setup.sh
…6-8443-d682711431ec

Fix hardcoded API URLs breaking local development
Add centralized API configuration with localhost fallback
@pmca31
pmca31 merged commit f059131 into main Feb 11, 2026
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.

3 participants