Commit Graph
37 Commits
Author SHA1 Message Date
aksdb 0bfacb7059 🐛 Reject week keys that are not real ISO weeks
WeekDayKeys accepted W01 to W53 without checking that the year has that
week. Closing 2025-W53, a year with 52 weeks, closed the days of
2026-W01 under a second key and the balance counted them twice. The
computed Monday must now map back to the requested week key.
2026-12-01 16:43:40 +01:00
aksdb 9f0700fa1c 🐛 Reject invalid changes instead of failing the whole sync batch
Every whitelisted field was written, so a tombstone or a partial change
without the required fields failed the validation and rolled back the
whole batch with 400, which a client would retry forever. Only the keys
present in the change are set now, a change is validated on its own and
answered as invalid with the message, and a tombstone for an unknown
row is answered ok without writing anything.
2026-12-01 16:41:57 +01:00
aksdb 8898d976e6 🐛 Keep tombstones when replacing data in the legacy import
Clients only pull changed rows and never learn about hard deletes, so
a row they already pulled survived as a ghost: it kept winning against
imported rows with the same effective_from. Existing rows now become
tombstones. Closed days and weeks are overwritten in place when an
imported row has the same key, so their unique index holds.
2026-12-01 16:37:26 +01:00
aksdb cb2d090ffc 🗑️ Remove legacy SQLite store, services and handlers 2026-11-29 20:28:10 +00:00
aksdb 611a2d105a 🧪 Test day and week closing rules 2026-11-29 20:27:12 +00:00
aksdb 9489952842 ✨ Export entries, days and weeks as CSV 2026-11-29 20:24:54 +00:00
aksdb 1edaf75e4b ✨ Seed settings for new users and auto-stop stale entries 2026-11-29 20:24:48 +00:00
aksdb 31b404e27a ✨ Add day and week closing on PocketBase records 2026-11-29 20:24:40 +00:00
aksdb 39e0f69342 🧪 Test legacy import
The tests build a legacy SQLite fixture from the old migrations and
cover the field mapping, skipped invalid rows, the replace-on-rerun
behaviour, the dry run and the guarantee that the legacy file and its
directory stay untouched.
2026-11-29 20:24:32 +00:00
aksdb e190c5c919 ✨ Add import-legacy command for the SQLite database
The command copies the tables of the old wotra.db into the PocketBase
records of one user, so the tracked time survives the move to the new
backend. The legacy file is only ever read; a dry run shows what would
be imported without writing anything.
2026-11-29 20:24:29 +00:00
aksdb fcb008dd57 🧪 Test sync push endpoint
Covers create, update, stale, forbidden and readonly answers, the
guard for the last settings row, request validation, the missing auth
token and that a failing change rolls back the whole batch. Also
checks that regular users cannot write synced collections over REST
and that superuser writes keep the owner and rev consistent.
2026-11-29 17:03:45 +00:00
aksdb f63fe1b549 ✨ Add batch push endpoint for synced collections
POST /api/sync/push applies up to 500 client changes of a signed-in
user in one transaction. Every change is answered with ok, stale,
forbidden or readonly, so the client can reconcile its local state
with the server state.

closed_days and closed_weeks are answered as readonly because only
the server computes them. The last remaining settings row of a user
cannot be deleted either; such a change is answered as stale, which
clients already treat as "server wins".
2026-11-29 17:03:42 +00:00
aksdb a2507d22d3 ✨ Scaffold PocketBase app with embedded UI
Add PocketBase v0.40.6 as a dependency together with the pieces the
new backend is built from: the list of synced collections with their
client-writable fields, the initial migration that creates the five
per-user collections (entries, closed_days, closed_weeks,
settings_history, balance_adjustments), and empty Register stubs for
the tracking and legacy import packages.

Clients only get read access to their own rows over REST; writes are
meant to go through the sync push endpoint. web/build is now ignored
except for a tracked placeholder so the built SPA can be embedded.

The entry point (main.go) and the UI embedding (ui.go) are not part
of this commit: the repo root is still the legacy "assets" package,
and Go does not allow "package main" in the same directory.
2026-11-29 16:58:41 +00:00
aksdb ab5749107c ♻️ Bootstrap when syncmarker is zero 2026-08-20 15:53:39 +00:00
aksdb 29284a024d 🐛 Fix sync from zero 2026-08-20 17:35:43 +02:00
aksdb babc9a8096 🧪 Reproduce failing sync from zero 2026-08-20 16:42:08 +02:00
aksdb 8cd58fbd2c fix: closing the week early should count properly 2026-05-13 20:47:39 +00:00
aksdb c617012401 test: expect proper midweek handling 2026-05-13 20:44:14 +00:00
aksdb ca5f5f95e2 refactor: introduce clock to make tests reproducible 2026-05-13 20:24:56 +00:00
aksdb a8a4ea0d4f M9.1: wire sync logging into all mutation paths
- Add LogClosedDayDelete and LogClosedWeekDelete to SyncStore
- Inject syncStore into EntryService; log Start, Stop, StopByID,
  Update, CreateInterval, Delete, AutoStopStalledEntries
