summaryrefslogtreecommitdiff
path: root/internal/commands/out.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/commands/out.go')
-rw-r--r--internal/commands/out.go21
1 files changed, 7 insertions, 14 deletions
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
},