Skip to content

Commit 6b130a0

Browse files
committed
feat: document Week 4 backend changes including 404 and BAD_REQUEST handling, user read endpoint, and OpenAPI updates
1 parent e5d0ffa commit 6b130a0

File tree

4 files changed

+115
-0
lines changed

4 files changed

+115
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Week 4 Checkout Summary — Backend
2+
3+
## Overview (Week 4 — late October)
4+
1. ### Standardized NOT_FOUND semantics
5+
- 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).
25+
- JaCoCo instruction coverage: ~84% total (gate ≥ 70% remains green).
26+
27+
## Key Decisions & Rationale
28+
- Centralize 404 behavior via a domain exception to reduce controller boilerplate and ensure consistent envelopes.
29+
- Keep cross-user reads gated and least-privilege by default; only self or `ADMIN` can fetch when feature is enabled.
30+
- Public profile DTO excludes email to reduce PII exposure; future public profile endpoint can reuse the same DTO or an even slimmer one.
31+
32+
## What Went Well
33+
- Layering preserved (Controller → Service → Repository). Controllers remain thin and secure.
34+
- Focused tests captured envelope behavior for both NOT_FOUND and BAD_REQUEST without bloating integration suites.
35+
- OpenAPI is back in sync, making frontend consumption clearer.
36+
37+
## What I Struggled With
38+
- Security slices in WebMvc tests required explicit authentication setup; solved with `@WithMockUser` or session cookie when appropriate.
39+
- Property-gated endpoint meant careful test enable/disable to keep the suite green by default.
40+
41+
## Suggested Next Steps (Backend)
42+
- When bringing up the admin console:
43+
- Enable `sameboat.endpoints.user-read=true` in admin/staging environments.
44+
- Add role-based method security (`@EnableMethodSecurity`) and migrate inline checks to `@PreAuthorize`.
45+
- Add integration tests for `403` (non-self, non-admin) and `200` for admin fetching other users.
46+
- Consider adding a dedicated public profile route (e.g., `/profiles/{id}`) with no auth but constrained DTO.
47+
- Continue ratcheting coverage toward 75% by adding small unit tests (e.g., more `UserService` edge cases, filter behaviors).
48+
49+
## Verification (Local)
50+
- Run fast tests (Windows cmd):
51+
```cmd
52+
mvn "-Dskip.migration.test=false" test
53+
```
54+
- Full verify (tests + coverage gate):
55+
```cmd
56+
mvn "-Dskip.migration.test=false" verify
57+
```
58+
- Optional migration schema test (requires Docker/Testcontainers):
59+
```cmd
60+
mvn -Pwith-migration-test test
61+
```
62+
63+
## Checklist (Backend Focus)
64+
- [x] ResourceNotFoundException + 404 mapping in GlobalExceptionHandler
65+
- [x] Service method throws on missing resource and unit test
66+
- [x] WebMvc test for NOT_FOUND envelope
67+
- [x] Focused BAD_REQUEST mapping test (`IllegalArgumentException`)
68+
- [x] OpenAPI sync with `/api/version` and error schema
69+
- [x] Architecture.md Week 4 summary
70+
- [x] README updated (Week 4 highlights, Windows mvn note, error catalog includes NOT_FOUND)
71+
- [x] Coverage gate ≥ 70% (current ~84%)
72+
- [x] Gated `GET /users/{id}` returning `PublicUserDto`; access: self or ADMIN; disabled by default
73+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Week 4 – Backend Plan (Checklist)
2+
3+
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).
13+
- [x] BAD_REQUEST mapping test: Focused WebMvc test asserting `IllegalArgumentException``{ "error": "BAD_REQUEST" }`.
14+
- [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`.
15+
- [x] Coverage gate: verified JaCoCo ≥ 70% (current ~84%).
16+
17+
## Left (Backend-focused)
18+
- [ ] None for Week 4. Carryovers: raise coverage target to 75% in a future cycle; enable gated `/users/{id}` when admin/public profile work lands.
19+
20+
## Scope Notes
21+
- Excluded (frontend-only): health polling backoff/pause, reduced-motion accessibility controls, debug panel utilities, identicon fallback, and visibility-driven session refresh.

docs/weekly-plan/week-4/week-4-plan-draft.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,27 @@ Theme (Proposed): Quality hardening, accessibility polish, developer ergonomics,
1616
| Visual polish (avatars) | Clarity in demos | Deterministic identicon fallback implemented |
1717
| Session freshness | Better long-lived tab UX | Visibility change triggers conditional refresh |
1818

19+
## Week 4 Status Checklist (as of 2025-10-29)
20+
21+
Notes:
22+
- 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.
34+
- [ ] Visual / UX polish (frontend): deterministic identicon fallback, copy‑to‑clipboard user ID, spacing sweep.
35+
- [ ] Session freshness (frontend): `visibilitychange`-based conditional refresh with overlap safeguards.
36+
- [ ] 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.
37+
38+
---
39+
1940
## Detailed Tasks (Initial Backlog)
2041

2142
### 1. Testing & CI
File renamed without changes.

0 commit comments

Comments
 (0)