-
Notifications
You must be signed in to change notification settings - Fork 0
/
done.go
48 lines (39 loc) · 1.04 KB
/
done.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
Copyright © 2024 Mathias Donoso mathiasd88@gmail.com
*/
package cmd
import (
"fmt"
"github.com/mathiasdonoso/chrono/db"
"github.com/mathiasdonoso/chrono/internal/chrono/progress"
"github.com/mathiasdonoso/chrono/internal/chrono/task"
"github.com/spf13/cobra"
)
// doneCmd represents the done command
var doneCmd = &cobra.Command{
Use: "done",
Short: "Finish a task by id",
Long: `Finish a task by id setting the status to "done".`,
Version: "0.0.1",
Run: func(cmd *cobra.Command, args []string) {
id := args[0]
dbConn, err := db.Connect()
defer dbConn.Close()
if err != nil {
fmt.Println("Error connecting to db:", err)
}
taskRepo := task.NewRepository(dbConn.GetDB())
progressRepo := progress.NewRepository(dbConn.GetDB())
taskService := task.NewService(taskRepo, progressRepo)
taskHandler := task.NewHandler(taskService)
res, err := taskHandler.FinishTask(id)
if err != nil {
fmt.Println("Error finishing the task:", err)
return
}
fmt.Println(res)
},
}
func init() {
rootCmd.AddCommand(doneCmd)
}