Commit graph

147 commits

Author SHA1 Message Date
Jon Seager
3a9fb16793
refactor(bags): replace multiple list methods with composable filter
- Add BagFilter struct with constructor methods (all, open, closed, for_roast)
- Replace 5 repository methods with single list(filter, request) method
- Add build_where_clause helper for dynamic WHERE clause construction
- Update all callers in bags and roasts routes

This eliminates method explosion when adding new filters - now only
BagFilter and build_where_clause need updating instead of adding
new repository methods.
2026-02-02 14:15:18 +00:00
Jon Seager
2d183e6955
refactor(routes): add macros to reduce route handler boilerplate
- Create define_get_handler! macro for GET-by-ID endpoints
- Create define_delete_handler! macro for DELETE endpoints with Datastar support
- Apply macros to roasters, roasts, and bags route modules
- Reduces 6 handlers from ~78 lines to ~12 lines total
2026-02-02 13:40:14 +00:00
Jon Seager
d689e48328
refactor(infra): standardize SQL query construction across repositories
- Add push_update_field! macro to reduce UPDATE query boilerplate
- Rename sort_clause() to order_clause() for consistency
- Convert bags.rs update method from string concatenation to QueryBuilder
- Apply macro to roasters.rs, roasts.rs, and bags.rs update methods

This reduces ~100 lines of repetitive code and ensures consistent
patterns for building dynamic UPDATE queries across all repositories.
2026-02-02 13:09:33 +00:00
Jon Seager
3e0aa1653f
chore(refactor): define macro for get/delete cli commands 2026-02-02 13:00:48 +00:00
Jon Seager
6611643424
chore: move RepositoryError into dedicated file 2026-02-02 12:57:15 +00:00
Jon Seager
ab9d4bfa13
feat: add amount to Bag Finished events 2025-11-27 15:10:17 +00:00
Jon Seager
f750107bb1
fix: add an action field to timeline events 2025-11-27 14:52:13 +00:00
Jon Seager
144257c2c8
fix: ensure bags are closed properly and closures are on the timeline 2025-11-27 14:42:38 +00:00
Jon Seager
673f76f09a
fix: ensure the list-bags command with no id lists all bags 2025-11-27 14:32:48 +00:00
Jon Seager
57260a71c2
fix: remove superfluous /bags/:id/finish endpoint 2025-11-27 14:24:26 +00:00
Jon Seager
7eab263071
chore: slight simplifications to bags 2025-11-27 14:03:00 +00:00
Jon Seager
d708a0e112
feat: add bags web views and templates 2025-11-27 14:02:55 +00:00
Jon Seager
f0cef61513
feat: add bags CLI commands 2025-11-27 14:02:38 +00:00
Jon Seager
ef6f30d6c3
feat: add bags API client 2025-11-27 14:01:40 +00:00
Jon Seager
dbfc6c4775
feat: add bags API urls 2025-11-27 13:59:39 +00:00
Jon Seager
14c3079600
feat: add bags domain and repositories 2025-11-27 13:56:06 +00:00
Jon Seager
02824a90f1
feat: add username/password flags to create-token command 2025-11-26 16:32:40 +00:00
Jon Seager
4358fa63dc
feat: add BREWLOG_ADMIN_USERNAME to select admin username on first start 2025-11-26 16:27:50 +00:00
Jon Seager
eabf69545f
feat: improved trace logging 2025-11-26 12:01:53 +00:00
Jon Seager
0119027e1a
chore: refactor client under infrastructure 2025-11-26 10:59:31 +00:00
Jon Seager
8aca3b92b7
chore: refactor cli and web under presentation 2025-11-26 10:48:25 +00:00
Jon Seager
e79db7c1d3
chore: rename server crate to application 2025-11-25 21:40:39 +00:00
Jon Seager
7df6cbcc51
fix: don't display delete icons when unauthenticated 2025-11-25 21:38:40 +00:00
Jon Seager
f88a880d07
feat!: update to a more human friendly url structure for roasters/roasts 2025-11-25 21:34:08 +00:00
Jon Seager
dd0f716437
chore: remove duplicated code for pagination 2025-11-25 19:56:50 +00:00
Jon Seager
d41cf7a86c
feat: switch to lax site policy for cookies 2025-11-25 19:15:29 +00:00
Jon Seager
7d4c7dda28
chore: remove unused code 2025-11-25 19:14:38 +00:00
Jon Seager
42d0f71eb1
feat!: use numeric, database-generated IDs throughout 2025-11-25 18:21:04 +00:00
Jon Seager
6e1053be8f
chore: clean up unused domain models and tables 2025-11-25 16:53:38 +00:00
copilot-swe-agent[bot]
e710c6dc62
refactor: improve code quality and add comprehensive documentation
Code Quality Improvements:
- Fix hex literal grouping in ID generator (0xB10C_1D -> 0x00B1_0C1D)
- Rename ListQuery::default() to default_query() to avoid confusion with Default trait
- Use div_ceil() instead of manual ceiling division
- Remove unnecessary borrows in auth token generation and hashing
- Simplify nested if statements in error handling

