diff options
Diffstat (limited to 'internal/actions/projects.go')
-rw-r--r-- | internal/actions/projects.go | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/internal/actions/projects.go b/internal/actions/projects.go index 4cb4638..d36780b 100644 --- a/internal/actions/projects.go +++ b/internal/actions/projects.go @@ -18,9 +18,8 @@ func (a *actions) CreateProject(ctx context.Context, name, client string, billab } var billableRateParam sql.NullInt64 - if billableRate != nil && *billableRate > 0 { - rate := int64(*billableRate * 100) // Convert dollars to cents - billableRateParam = sql.NullInt64{Int64: rate, Valid: true} + if billableRate != nil { + billableRateParam = sql.NullInt64{Int64: int64(*billableRate * 100), Valid: true} } project, err := a.queries.CreateProject(ctx, queries.CreateProjectParams{ @@ -35,6 +34,24 @@ func (a *actions) CreateProject(ctx context.Context, name, client string, billab return &project, nil } +func (a *actions) EditProject(ctx context.Context, id int64, name string, billableRate *float64) (*queries.Project, error) { + var rateParam sql.NullInt64 + if billableRate != nil { + rateParam = sql.NullInt64{Int64: int64(*billableRate * 100), Valid: true} + } + + project, err := a.queries.UpdateProject(ctx, queries.UpdateProjectParams{ + Name: name, + BillableRate: rateParam, + ID: id, + }) + if err != nil { + return nil, fmt.Errorf("failed to update project: %w", err) + } + + return &project, nil +} + // FindProject finds a project by name or ID func (a *actions) FindProject(ctx context.Context, nameOrID string) (*queries.Project, error) { // Parse as ID if possible, otherwise use 0 |