Skip to content

Backend Notifications: 2 - Application#266

Merged
danctila merged 3 commits intomainfrom
danc/notifications-backend
Apr 4, 2026
Merged

Backend Notifications: 2 - Application#266
danctila merged 3 commits intomainfrom
danc/notifications-backend

Conversation

@danctila
Copy link
Copy Markdown
Contributor

@danctila danctila commented Apr 4, 2026

Description

Implements the backend notification foundation.

When a task is created with an assigned user, that user is notified immediately - both as a persistent in-app notification (stored in db) and as a mobile push (sent to any registered Expo push tokens). The goal is to establish the pattern so different notification types (high-priority unassigned tasks, guest arrival, etc.) can be added later if we want

Type of Change

  • New feature (non-breaking change that adds functionality)

Related Issue(s)

Stacked on: #265
Closes: #97

What Changed?

  • Added NotificationsRepository - insert, list, mark read, mark all read, upsert/query device tokens
  • Added notifications.Service - persists the in-app notification then fire-and-forgets Expo push via goroutine to any registered device tokens
  • Added NotificationsHandler with four endpoints: GET /notifications, PUT /notifications/:id/read, PUT /notifications/read-all, POST /device-tokens
  • Added NotificationSender interface to RequestsHandler; CreateRequest and GenerateRequest now trigger a task_assigned notification when user_id is set
  • handler test coverage for all four endpoints

How it works / (🤞 will work) with web and mobile

Web - poll GET /api/v1/notifications (via a useNotifications TanStack Query hook with some stale timeout) to drive the notification somewhere in the UI. Call PUT /notifications/:id/read or PUT /notifications/read-all when the user opens the panel.

Mobile - on app startup, call expo-notifications to get the device's ExpoPushToken, then POST /api/v1/device-tokens with the token and platform (ios/android). From that point the backend will deliver push notifications through Expo's push service whenever the user is assigned a task, even when the app is backgrounded.

Testing & Validation

How this was tested

  1. go build ./... compiles
  2. go test ./internal/handler/... -v handler tests pass (existing + new)
  3. Linting passes
CleanShot 2026-04-04 at 15 02 50@2x

Unfinished Work & Known Issues

  • The following items are intentionally deferred:
    • Web UI changes / hookup to endpoints
    • Mobile expo-notifications registration flow

Notes & Nuances

  • NotificationSender is nilable on RequestsHandler - if nil, notifications are silently skipped. This keeps existing tests unaffected (they pass nil) and makes the it safer to deploy before the frontend is wired up
  • Expo push is fire-and-forget in a goroutine. Push failures are logged with slog but never fail the originating API call so a push outage shoulnd't break task creation

Pre-Merge Checklist

Code Quality

  • Code follows the project's style guidelines and conventions
  • Self-review completed (I've reviewed my own code for obvious issues)
  • No debugging code, console logs, or commented-out code left behind
  • No merge conflicts with the base branch
  • Meaningful commit messages that explain the "why"

Testing & CI

  • All CI checks are passing
  • All new and existing tests pass locally
  • Test coverage hasn't decreased (or decrease is justified)
  • Linting passes without errors

Documentation

  • Code is self-documenting or includes helpful comments for complex logic
  • API documentation updated (if backend endpoints changed)
  • Type definitions are accurate and up-to-date

@danctila danctila self-assigned this Apr 4, 2026
@danctila danctila added feature Introduces a new and complete feature feat(urethon) labels Apr 4, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 4, 2026

Codecov Report

❌ Patch coverage is 23.27044% with 122 lines in your changes missing coverage. Please review.
✅ Project coverage is 18.52%. Comparing base (5e24a28) to head (a46c503).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
backend/internal/repository/notifications.go 0.00% 73 Missing ⚠️
backend/internal/service/notifications/service.go 0.00% 29 Missing ⚠️
backend/internal/service/server.go 0.00% 12 Missing ⚠️
backend/internal/handler/requests.go 25.00% 4 Missing and 2 partials ⚠️
backend/internal/handler/notifications.go 94.59% 1 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #266      +/-   ##
==========================================
+ Coverage   18.12%   18.52%   +0.40%     
==========================================
  Files          42       45       +3     
  Lines        1727     1884     +157     
==========================================
+ Hits          313      349      +36     
- Misses       1408     1526     +118     
- Partials        6        9       +3     
Flag Coverage Δ
backend 18.52% <23.27%> (+0.40%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
backend/internal/handler/notifications.go 94.59% <94.59%> (ø)
backend/internal/handler/requests.go 79.72% <25.00%> (-3.37%) ⬇️
backend/internal/service/server.go 0.00% <0.00%> (ø)
backend/internal/service/notifications/service.go 0.00% <0.00%> (ø)
backend/internal/repository/notifications.go 0.00% <0.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@danctila danctila requested a review from Dao-Ho April 4, 2026 19:00
Copy link
Copy Markdown
Contributor

@Dao-Ho Dao-Ho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some smol nits but looks good otherwise 🐐 ✅

danctila added 3 commits April 4, 2026 15:25
leaving these custom errors in the notifs package bc they won't be used anyhwere else
@danctila danctila force-pushed the danc/notifications-backend branch from 2515105 to a46c503 Compare April 4, 2026 19:26
@danctila danctila requested a review from Dao-Ho April 4, 2026 19:28
Copy link
Copy Markdown
Contributor

@Dao-Ho Dao-Ho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM ✅

@danctila danctila merged commit 286f501 into main Apr 4, 2026
6 checks passed
@danctila danctila deleted the danc/notifications-backend branch April 4, 2026 19:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat(urethon) feature Introduces a new and complete feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Backend Notification architecture

2 participants