Documentation:
- Add comprehensive authentication section to README
- Document environment variables for server and CLI
- Add security best practices and considerations
- Document password hashing (Argon2id), token storage (SHA-256), and session management
- Include step-by-step authentication setup guide
- Add production deployment recommendations

All 70 tests pass (8 unit + 46 server + 16 CLI) 

Co-authored-by: jnsgruk <668505+jnsgruk@users.noreply.github.com>
2025-11-25 16:28:51 +00:00
copilot-swe-agent[bot]
b46295d0cf
fix(auth): support session cookie authentication in API endpoints
- Update AuthenticatedUser extractor to check session cookies first
- Add authenticate_via_session() helper function
- Session cookies now work for all API write operations
- Change SameSite to Strict for better CSRF protection
- Add BREWLOG_SECURE_COOKIES env var to enable secure flag in production

This fixes the bug where authenticated frontend users got 401 errors
when submitting forms. API endpoints now accept both Bearer tokens
and session cookies for authentication.

All 65 tests pass (8 unit + 42 server + 15 CLI) 

Co-authored-by: jnsgruk <668505+jnsgruk@users.noreply.github.com>
2025-11-25 16:28:49 +00:00
copilot-swe-agent[bot]
4c040f2c58
fix(security): validate session tokens against database
- Add sessions table to store session tokens with expiration
- Create Session domain model and SessionRepository trait
- Implement SqlSessionRepository for session persistence
- Update is_authenticated() to validate tokens against database
- Sessions expire after 30 days
- Session tokens hashed with SHA-256 before storage
- Delete sessions from database on logout
- Update all page handlers to properly validate sessions

This prevents session hijacking by ensuring only valid, unexpired
tokens stored in the database can authenticate requests.

Co-authored-by: jnsgruk <668505+jnsgruk@users.noreply.github.com>
2025-11-25 16:28:48 +00:00
copilot-swe-agent[bot]
e6811d45ad
feat(frontend): add login page and session-based authentication
- Add tower and tower-cookies dependencies for session management
- Create login page template with username/password form
- Implement /login and /logout routes with cookie-based sessions
- Update navigation bar to show Login/Logout based on auth state
- Add is_authenticated field to all page templates
- Hide create/update/delete UI controls when unauthenticated
- Session tokens stored in secure HttpOnly cookies with SameSite=Lax
- Password verification uses constant-time comparison via Argon2

Co-authored-by: jnsgruk <668505+jnsgruk@users.noreply.github.com>
2025-11-25 16:28:47 +00:00
copilot-swe-agent[bot]
0e35d18a21
fix(client): use request() helper for all client methods to include auth token
Co-authored-by: jnsgruk <668505+jnsgruk@users.noreply.github.com>
2025-11-25 16:28:13 +00:00
copilot-swe-agent[bot]
97aaf9311d
fix(api): use TokenResponse DTO to exclude sensitive token_hash field
Co-authored-by: jnsgruk <668505+jnsgruk@users.noreply.github.com>
2025-11-25 16:28:12 +00:00
copilot-swe-agent[bot]
5c05f35a59
fix(auth): make AuthenticatedUser extractor perform authentication directly
Co-authored-by: jnsgruk <668505+jnsgruk@users.noreply.github.com>
2025-11-25 16:28:12 +00:00
copilot-swe-agent[bot]
5f4cbf5294
fix(auth): enforce authentication on write operations and fix CLI token auth
Co-authored-by: jnsgruk <668505+jnsgruk@users.noreply.github.com>
2025-11-25 16:28:11 +00:00
copilot-swe-agent[bot]
6d0ee869f7
feat(api): add authentication middleware and token management routes
Co-authored-by: jnsgruk <668505+jnsgruk@users.noreply.github.com>
2025-11-25 16:28:10 +00:00
copilot-swe-agent[bot]
0b9cfefce5
feat(cli): add token management commands
Co-authored-by: jnsgruk <668505+jnsgruk@users.noreply.github.com>
2025-11-25 16:28:09 +00:00
copilot-swe-agent[bot]
d96f2c27e0
feat(auth): add password hashing, token generation, and admin bootstrap
Co-authored-by: jnsgruk <668505+jnsgruk@users.noreply.github.com>
2025-11-25 16:28:03 +00:00
copilot-swe-agent[bot]
ca5d25ea10
feat(domain): add auth database schema and domain models
Co-authored-by: jnsgruk <668505+jnsgruk@users.noreply.github.com>
2025-11-25 16:27:51 +00:00
Jon Seager
4f69d20bb1
feat: add pagination/infinite scroll to timeline 2025-11-24 21:45:59 +00:00
Jon Seager
8a445c4212
test: add some unit tests for datastar helpers 2025-11-24 18:06:43 +00:00
Jon Seager
228306487e
refactor(roasts): simplify tasting note parsing 2025-11-24 11:44:17 +00:00
Jon Seager
fb9fb6cc23
refactor(roasts): require roast metadata 2025-11-24 11:44:16 +00:00
Jon Seager
90390c17ba
refactor(routes): share pagination helpers 2025-11-24 11:44:15 +00:00
Jon Seager
3241f3c961
feat: bootstrap brewlog platform 2025-11-24 11:44:12 +00:00