-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
executable file
·91 lines (73 loc) · 2.17 KB
/
main.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package main
import (
"bufio"
"fmt"
"log"
"os"
"strings"
"github.com/google/uuid"
"github.com/thiagodebastos/gofixit/domain/entity"
"github.com/thiagodebastos/gofixit/domain/valueobject"
"github.com/thiagodebastos/gofixit/infra/persistence/sqlite"
)
func createIssue() entity.Issue {
reader := bufio.NewReader(os.Stdin)
fmt.Print("Create a new issue title: ")
title, _ := reader.ReadString('\n')
title = strings.TrimSpace(title)
fmt.Print("Add a description: ")
description, _ := reader.ReadString('\n')
description = strings.TrimSpace(description)
fmt.Print("Add a priority [lowest, low, medium, high, highest]: ")
priority, _ := reader.ReadString('\n')
priority = strings.TrimSpace(priority)
newPriority, priorityOk := valueobject.PriorityFromString(priority)
for !priorityOk {
fmt.Print("Invalid priority, add a priority [lowest, low, medium, high, highest]: ")
priority, _ := reader.ReadString('\n')
priority = strings.TrimSpace(priority)
newPriority, priorityOk = valueobject.PriorityFromString(priority)
}
i, _ := entity.CreateIssue(
uuid.New(),
title,
description,
valueobject.StatusOpen,
newPriority,
)
return i
}
func main() {
// Open a connection to an in-memory SQLite database.
conn, err := sqlite.OpenConn(":memory:", sqlite.OpenReadWrite)
if err != nil {
log.Fatalf("failed to open database connection: %v", err)
}
defer conn.Close()
// Set up your repositories
userRepo := sqlite.NewUserRepository(conn)
issueRepo := sqlite.NewIssueRepository(conn)
// Example of using the repositories
err = userRepo.CreateUser()
if err != nil {
log.Fatalf("failed to create user: %v", err)
}
user, err := userRepo.GetUser(1)
if err != nil {
log.Fatalf("failed to get user: %v", err)
}
log.Printf("User: %v", user)
printAligned := func(label string, value interface{}) {
fmt.Printf("%-12s: %v\n", label, value)
}
printIssue := func(i entity.Issue) {
printAligned("ID", i.ID())
printAligned("Title", i.Title())
printAligned("Description", i.Description())
printAligned("Status", i.Status().ToString())
printAligned("Priority", i.Priority().String())
fmt.Printf("\n")
}
myIssue := createIssue()
printIssue(myIssue)
}