You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Merge: PR #47 from sameboat-platform/feat/week4-backend-notfound-badrequest-openapi-docs
This pull request introduces several backend improvements focused on error handling, endpoint hardening, documentation updates, and test coverage. The main highlights are the standardization of 404 (NOT_FOUND) error semantics, improved BAD_REQUEST mapping, the addition of a gated public user profile endpoint, and synchronization of OpenAPI and documentation with the current backend state.
- Standardized NOT_FOUND: added `ResourceNotFoundException` and mapped to HTTP 404 with error `NOT_FOUND`in the global handler; service throws, controllers stay thin.
- OpenAPI sync: spec now includes `/api/version` and a reusable `ErrorResponse` schema enumerating current error codes.
17
+
- Future endpoint (gated): added a hardened `GET /users/{id}` returning `PublicUserDto` (no email). It’s disabled by default and only enabled when `sameboat.endpoints.user-read=true`; access allowed to self or `ADMIN`.
12
18
13
19
## Getting Started (Contributors)
14
20
Before writing code or using AI assistance:
@@ -36,6 +42,11 @@ Alias Tokens (for AI prompts): `BACKEND_CI_GUARD`, `LAYER_RULE`, `SECURITY_BASEL
36
42
-`GET /health` → 200 OK (custom simple health)
37
43
-`GET /actuator/health` → 200 OK and `{ "status": "UP" }`
38
44
45
+
Windows note: prefer `mvn` (not the wrapper) when running multiple CLI properties in one go; wrap all flags in double quotes in cmd.exe, for example:
46
+
```cmd
47
+
mvn "-Dskip.migration.test=false" verify
48
+
```
49
+
39
50
### Container (Docker) Usage
40
51
A multi-stage Dockerfile is provided for local testing and Render deployment.
- Introduced `ResourceNotFoundException` in the common layer and mapped it in `GlobalExceptionHandler` to HTTP 404 with error code `NOT_FOUND`.
6
+
- Services throw the exception; controllers remain thin and rely on the centralized handler.
7
+
- Added tests: service unit test for missing user and WebMvc test asserting the 404 envelope.
8
+
9
+
2.### BAD_REQUEST mapping coverage
10
+
- Added a focused WebMvc test to assert `IllegalArgumentException` is translated to HTTP 400 with `{ "error": "BAD_REQUEST" }`.
11
+
- Keeps error envelope consistent and prevents controller-specific ad hoc responses.
12
+
13
+
3.### Endpoint hardening for future admin/public profiles
14
+
- Added a gated user read endpoint `GET /users/{id}` returning `PublicUserDto` (no email or sensitive fields).
15
+
- Endpoint is disabled by default; enable with `sameboat.endpoints.user-read=true`.
16
+
- Access control: only the authenticated user (self) or `ADMIN` may fetch. Tests are present but disabled until the feature is enabled for real environments.
17
+
18
+
4.### OpenAPI & Docs
19
+
- Updated `openapi/sameboat.yaml` to include `/api/version` and a reusable `ErrorResponse` schema enumerating current error codes (`UNAUTHENTICATED`, `BAD_CREDENTIALS`, `SESSION_EXPIRED`, `VALIDATION_ERROR`, `BAD_REQUEST`, `RATE_LIMITED`, `NOT_FOUND`, `INTERNAL_ERROR`).
20
+
-`docs/Architecture.md`: added a Week 4 Backend Summary with the above items.
21
+
- README: added Week 4 highlights, Windows `mvn` quoting note, and included `NOT_FOUND` in error catalog table.
22
+
23
+
5.### Tests & Quality Gates
24
+
- All tests pass locally (migration Testcontainers profile skipped without Docker).
Context: Backend-only items extracted from the Week 4 plan. Status as of 2025-10-29.
4
+
5
+
## Done
6
+
-[x] Environment onboarding: `.env.example` present at repo root and referenced in README (copy to `.env` for local runs).
7
+
-[x] CI pipeline (BACKEND_CI_GUARD): `.github/workflows/backend-ci.yml` runs migration immutability check, `mvn verify` (unit + integration tests), JaCoCo coverage gate (≥ 70%), and a Flyway schema test profile step.
8
+
-[x] Auth hardening: password complexity validation, in-memory login rate limiting returning `RATE_LIMITED` on abuse, and scheduled session pruning job.
9
+
-[x] Public endpoints: `GET /health`, `GET /actuator/health`, and `GET /api/version` implemented and covered by integration tests.
10
+
-[x] Profiles & CORS: `dev` vs `prod` profiles with secure cookie/domains in prod; CORS allowlist configured (credentials enabled, no wildcards).
11
+
-[x] Flyway migrations: schema aligned with `UserEntity` (e.g., timezone column) via a new migration; historical migrations protected by immutability scripts.
12
+
-[x] NOT_FOUND mapping: Added `ResourceNotFoundException`, mapped to 404 in `GlobalExceptionHandler`, service method `UserService.getByIdOrThrow(UUID)`, gated `GET /users/{id}` uses it when enabled; tests added (service + WebMvc 404 envelope).
-[x] OpenAPI sync: `openapi/sameboat.yaml` updated to include `/api/version` and `ErrorResponse` schema with current error codes; brief Week 4 backend summary added to `docs/Architecture.md`.
- This repository is the backend (Spring Boot). Several Week 4 items target the frontend app (Vite/React) and its CI; those remain pending here and should be tracked/completed in the frontend repo.
23
+
- BACKEND_CI_GUARD respected: main backend CI workflow exists at `.github/workflows/backend-ci.yml`.
24
+
25
+
Done
26
+
-[x] Environment onboarding (backend scope): `.env.example` is present at repo root and referenced in README “Run locally” section (copy `.env.example` → `.env`).
27
+
-[x] CI (backend scope): Backend CI already runs tests (`mvn verify`) and fails on red; coverage gate enforced (JaCoCo ≥ 70%).
28
+
29
+
Left (to be completed, mostly frontend scope unless noted)
30
+
-[ ] Testing & CI (frontend): Add `npm test` step to the frontend CI (`frontend-ci.yml`) before build; add routing/auth UI tests listed below.
31
+
-[ ] Health polling resilience (frontend): pause-on-error, exponential backoff, debug surface for failure streak/last success.
32
+
-[ ] Accessibility / Motion control (frontend): central reduced‑motion preference, gate animations, document approach in `Architecture.md` (Week 4 section).
33
+
-[ ] Developer control utilities (frontend): debug panel interval override, failure/backoff display, “Force full auth refresh” button.
-[ ] Documentation: Add Week 4 summary in `docs/Architecture.md`; update any week‑3 links if metrics scripts change; consider short CHANGELOG segment if scope grows.
0 commit comments