summaryrefslogtreecommitdiff
path: root/internal/reports/api.go
diff options
context:
space:
mode:
authorT <t@tjp.lol>2025-09-29 15:04:44 -0600
committerT <t@tjp.lol>2025-09-30 11:40:45 -0600
commit7ba68d333bc20b5795ccfd3870546a05eee60470 (patch)
tree12dc4b017803b7d01844fd42b9e3be281cbbd986 /internal/reports/api.go
parentbce8dbb58165e443902d9dae3909225ef42630c4 (diff)
Support for archiving clients and projects.HEADmain
Diffstat (limited to 'internal/reports/api.go')
-rw-r--r--internal/reports/api.go31
1 files changed, 25 insertions, 6 deletions
diff --git a/internal/reports/api.go b/internal/reports/api.go
index 90b066b..b7bd3c2 100644
--- a/internal/reports/api.go
+++ b/internal/reports/api.go
@@ -4,7 +4,9 @@ import (
"context"
"database/sql"
"fmt"
+ "os"
"path/filepath"
+ "strings"
"time"
"git.tjp.lol/punchcard/internal/queries"
@@ -25,6 +27,23 @@ type ReportResult struct {
TotalEntries int
}
+func expandPath(path string) (string, error) {
+ if strings.HasPrefix(path, "~/") {
+ home, err := os.UserHomeDir()
+ if err != nil {
+ return "", fmt.Errorf("failed to get home directory: %w", err)
+ }
+ path = filepath.Join(home, path[2:])
+ } else if path == "~" {
+ home, err := os.UserHomeDir()
+ if err != nil {
+ return "", fmt.Errorf("failed to get home directory: %w", err)
+ }
+ path = home
+ }
+ return filepath.Abs(path)
+}
+
func GenerateInvoice(ctx context.Context, q *queries.Queries, params ReportParams) (*ReportResult, error) {
if params.ProjectName == "" {
return GenerateClientInvoice(ctx, q, params)
@@ -91,7 +110,7 @@ func GenerateClientInvoice(ctx context.Context, q *queries.Queries, params Repor
outputPath = GenerateDefaultInvoiceFilename(invoiceData.ClientName, invoiceData.ProjectName, params.DateRange)
}
- outputPath, err = filepath.Abs(outputPath)
+ outputPath, err = expandPath(outputPath)
if err != nil {
return nil, fmt.Errorf("failed to resolve output path: %w", err)
}
@@ -172,7 +191,7 @@ func GenerateProjectInvoice(ctx context.Context, q *queries.Queries, params Repo
outputPath = GenerateDefaultInvoiceFilename(invoiceData.ClientName, invoiceData.ProjectName, params.DateRange)
}
- outputPath, err = filepath.Abs(outputPath)
+ outputPath, err = expandPath(outputPath)
if err != nil {
return nil, fmt.Errorf("failed to resolve output path: %w", err)
}
@@ -236,7 +255,7 @@ func GenerateClientTimesheet(ctx context.Context, q *queries.Queries, params Rep
outputPath = GenerateDefaultTimesheetFilename(timesheetData.ClientName, timesheetData.ProjectName, params.DateRange)
}
- outputPath, err = filepath.Abs(outputPath)
+ outputPath, err = expandPath(outputPath)
if err != nil {
return nil, fmt.Errorf("failed to resolve output path: %w", err)
}
@@ -299,7 +318,7 @@ func GenerateProjectTimesheet(ctx context.Context, q *queries.Queries, params Re
outputPath = GenerateDefaultTimesheetFilename(timesheetData.ClientName, timesheetData.ProjectName, params.DateRange)
}
- outputPath, err = filepath.Abs(outputPath)
+ outputPath, err = expandPath(outputPath)
if err != nil {
return nil, fmt.Errorf("failed to resolve output path: %w", err)
}
@@ -361,7 +380,7 @@ func GenerateClientUnifiedReport(ctx context.Context, q *queries.Queries, params
outputPath = GenerateDefaultUnifiedFilename(unifiedData.InvoiceData.ClientName, unifiedData.InvoiceData.ProjectName, params.DateRange)
}
- outputPath, err = filepath.Abs(outputPath)
+ outputPath, err = expandPath(outputPath)
if err != nil {
return nil, fmt.Errorf("failed to resolve output path: %w", err)
}
@@ -442,7 +461,7 @@ func GenerateProjectUnifiedReport(ctx context.Context, q *queries.Queries, param
outputPath = GenerateDefaultUnifiedFilename(unifiedData.InvoiceData.ClientName, unifiedData.InvoiceData.ProjectName, params.DateRange)
}
- outputPath, err = filepath.Abs(outputPath)
+ outputPath, err = expandPath(outputPath)
if err != nil {
return nil, fmt.Errorf("failed to resolve output path: %w", err)
}