Add registration validation and more activities - #2
Conversation
…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.
…erification scripts
- 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.
There was a problem hiding this comment.
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_dbmanagement 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/. |
|
|
||
| # Stop any running Django processes | ||
| echo "Stopping existing Django processes..." | ||
| pkill -f "python.*manage.py runserver" 2>/dev/null || echo "No existing process found" |
There was a problem hiding this comment.
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).
| BASE_URL="http://localhost:8000" | ||
|
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
@copilot open a new pull request to apply changes based on this feedback
| test('renders learn react link', () => { | ||
| render(<App />); | ||
| const linkElement = screen.getByText(/learn react/i); | ||
| expect(linkElement).toBeInTheDocument(); | ||
| }); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
@copilot open a new pull request to apply changes based on this feedback
| @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), | ||
| ] |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
@copilot open a new pull request to apply changes based on this feedback
| @@ -0,0 +1 @@ | |||
| REACT_APP_CODESPACE_NAME=bug-free-goldfish-pqgxwp57wvc6q9q | |||
There was a problem hiding this comment.
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.
| REACT_APP_CODESPACE_NAME=bug-free-goldfish-pqgxwp57wvc6q9q | |
| REACT_APP_CODESPACE_NAME=your-codespace-name-here |
| <img | ||
| src="%PUBLIC_URL%/octofitapp-small.png" | ||
| alt="OctoFit Logo" | ||
| height="40" | ||
| className="me-2" | ||
| onError={(e) => { e.target.style.display = 'none'; }} | ||
| /> |
There was a problem hiding this comment.
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.
| npm build | ||
|
|
||
| # Run linter | ||
| npm run lint |
There was a problem hiding this comment.
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).
| npm build | |
| # Run linter | |
| npm run lint | |
| npm run build |
| """Calculate the number of users in this team.""" | ||
| return User.objects.filter(team=obj.name).count() | ||
|
|
||
|
|
There was a problem hiding this comment.
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.
| """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() |
| # 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')) |
There was a problem hiding this comment.
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.
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>
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>
[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>
…4ef4-90d2-c6738f3f4294
…4-90d2-c6738f3f4294 Centralize API URL configuration with localhost fallback
…4d3c-b8ef-75364c55a593
…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
…47a6-8443-d682711431ec
…6-8443-d682711431ec Fix hardcoded API URLs breaking local development
Add centralized API configuration with localhost fallback
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:
User,Team,Activity,Leaderboard, andWorkoutinmodels.py, with appropriate fields and database table names to represent the application's main entities.serializers.pyfor all models, including a computedmember_countfield for teams.Admin and management utilities:
admin.py, enabling advanced filtering, search, and display options in the admin interface.populate_db.pyto seed the database with sample data for users, teams, activities, leaderboard entries, and workouts, including unique index creation for user emails.__init__.pyfiles. [1] [2]Project setup and developer experience:
manage.pyandasgi.pyto enable standard Django project execution and ASGI configuration. [1] [2]CODESPACE_SETUP.mdguide for running and testing the backend in GitHub Codespaces, detailing configuration, port forwarding, API endpoints, and troubleshooting steps.Documentation and prompts: