Extract service/store layer from API handlers #13

Open
opened 2026-03-16 21:29:35 +00:00 by austin · 0 comments
Owner

All SQL queries are currently inline in the HTTP handlers (internal/api/projects.go, internal/api/issues.go). This makes the code hard to test and the handlers too thick.

What needs to happen

Create internal/store/ with a Store struct wrapping *sql.DB. Methods like:

  • ListProjects(ctx context.Context) ([]models.Project, error)
  • CreateProject(ctx context.Context, input CreateProjectInput) (*models.Project, error)
  • ListIssues(ctx context.Context, projectKey string, filters IssueFilters) ([]models.Issue, error)
  • CreateIssue(ctx context.Context, projectKey string, input CreateIssueInput) (*models.Issue, error)
  • etc.

Handlers become thin: parse request → call store → write response. This is the repository pattern, very standard in Go.

Keep it as a concrete struct with concrete methods. Do not create an interface yet — interfaces come later when you actually need to mock for tests.

Key files

  • internal/api/issues.go — SQL to extract
  • internal/api/projects.go — SQL to extract
  • internal/store/ — new package
All SQL queries are currently inline in the HTTP handlers (`internal/api/projects.go`, `internal/api/issues.go`). This makes the code hard to test and the handlers too thick. ## What needs to happen Create `internal/store/` with a `Store` struct wrapping `*sql.DB`. Methods like: - `ListProjects(ctx context.Context) ([]models.Project, error)` - `CreateProject(ctx context.Context, input CreateProjectInput) (*models.Project, error)` - `ListIssues(ctx context.Context, projectKey string, filters IssueFilters) ([]models.Issue, error)` - `CreateIssue(ctx context.Context, projectKey string, input CreateIssueInput) (*models.Issue, error)` - etc. Handlers become thin: parse request → call store → write response. This is the repository pattern, very standard in Go. Keep it as a concrete struct with concrete methods. Do not create an interface yet — interfaces come later when you actually need to mock for tests. ## Key files - `internal/api/issues.go` — SQL to extract - `internal/api/projects.go` — SQL to extract - `internal/store/` — new package
austin added this to the CLI Core milestone 2026-03-16 21:29:35 +00:00
austin self-assigned this 2026-03-16 21:29:35 +00:00
austin added this to the Vektor - CLI project 2026-03-16 21:29:35 +00:00
Sign in to join this conversation.
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
austin/vektor#13
No description provided.