- Inject syncStore into DayService; log CloseDay, MarkDay, ReopenDay,
  and the recomputeWeek closed-week upsert
- Inject syncStore into SettingsService; log Upsert, UpdateSettings,
  DeleteSettings
- Add LogClosedWeek/LogClosedWeekDelete calls in WeekService.CloseWeek
  and ReopenWeek
- Update main.go and all service test helpers for new constructor signatures
- All Go tests and 19 Vitest tests pass
2026-04-30 22:57:02 +02:00
aksdb d8366f5c25 Add sync redesign with offline fallback (M9)
- Migration 003: adds logged_at to sync_log for TTL pruning; migrates
  settings_history to UUID TEXT PK with updated_at column
- SyncStore: Prune() deletes rows older than 30d and writes a '_pruned'
  marker at the boundary version; Pull() calls Prune lazily and returns
  ErrSyncStale (410) when the client's since_version is behind the marker
- sync_handler.go: GET /api/sync/pull?since=N; POST /api/sync/push with
  last-updated_at-wins conflict resolution for entries, balance_adjustments,
  settings_history; closed_days/closed_weeks skipped (server-only mutations)
- router.go: passes entryStore, adjustmentStore, settingsStore to SyncHandler
- settings_store.go: UUID PK, updated_at column, Upsert() for push path
- settings_service.go: generates UUID on create, sets updated_at on update
- settings_handler.go: ID params changed from int64 to string
- domain.go: Settings.ID string, Settings.UpdatedAt added
- client.ts: all mutation methods catch TypeError (offline) and fall back
  to Dexie write + outbox enqueue; crypto.randomUUID() for offline creates;
  Settings.id type changed to string
- db.ts: Dexie v3 — settings_history key path changed to string UUID;
  upgrade handler clears table for repopulation via pull
- sync.ts: real pushOutbox to POST /api/sync/push; pullChanges uses GET
  with ?since=N; 410 triggers coldStart() + retry; coldStart() wipes all
  tables and resets last_version
- 4 new Go store tests covering normal pull, stale client, empty prune,
  client-ahead-of-marker; all tests pass (store + service, 19 Vitest)
2026-04-30 22:50:33 +02:00
aksdb 3214f48a6f Add balance adjustments (M8)
- New balance_adjustments table with CRUD store, sync logging, and service methods
- SQL migrations restructured: embed fs.FS from internal/store/migrations/, apply in order via user_version
- WeekService.Balance combines closed-weeks delta + adjustments delta; BalanceSummary breakdown
- Four REST routes: GET/POST /api/balance/adjustments, PUT/DELETE /api/balance/adjustments/{id}
- Dexie schema v2 + sync apply cases for balance_adjustments
- API client: BalanceAdjustment type, balance namespace (list/create/update/delete)
- utils: composeDeltaMs / decomposeDeltaMs helpers + 8 new Vitest tests (19 total, all passing)
- History page: balance card breakdown line + full adjustments section with inline add/edit/delete
2026-04-30 21:50:57 +02:00
aksdb 8ca838fa6e feat: overall overtime balance on history page
Backend:
- ClosedWeekStore.SumDelta: single SQL aggregate returning total delta_ms and
  row count across all closed_weeks
- WeekService.Balance: thin passthrough returning BalanceResult{TotalDeltaMs, ClosedWeekCount}
- GET /api/weeks/balance handler; route registered alongside /weeks list/close/reopen
- Tests: store-level SumDelta (empty + populated), service-level Balance (empty + 2 weeks)

Frontend:
- weeks.balance() added to API client
- History page: balance card at top, fetched in parallel with existing data
- Loading state shows '—'; once loaded shows formatDelta value in green/red/gray
- Shows 'across N closed weeks' count alongside the value
2026-04-30 20:01:24 +02:00
aksdb 15bf3c3a18 feat: edit and delete settings history rows
Backend:
- SettingsStore: Add GetByID, Update, Delete, Count methods
- SettingsService: Add UpdateSettings (validates same rules as Upsert),
  DeleteSettings (guards against deleting the last row → 409)
- New sentinels: ErrSettingsNotFound, ErrLastSettingsRow
- Handler: PUT /api/settings/history/{id} → 200 updated row
           DELETE /api/settings/history/{id} → 204 / 404 / 409

Frontend:
- API client: settings.update(id, body) and settings.delete(id)
- Settings page: history table gains edit (pencil) and delete (×) buttons
- Inline edit form expands in place within the table row
- Delete button disabled and hint shown when only one row remains
- maskLabel() helper shows workday names instead of raw bitmask
- After save/delete: full reload to reflect changes in 'current' section
2026-04-30 19:50:27 +02:00
aksdb bf0c728818 fix(entries): reject create/update of intervals in the future
- Add ErrFutureDay sentinel error
- CreateInterval: rejects if startDayKey > todayKey (400)
- Update: rejects if new start_time moves entry to a future day (400)
- Handler maps ErrFutureDay → 400 Bad Request for both endpoints
- Add TestCreateIntervalRejectsFutureDay
- Add TestUpdateRejectsMoveToFutureDay
- UI already gates this via dayCapabilities (canAddInterval=false,
  canEditEntries=false for future days), but server now enforces it too
