Skip to content

refactor(store): wave B.18 — assignment repo (closes action chain) (#279)#280

Merged
PaulDotterer merged 1 commit into
mainfrom
feat/279-assignment-repo
May 15, 2026
Merged

refactor(store): wave B.18 — assignment repo (closes action chain) (#279)#280
PaulDotterer merged 1 commit into
mainfrom
feat/279-assignment-repo

Conversation

@PaulDotterer

@PaulDotterer PaulDotterer commented May 15, 2026

Copy link
Copy Markdown
Contributor

Summary

`AssignmentRepo` closes the action-chain migration (Action #271 → ActionSet #273 → Definition #275 → Execution #277 → Assignment). Branches off main.

Methods

  • `Get(key)` — composite (source, target) lookup
  • `GetByID(id)`
  • `List(filter)` — returns `AssignmentWithNames` (joined source_name + target_name); 4-axis filter shared with Count
  • `Count(filter)`
  • `ListAvailableForDevice(deviceID)` — available-mode assignments resolving to device (user-selection catalog)
  • `ListAssignedUserIDsForDevice(deviceID)` — narrow string-list lookup

Non-goals (join shapes — defer)

  • `ListAssignedActionsForDevice` (action data — lives on action-domain seam)
  • `ListDirectAssignmentsForDevice` / `ListGroupAssignmentsForDevice` (join-row shapes)
  • `ListAssignmentsForUser` — different row shape; transitional inline conversion at the one call site

Call sites migrated

  • `assignment_handler.go` — full CRUD + `assignmentToProto` signature
  • `user_selection_handler.go` — 2 sites
  • `device_handler.go` — `ListDeviceAssignedUserIDs`

Acceptance

  • Build / vet / staticcheck / gofmt: clean.
  • Tests pass: api (1m57s).

Part of #242. Closes #279.

Summary by CodeRabbit

  • Refactor
    • Internal refactor of assignment and device handling for greater consistency and maintainability.
    • No changes to public APIs or user-visible behavior; listing, selection, and token flows remain unchanged.
    • Improves reliability of assignment listings, counts, and device-related checks without impacting end-user workflows.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 15, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 258bdab1-e982-45bb-902c-c88d7d1e5346

📥 Commits

Reviewing files that changed from the base of the PR and between c43586f and 3b671cc.

📒 Files selected for processing (7)
  • internal/api/assignment_handler.go
  • internal/api/device_handler.go
  • internal/api/user_selection_handler.go
  • internal/store/assignment.go
  • internal/store/postgres/assignment.go
  • internal/store/postgres/wire.go
  • internal/store/repos.go
🚧 Files skipped from review as they are similar to previous changes (7)
  • internal/store/postgres/wire.go
  • internal/api/device_handler.go
  • internal/store/repos.go
  • internal/store/assignment.go
  • internal/api/user_selection_handler.go
  • internal/store/postgres/assignment.go
  • internal/api/assignment_handler.go

📝 Walkthrough

Walkthrough

Adds a store-level Assignment domain, a Postgres-backed AssignmentRepo, wires it into Repos, and updates handlers to call the new repository methods instead of direct sqlc query-layer calls.

Changes

Assignment Repository Migration

Layer / File(s) Summary
Domain types and repository interface
internal/store/assignment.go
Assignment, AssignmentWithNames, AssignmentKey, list/count filter structs, and AssignmentRepo interface with Get, GetByID, List, Count, ListAvailableForDevice, and ListAssignedUserIDsForDevice.
Postgres repository implementation
internal/store/postgres/assignment.go
Postgres-backed Assignment repo wrapping sqlc Queries and implementing all AssignmentRepo read methods, row mapping helper, and not-found translation.
Repository registration and wiring
internal/store/repos.go, internal/store/postgres/wire.go
Adds Assignment AssignmentRepo to Repos and initializes it with NewAssignment(q) in NewRepos.
Handler call-site migrations
internal/api/assignment_handler.go, internal/api/device_handler.go, internal/api/user_selection_handler.go
Handlers switched from Queries() to Repos().Assignment for assignment lookups and lists; assignmentToProto now accepts store.Assignment; transitional conversions added where query-shaped rows remain in use.

Sequence Diagram

sequenceDiagram
  participant Handler as API Handler
  participant Repo as AssignmentRepo
  participant DB as Postgres/sqlc

  Handler->>Repo: Get(AssignmentKey) / List(filter) / Count(filter)
  Repo->>DB: corresponding sqlc query (GetAssignment / ListAssignments / CountAssignments)
  DB-->>Repo: rows or count
  Repo-->>Handler: domain Assignment / AssignmentWithNames / count
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

  • #271: wave B.18: assignment repo — This PR implements the AssignmentRepo read-side and migrates handlers as described in the issue.

Possibly related PRs

Poem

🐰 Hopped from queries to a tidy repo nest,
Rows mapped to types, each field dressed,
Handlers now call where interfaces lie,
Postgres replies, neat domains reply,
A little rabbit cheers this code-refactor fest.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: implementing AssignmentRepo to complete the action-chain migration, which is the primary focus of the PR.
Linked Issues check ✅ Passed All coding objectives from issue #279 are met: AssignmentRepo methods (Get, GetByID, List, Count, ListAvailableForDevice, ListAssignedUserIDsForDevice) implemented; AssignmentWithNames with joined names provided; 4-axis filter shape created; device-targeting reads implemented; call sites in assignment_handler, user_selection_handler, and device_handler migrated; acceptance criteria (build/vet/staticcheck/gofmt clean, tests passing) satisfied.
Out of Scope Changes check ✅ Passed All changes are scoped to the AssignmentRepo implementation and its integration. Non-goals (ListAssignedActionsForDevice, ListDirectAssignmentsForDevice, ListGroupAssignmentsForDevice, ListAssignmentsForUser) are deferred as intended; inline conversion for ListAssignmentsForUser mentioned in PR summary aligns with the non-goals statement.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/279-assignment-repo

Comment @coderabbitai help to get the list of available commands and usage tips.

AssignmentRepo closes the action-chain migration (Action → ActionSet
→ Definition → Execution → Assignment). Read side of
assignments_projection:

  Get / GetByID / List(filter) / Count(filter) /
  ListAvailableForDevice / ListAssignedUserIDsForDevice

List returns AssignmentWithNames (joined source_name + target_name)
for the list UI. ListAvailableForDevice serves the user-selection
catalog; ListAssignedUserIDsForDevice is the narrow string-list
used by device_handler.

Non-goals (join-row shapes — defer):
- ListAssignedActionsForDevice (returns action data — lives on the
  action-domain seam)
- ListDirectAssignmentsForDevice / ListGroupAssignmentsForDevice
  (join-row shapes)
- ListAssignmentsForUser (different row shape — transitional inline
  conversion at the one call site for now)

Call sites migrated:
- assignment_handler.go (Create/Delete/Get/List/Count +
  assignmentToProto signature)
- user_selection_handler.go (ListAvailableAssignmentsForDevice ×2)
- device_handler.go (ListDeviceAssignedUserIDs)

Closes #279.
@PaulDotterer PaulDotterer force-pushed the feat/279-assignment-repo branch from c43586f to 3b671cc Compare May 15, 2026 23:39
@PaulDotterer PaulDotterer merged commit 086bb2c into main May 15, 2026
5 checks passed
@PaulDotterer PaulDotterer deleted the feat/279-assignment-repo branch May 15, 2026 23:56
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.

wave B.18: assignment repo (closes action chain)

1 participant