diff options
Diffstat (limited to 'internal/commands/helpers.go')
-rw-r--r-- | internal/commands/helpers.go | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/internal/commands/helpers.go b/internal/commands/helpers.go new file mode 100644 index 0000000..a0c572b --- /dev/null +++ b/internal/commands/helpers.go @@ -0,0 +1,32 @@ +package commands + +import ( + "context" + "errors" + "punchcard/internal/actions" + "punchcard/internal/queries" +) + +// ErrNoActiveTimer is returned when trying to punch out but no timer is active +var ErrNoActiveTimer = errors.New("no active timer found") + +// Helper functions for commands that need to find clients/projects +// These wrap the actions package for backward compatibility + +func findClient(ctx context.Context, q *queries.Queries, clientRef string) (queries.Client, error) { + a := actions.New(q) + client, err := a.FindClient(ctx, clientRef) + if err != nil { + return queries.Client{}, err + } + return *client, nil +} + +func findProject(ctx context.Context, q *queries.Queries, projectRef string) (queries.Project, error) { + a := actions.New(q) + project, err := a.FindProject(ctx, projectRef) + if err != nil { + return queries.Project{}, err + } + return *project, nil +}
\ No newline at end of file |