2026-04-30 19:09:22 +02:00
aksdb 47dd2c9779 fix: CloseWeek uses settings effective at close time, not week Monday
Settings configured mid-week (e.g. Thursday) have an effective_from
of that date. CloseWeek was looking up settings as-of Monday, which
predates the new settings row and fell back to the old default.

Now uses today's date for the settings lookup, so any settings change
made before closing the week is correctly reflected in expected_ms.
2026-04-30 18:23:13 +02:00
aksdb e37458f513 fix: weekDayKeys formula breaks when Jan 4 falls on Sunday
The naive formula used (jan4.Weekday() - time.Monday) produces -1
when Jan 4 is a Sunday (Weekday()==0), shifting the computed Monday
one week forward. 2026 is affected: Jan 4 is a Sunday, so every
week key in 2026 was mapped to the wrong 7-day range, causing
CloseWeek to look for closed_days on the wrong dates and finding
nothing — resulting in worked_ms=0 and a full -Nh delta.

Fix: use (weekday+6)%7 to get days-since-Monday (Mon=0…Sun=6),
which is always non-negative.

Adds table-driven TestWeekDayKeys covering 2024 (Thu), 2026 (Sun),
and 2023 (Wed) to prevent regression.
2026-04-30 18:20:37 +02:00
aksdb 47c7a97d47 fix: keep closed week snapshot in sync when days change
When a day is closed, re-closed, or reopened, DayService now
recomputes worked_ms and delta_ms on the closed week containing
that day (if the week is already closed). This prevents stale
delta values after editing entries and re-closing a day.

- DayService.recomputeWeek: sums worked_ms from all closed_days
  in the week, updates closed_weeks row preserving expected_ms
- NewDayService now takes ClosedWeekStore
- WeekKeyForDayKey exported helper (used by DayService)
- TestWeekSnapshotUpdatesWhenDayReopened regression test
2026-04-30 18:16:22 +02:00
aksdb c675a7b01d fix: skip untracked workdays when closing a week
Previously any past workday without a closed_days record blocked week
close. Now only days that actually have entries require an explicit
close. Empty workdays count as 0h worked, which is reflected in the
weekly delta automatically.

- WeekService.CloseWeek: after finding no closed_days record, check
  whether the day has any entries; only error if it does
- NewWeekService: takes EntryStore to support the above check
- Updated TestCloseWeekMissingDayFails to reflect the new semantic
  (test now creates entries on Friday but leaves it unclosed)
2026-04-30 17:59:04 +02:00
aksdb 6fceda46b5 fix: allow closing current week when future workdays are not yet closed
CloseWeek was requiring every workday in the ISO week to have a
closed_days record, including days in the future. Now only workdays
up to and including today are checked; future workdays are skipped.

Adds TestCloseWeekMidWeek regression test.
2026-04-30 17:54:38 +02:00
aksdb 9d6233b116 feat: add manual interval creation and inline entry editing
- Service: CreateInterval() validates same-day, end>start, day not closed
- Service: Update() now rejects edits on closed-day entries (ErrDayAlreadyClosed)
- Handler: POST /api/entries creates a completed interval with explicit times
- API client: entries.createInterval(startMs, endMs, note)
- Utils: parseTimeInput / toTimeInput helpers for HH:MM <-> unix ms
- Today page: '+ Add interval' form (time pickers + optional note)
- Today page: pencil button on each entry opens inline edit row (start/end/note)
- Tests: TestCreateInterval, TestCreateIntervalEndBeforeStart,
         TestCreateIntervalCrossesMidnight, TestUpdateRejectsClosedDay
2026-04-30 17:45:02 +02:00
aksdb 2055a46dee feat(m6): CSV export, Makefile, README, single-binary build 2026-04-30 16:48:44 +02:00
aksdb 4a328ad6cc feat(m5): PWA service worker, offline Dexie store, outbox, sync endpoints 2026-04-30 16:47:27 +02:00
aksdb df04d9d7a9 feat(m4): SvelteKit frontend - today, week, history, settings views 2026-04-30 16:45:00 +02:00
aksdb d0ef0387f2 feat(m3): week close, overtime/undertime delta, frozen settings snapshot 2026-04-30 16:39:42 +02:00
aksdb 4a0e0c8318 feat(m2): settings history, close day, holiday/vacation/sick marking 2026-04-30 16:37:56 +02:00
aksdb 3aa068efd2 feat(m1): backend scaffold - entries CRUD, start/stop, auth, migrations 2026-04-30 16:35:06 +02:00