feat(ui+backend): task categories edition

This commit is contained in:
2020-09-14 08:11:42 +02:00
parent 833213e5fe
commit e3274cdecf
10 changed files with 449 additions and 76 deletions

14
internal/graph/error.go Normal file
View File

@ -0,0 +1,14 @@
package graph
import (
"github.com/vektah/gqlparser/v2/gqlerror"
)
var (
ErrAssociatedTaskExist = &gqlerror.Error{
Message: "",
Extensions: map[string]interface{}{
"code": "associated-task-exist",
},
}
)

View File

@ -30,6 +30,11 @@ input TimeUnitChanges {
acronym: String
}
input ProjectTaskCategoryChanges {
label: String
costPerTimeUnit: Float
}
type Mutation {
updateUser(id: ID!, changes: UserChanges!): User!
createProject(changes: CreateProjectChanges!): Project!
@ -37,5 +42,8 @@ type Mutation {
addProjectTask(projectId: ID!, changes: ProjectTaskChanges!): Task!
removeProjectTask(projectId: ID!, taskId: ID!): Boolean!
updateProjectTask(projectId: ID!, taskId: ID!, changes: ProjectTaskChanges!): Task!
addProjectTaskCategory(projectId: ID!, changes: ProjectTaskCategoryChanges!): TaskCategory!
updateProjectTaskCategory(projectId: ID!, taskCategoryId: ID!, changes: ProjectTaskCategoryChanges!): TaskCategory!
removeProjectTaskCategory(projectId: ID!, taskCategoryId: ID!): Boolean!
updateProjectParams(projectId: ID!, changes: ProjectParamsChanges!): ProjectParams!
}

View File

@ -34,6 +34,18 @@ func (r *mutationResolver) UpdateProjectTask(ctx context.Context, projectID int6
return handleUpdateProjectTask(ctx, projectID, taskID, changes)
}
func (r *mutationResolver) AddProjectTaskCategory(ctx context.Context, projectID int64, changes model.ProjectTaskCategoryChanges) (*model.TaskCategory, error) {
return handleAddProjectTaskCategory(ctx, projectID, changes)
}
func (r *mutationResolver) UpdateProjectTaskCategory(ctx context.Context, projectID int64, taskCategoryID int64, changes model.ProjectTaskCategoryChanges) (*model.TaskCategory, error) {
return handleUpdateProjectTaskCategory(ctx, projectID, taskCategoryID, changes)
}
func (r *mutationResolver) RemoveProjectTaskCategory(ctx context.Context, projectID int64, taskCategoryID int64) (bool, error) {
return handleRemoveProjectTaskCategory(ctx, projectID, taskCategoryID)
}
func (r *mutationResolver) UpdateProjectParams(ctx context.Context, projectID int64, changes model.ProjectParamsChanges) (*model.ProjectParams, error) {
return handleUpdateProjectParams(ctx, projectID, changes)
}

View File

@ -3,6 +3,8 @@ package graph
import (
"context"
"github.com/99designs/gqlgen/graphql"
"forge.cadoles.com/Cadoles/guesstimate/internal/model"
model1 "forge.cadoles.com/Cadoles/guesstimate/internal/model"
"github.com/pkg/errors"
@ -126,3 +128,56 @@ func handleUpdateProjectParams(ctx context.Context, projectID int64, changes mod
return project.Params, nil
}
func handleAddProjectTaskCategory(ctx context.Context, projectID int64, changes model.ProjectTaskCategoryChanges) (*model.TaskCategory, error) {
db, err := getDB(ctx)
if err != nil {
return nil, errors.WithStack(err)
}
repo := model.NewProjectRepository(db)
taskCategory, err := repo.AddTaskCategory(ctx, projectID, changes)
if err != nil {
return nil, errors.WithStack(err)
}
return taskCategory, nil
}
func handleUpdateProjectTaskCategory(ctx context.Context, projectID int64, taskCategoryID int64, changes model.ProjectTaskCategoryChanges) (*model.TaskCategory, error) {
db, err := getDB(ctx)
if err != nil {
return nil, errors.WithStack(err)
}
repo := model.NewProjectRepository(db)
taskCategory, err := repo.UpdateTaskCategory(ctx, projectID, taskCategoryID, changes)
if err != nil {
return nil, errors.WithStack(err)
}
return taskCategory, nil
}
func handleRemoveProjectTaskCategory(ctx context.Context, projectID int64, taskCategoryID int64) (bool, error) {
db, err := getDB(ctx)
if err != nil {
return false, errors.WithStack(err)
}
repo := model.NewProjectRepository(db)
if err := repo.RemoveTaskCategory(ctx, projectID, taskCategoryID); err != nil {
if errors.Is(err, model.ErrAssociatedTaskExist) {
graphql.AddError(ctx, ErrAssociatedTaskExist)
return false, nil
}
return false, errors.WithStack(err)
}
return true, nil
}