| iomodo | 3b89bdf | 2025-07-25 15:19:22 +0400 | [diff] [blame] | 1 | package git_tm |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "fmt" |
| iomodo | 0c203b1 | 2025-07-26 19:44:57 +0400 | [diff] [blame] | 6 | "log/slog" |
| 7 | "os" |
| iomodo | 3b89bdf | 2025-07-25 15:19:22 +0400 | [diff] [blame] | 8 | "time" |
| 9 | |
| 10 | "github.com/iomodo/staff/git" |
| 11 | "github.com/iomodo/staff/tm" |
| 12 | ) |
| 13 | |
| 14 | // Example demonstrates how to use the GitTaskManager |
| 15 | func Example() { |
| iomodo | 0c203b1 | 2025-07-26 19:44:57 +0400 | [diff] [blame] | 16 | // Create logger |
| 17 | logger := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelInfo})) |
| 18 | |
| iomodo | 3b89bdf | 2025-07-25 15:19:22 +0400 | [diff] [blame] | 19 | // Initialize git interface |
| 20 | gitInterface := git.DefaultGit("./tasks-repo") |
| 21 | |
| 22 | // Create task manager |
| iomodo | 0c203b1 | 2025-07-26 19:44:57 +0400 | [diff] [blame] | 23 | taskManager := NewGitTaskManagerWithLogger(gitInterface, "./tasks-repo", logger) |
| iomodo | 3b89bdf | 2025-07-25 15:19:22 +0400 | [diff] [blame] | 24 | |
| 25 | // Create a new task |
| 26 | ctx := context.Background() |
| 27 | dueDate := time.Now().AddDate(0, 0, 7) // Due in 7 days |
| 28 | |
| 29 | createReq := &tm.TaskCreateRequest{ |
| 30 | Title: "Implement user authentication", |
| 31 | Description: "Add login/logout functionality with JWT tokens", |
| 32 | OwnerID: "john.doe", |
| 33 | Priority: tm.PriorityHigh, |
| 34 | DueDate: &dueDate, |
| 35 | } |
| 36 | |
| 37 | task, err := taskManager.CreateTask(ctx, createReq) |
| 38 | if err != nil { |
| iomodo | 0c203b1 | 2025-07-26 19:44:57 +0400 | [diff] [blame] | 39 | logger.Error("Failed to create task", slog.String("error", err.Error())) |
| 40 | os.Exit(1) |
| iomodo | 3b89bdf | 2025-07-25 15:19:22 +0400 | [diff] [blame] | 41 | } |
| 42 | |
| iomodo | 0c203b1 | 2025-07-26 19:44:57 +0400 | [diff] [blame] | 43 | logger.Info("Created task", slog.String("id", task.ID)) |
| iomodo | 3b89bdf | 2025-07-25 15:19:22 +0400 | [diff] [blame] | 44 | |
| 45 | // Get the task |
| user | 5a7d60d | 2025-07-27 21:22:04 +0400 | [diff] [blame] | 46 | retrievedTask, err := taskManager.GetTask(task.ID) |
| iomodo | 3b89bdf | 2025-07-25 15:19:22 +0400 | [diff] [blame] | 47 | if err != nil { |
| iomodo | 0c203b1 | 2025-07-26 19:44:57 +0400 | [diff] [blame] | 48 | logger.Error("Failed to get task", slog.String("error", err.Error())) |
| 49 | os.Exit(1) |
| iomodo | 3b89bdf | 2025-07-25 15:19:22 +0400 | [diff] [blame] | 50 | } |
| 51 | |
| iomodo | 0c203b1 | 2025-07-26 19:44:57 +0400 | [diff] [blame] | 52 | logger.Info("Retrieved task", slog.String("id", retrievedTask.ID), slog.String("title", retrievedTask.Title)) |
| iomodo | 3b89bdf | 2025-07-25 15:19:22 +0400 | [diff] [blame] | 53 | |
| 54 | // Start the task |
| 55 | startedTask, err := taskManager.StartTask(ctx, task.ID) |
| 56 | if err != nil { |
| iomodo | 0c203b1 | 2025-07-26 19:44:57 +0400 | [diff] [blame] | 57 | logger.Error("Failed to start task", slog.String("error", err.Error())) |
| 58 | os.Exit(1) |
| iomodo | 3b89bdf | 2025-07-25 15:19:22 +0400 | [diff] [blame] | 59 | } |
| 60 | |
| iomodo | 0c203b1 | 2025-07-26 19:44:57 +0400 | [diff] [blame] | 61 | logger.Info("Started task", slog.String("id", startedTask.ID), slog.String("status", string(startedTask.Status))) |
| iomodo | 3b89bdf | 2025-07-25 15:19:22 +0400 | [diff] [blame] | 62 | |
| 63 | // List all tasks |
| 64 | taskList, err := taskManager.ListTasks(ctx, nil, 0, 10) |
| 65 | if err != nil { |
| iomodo | 0c203b1 | 2025-07-26 19:44:57 +0400 | [diff] [blame] | 66 | logger.Error("Failed to list tasks", slog.String("error", err.Error())) |
| 67 | os.Exit(1) |
| iomodo | 3b89bdf | 2025-07-25 15:19:22 +0400 | [diff] [blame] | 68 | } |
| 69 | |
| iomodo | 0c203b1 | 2025-07-26 19:44:57 +0400 | [diff] [blame] | 70 | logger.Info("Total tasks", slog.Int("count", taskList.TotalCount)) |
| iomodo | 3b89bdf | 2025-07-25 15:19:22 +0400 | [diff] [blame] | 71 | for _, t := range taskList.Tasks { |
| iomodo | 0c203b1 | 2025-07-26 19:44:57 +0400 | [diff] [blame] | 72 | logger.Info("Task", slog.String("id", t.ID), slog.String("title", t.Title), slog.String("status", string(t.Status))) |
| iomodo | 3b89bdf | 2025-07-25 15:19:22 +0400 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | // Complete the task |
| 76 | completedTask, err := taskManager.CompleteTask(ctx, task.ID) |
| 77 | if err != nil { |
| iomodo | 0c203b1 | 2025-07-26 19:44:57 +0400 | [diff] [blame] | 78 | logger.Error("Failed to complete task", slog.String("error", err.Error())) |
| 79 | os.Exit(1) |
| iomodo | 3b89bdf | 2025-07-25 15:19:22 +0400 | [diff] [blame] | 80 | } |
| 81 | |
| iomodo | 0c203b1 | 2025-07-26 19:44:57 +0400 | [diff] [blame] | 82 | logger.Info("Completed task", slog.String("id", completedTask.ID), slog.String("completed_at", completedTask.CompletedAt.Format(time.RFC3339))) |
| iomodo | 3b89bdf | 2025-07-25 15:19:22 +0400 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | // ExampleTaskFile shows the format of a task file |
| 86 | func ExampleTaskFile() { |
| 87 | fmt.Print(`Example task file (tasks/task-1704067200-abc123.md): |
| 88 | |
| 89 | --- |
| 90 | id: task-1704067200-abc123 |
| 91 | title: Implement user authentication |
| 92 | description: Add login/logout functionality with JWT tokens |
| 93 | owner_id: john.doe |
| 94 | owner_name: John Doe |
| 95 | status: in_progress |
| 96 | priority: high |
| 97 | created_at: 2024-01-01T10:00:00Z |
| 98 | updated_at: 2024-01-01T15:30:00Z |
| 99 | due_date: 2024-01-08T17:00:00Z |
| 100 | completed_at: null |
| 101 | archived_at: null |
| 102 | --- |
| 103 | |
| 104 | # Task Description |
| 105 | |
| 106 | Add login/logout functionality with JWT tokens for the web application. |
| 107 | |
| 108 | ## Requirements |
| 109 | |
| 110 | - User registration and login forms |
| 111 | - JWT token generation and validation |
| 112 | - Password hashing with bcrypt |
| 113 | - Session management |
| 114 | - Logout functionality |
| 115 | |
| 116 | ## Notes |
| 117 | |
| 118 | - Consider using bcrypt for password hashing |
| 119 | - Implement refresh token mechanism |
| 120 | - Add rate limiting for login attempts |
| 121 | `) |
| 122 | } |