Skip to content

Conversation

@ebigunso
Copy link
Owner

Summary

Implements PR-C scope across backend (Axum) and SvelteKit frontend.

Backend (Axum)

  • New read endpoints (session required, no CSRF):
    • GET /sleep/recent?days=7 — clamps days to [1,31], ordered by date desc
    • GET /sleep/range?from=YYYY-MM-DD&to=YYYY-MM-DD — validates from ≤ to and range ≤ 62 days, ordered by date asc
  • Model/Repository:
    • Add SleepListItem (id, date, bed_time, wake_time, latency_min, awakenings, quality, duration_min)
    • repository::list_recent_sleep(db, days)
    • repository::list_sleep_range(db, from, to)
  • Router/Handlers:
    • Wire routes in app.rs using RequireSessionJson, return JSON and 400 {code,message} on invalid params
  • OpenAPI (openapi.yaml):
    • Document /sleep/recent and /sleep/range
    • Add components: SleepListItem, BadRequest; cookieAuth security for reads
  • Tests:
    • Add tests/api_sleep_list.rs covering happy cases and invalid params

Frontend (SvelteKit)

  • Utilities (src/lib/api.ts):
    • getCsrfToken alias; apiFetch wrapper (credentials + CSRF)
    • Helpers: getRecent, getRange, createSleep, updateSleep, deleteSleep, upsertExercise
    • Types: SleepListItem, SleepInput, ExerciseUpsert
  • Components:
    • SleepBar.svelte – 24h mini-bar with cross-midnight wrap
    • ConfirmDialog.svelte – generic confirm modal
    • SleepForm.svelte – UI validations, duration warning for <2h or >14h; Proceed still saves; best-effort /exercise and optional /note post
    • WeekRow.svelte – row renderer with bar + metrics + edit/delete and exercise badge
  • Stores:
    • src/lib/stores/sleep.ts – recent list + per-date intensity with upsert/remove helpers
  • Dashboard (week view):
    • +page.server.ts loads getRecent(7)
    • +page.svelte renders 7 rows (missing dates show Add), Quick Log -> /sleep/new
  • Create/Edit/Delete routes:
    • /sleep/new
    • /sleep/[id]/edit (loads by ?date=; delete confirmed)
  • Day view:
    • /day/[date] — loads single-day via /sleep/range and renders full record + Edit
  • Tests (UI):
    • Playwright e2e: login → quick log → edit → delete; duration warning respected
    • Vitest unit: SleepBar wrap correctness, CSRF token cookie selection; vitest config added
  • Dev experience:
    • vitest.config.ts (jsdom)
    • vite.config.ts skips SvelteKit/tailwind plugins under VITEST env to avoid hot-update in vitest

Alignment with PR-A/PR-B

  • Reads require authenticated session, no CSRF
  • Login via /login (form), frontend continues probing /api/session
  • Backend remains API-only (no HTML)

How to run locally

  • Backend: cargo test -p sleep-api (all green)
  • Frontend:
    • cd sleep-ui && npm install
    • npm run test:unit (vitest)
    • For e2e: set PLAYWRIGHT_EMAIL/PASSWORD and run npm run test:e2e

Notes

  • Exercise upsert treated as last-write-wins; UI updates intensity badges via store. Can enforce DB uniqueness later.
  • Duration warnings are UI-only: warn and allow proceed.

Changelog of notable files

  • sleep-api/src/app.rs: + /sleep/recent, /sleep/range
  • sleep-api/src/models/sleep.rs: + SleepListItem
  • sleep-api/src/repository.rs: + list_recent_sleep, list_sleep_range
  • openapi.yaml: + endpoints & schemas
  • sleep-api/tests/api_sleep_list.rs: new
  • sleep-ui/src/lib/api.ts: new helpers & types
  • sleep-ui/src/lib/components/: SleepBar.svelte, ConfirmDialog.svelte, SleepForm.svelte, WeekRow.svelte
  • sleep-ui/src/lib/stores/sleep.ts: new
  • sleep-ui/src/routes/: +page.server.ts, +page.svelte, sleep/new, sleep/[id]/edit, day/[date]
  • sleep-ui/tests/: e2e.spec.ts, unit/csrf.spec.ts, unit/sleep.spec.ts

All backend tests and frontend unit tests pass locally.

…idation; add SleepListItem model and repo fns; document in OpenAPI; add integration tests
…ings, ConfirmDialog; CRUD routes (/sleep/new, /sleep/[id]/edit); day view; API helpers and stores
Copilot AI review requested due to automatic review settings August 21, 2025 19:57
Copy link
Contributor

Copilot AI left a comment

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 implements a comprehensive dashboard and sleep CRUD functionality for both the backend (Axum) and frontend (SvelteKit), adding essential list endpoints and visualization components.

Key Changes

  • Added new read-only endpoints for sleep data (/sleep/recent and /sleep/range) with session authentication
  • Implemented complete dashboard with week view, sleep visualization bars, and CRUD operations
  • Added comprehensive test coverage including Playwright e2e tests and Vitest unit tests

Reviewed Changes

Copilot reviewed 25 out of 26 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
sleep-api/src/app.rs Adds GET endpoints for recent and range sleep queries with parameter validation
sleep-api/src/repository.rs Implements database queries for listing sleep entries with proper ordering
sleep-api/src/models/sleep.rs Defines SleepListItem struct for API responses
sleep-ui/src/lib/api.ts Adds helper functions and types for sleep/exercise API interactions
sleep-ui/src/lib/components/ Creates reusable components for sleep visualization, forms, and confirmations
sleep-ui/src/routes/ Implements dashboard, create/edit/delete flows, and day view pages
sleep-ui/tests/ Adds comprehensive unit and e2e test coverage
sleep-ui/vitest.config.ts Configures Vitest for unit testing
Files not reviewed (1)
  • sleep-ui/package-lock.json: Language not supported

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@ebigunso ebigunso self-assigned this Aug 22, 2025
@ebigunso ebigunso changed the title PR-C: Dashboard, Sleep CRUD, Day View (SvelteKit) + Backend list endpoints ✨ Dashboard, Sleep CRUD, Day View (SvelteKit) + Backend list endpoints Aug 22, 2025
@ebigunso ebigunso merged commit 72c86d8 into main Aug 27, 2025
2 checks passed
@ebigunso ebigunso deleted the feature/2025-08-22/add-dashboard branch August 27, 2025 15:18
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.

2 participants