feat(ui+backend): task update ok
This commit is contained in:
@ -2,48 +2,10 @@ package graph
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"forge.cadoles.com/Cadoles/guesstimate/internal/model"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func handleEstimations(ctx context.Context, task *model.Task) (*model.Estimations, error) {
|
||||
estimations := &model.Estimations{}
|
||||
|
||||
if task.Estimations == nil {
|
||||
return estimations, nil
|
||||
}
|
||||
|
||||
rawOptimistic, exists := task.Estimations[model.EstimationOptimistic]
|
||||
if exists && rawOptimistic != nil {
|
||||
optimistic, err := strconv.ParseFloat(*rawOptimistic, 64)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
estimations.Optimistic = optimistic
|
||||
}
|
||||
|
||||
rawLikely, exists := task.Estimations[model.EstimationLikely]
|
||||
if exists && rawLikely != nil {
|
||||
likely, err := strconv.ParseFloat(*rawLikely, 64)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
estimations.Likely = likely
|
||||
}
|
||||
|
||||
rawPessimistic, exists := task.Estimations[model.EstimationPessimistic]
|
||||
if exists && rawPessimistic != nil {
|
||||
pessimistic, err := strconv.ParseFloat(*rawPessimistic, 64)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
estimations.Pessimistic = pessimistic
|
||||
}
|
||||
|
||||
return estimations, nil
|
||||
return task.Estimations, nil
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ type Mutation {
|
||||
updateUser(id: ID!, changes: UserChanges!): User!
|
||||
createProject(changes: CreateProjectChanges!): Project!
|
||||
updateProjectTitle(projectId: ID!, title: String!): Project!
|
||||
addProjectTask(projectId: ID!, changes: ProjectTaskChanges): Task!
|
||||
addProjectTask(projectId: ID!, changes: ProjectTaskChanges!): Task!
|
||||
removeProjectTask(projectId: ID!, taskId: ID!): Boolean!
|
||||
updateProjectTask(projectId: ID!, taskId: ID!, changes: ProjectTaskChanges!): Task!
|
||||
}
|
@ -22,7 +22,7 @@ func (r *mutationResolver) UpdateProjectTitle(ctx context.Context, projectID int
|
||||
return handleUpdateProjectTitle(ctx, projectID, title)
|
||||
}
|
||||
|
||||
func (r *mutationResolver) AddProjectTask(ctx context.Context, projectID int64, changes *model.ProjectTaskChanges) (*model.Task, error) {
|
||||
func (r *mutationResolver) AddProjectTask(ctx context.Context, projectID int64, changes model.ProjectTaskChanges) (*model.Task, error) {
|
||||
return handleAddProjectTask(ctx, projectID, changes)
|
||||
}
|
||||
|
||||
@ -30,6 +30,10 @@ func (r *mutationResolver) RemoveProjectTask(ctx context.Context, projectID int6
|
||||
return handleRemoveProjectTask(ctx, projectID, taskID)
|
||||
}
|
||||
|
||||
func (r *mutationResolver) UpdateProjectTask(ctx context.Context, projectID int64, taskID int64, changes model.ProjectTaskChanges) (*model.Task, error) {
|
||||
return handleUpdateProjectTask(ctx, projectID, taskID, changes)
|
||||
}
|
||||
|
||||
// Mutation returns generated.MutationResolver implementation.
|
||||
func (r *Resolver) Mutation() generated.MutationResolver { return &mutationResolver{r} }
|
||||
|
||||
|
@ -64,7 +64,7 @@ func handleUpdateProjectTitle(ctx context.Context, projectID int64, title string
|
||||
return project, nil
|
||||
}
|
||||
|
||||
func handleAddProjectTask(ctx context.Context, projectID int64, changes *model.ProjectTaskChanges) (*model.Task, error) {
|
||||
func handleAddProjectTask(ctx context.Context, projectID int64, changes model.ProjectTaskChanges) (*model.Task, error) {
|
||||
db, err := getDB(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
@ -94,3 +94,19 @@ func handleRemoveProjectTask(ctx context.Context, projectID int64, taskID int64)
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func handleUpdateProjectTask(ctx context.Context, projectID, taskID int64, changes model.ProjectTaskChanges) (*model.Task, error) {
|
||||
db, err := getDB(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
repo := model.NewProjectRepository(db)
|
||||
|
||||
task, err := repo.UpdateTask(ctx, projectID, taskID, changes)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
return task, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user