From 665bd389a0a1c8adadcaa1122e846cc81f5ead31 Mon Sep 17 00:00:00 2001 From: T Date: Tue, 5 Aug 2025 11:37:02 -0600 Subject: WIP TUI --- internal/commands/out.go | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) (limited to 'internal/commands/out.go') diff --git a/internal/commands/out.go b/internal/commands/out.go index f98a63c..1355f3d 100644 --- a/internal/commands/out.go +++ b/internal/commands/out.go @@ -1,18 +1,16 @@ package commands import ( - "database/sql" "errors" "fmt" "time" + "punchcard/internal/actions" punchctx "punchcard/internal/context" "github.com/spf13/cobra" ) -var ErrNoActiveTimer = errors.New("no active timer found") - func NewOutCmd() *cobra.Command { return &cobra.Command{ Use: "out", @@ -25,23 +23,18 @@ func NewOutCmd() *cobra.Command { return fmt.Errorf("database not available in context") } - // Stop the active timer by setting end_time to now - stoppedEntry, err := q.StopTimeEntry(cmd.Context()) + a := actions.New(q) + session, err := a.PunchOut(cmd.Context()) if err != nil { - if errors.Is(err, sql.ErrNoRows) { + if errors.Is(err, actions.ErrNoActiveTimer) { return ErrNoActiveTimer } - return fmt.Errorf("failed to stop timer: %w", err) + return err } - // Calculate duration - duration := stoppedEntry.EndTime.Time.Sub(stoppedEntry.StartTime) - // Output success message - cmd.Printf("Timer stopped. Session duration: %v\n", duration.Round(time.Second)) - - // Show entry ID for reference - cmd.Printf("Time entry ID: %d\n", stoppedEntry.ID) + cmd.Printf("Timer stopped. Session duration: %v\n", session.Duration.Round(time.Second)) + cmd.Printf("Time entry ID: %d\n", session.ID) return nil }, -- cgit v1.2.3