feature(api): add mutation to update task group location

This commit is contained in:
Jordan Knott 2020-04-10 21:47:43 -05:00
parent bd73717deb
commit bd878c9c64
8 changed files with 169 additions and 11 deletions

View File

@ -64,6 +64,7 @@ type ComplexityRoot struct {
CreateUserAccount func(childComplexity int, input NewUserAccount) int
DeleteTask func(childComplexity int, input DeleteTaskInput) int
LogoutUser func(childComplexity int, input LogoutUser) int
UpdateTaskGroupLocation func(childComplexity int, input NewTaskGroupLocation) int
UpdateTaskLocation func(childComplexity int, input NewTaskLocation) int
UpdateTaskName func(childComplexity int, input UpdateTaskName) int
}
@ -140,6 +141,7 @@ type MutationResolver interface {
CreateTeam(ctx context.Context, input NewTeam) (*pg.Team, error)
CreateProject(ctx context.Context, input NewProject) (*pg.Project, error)
CreateTaskGroup(ctx context.Context, input NewTaskGroup) (*pg.TaskGroup, error)
UpdateTaskGroupLocation(ctx context.Context, input NewTaskGroupLocation) (*pg.TaskGroup, error)
CreateTask(ctx context.Context, input NewTask) (*pg.Task, error)
UpdateTaskLocation(ctx context.Context, input NewTaskLocation) (*pg.Task, error)
LogoutUser(ctx context.Context, input LogoutUser) (bool, error)
@ -305,6 +307,18 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
return e.complexity.Mutation.LogoutUser(childComplexity, args["input"].(LogoutUser)), true
case "Mutation.updateTaskGroupLocation":
if e.complexity.Mutation.UpdateTaskGroupLocation == nil {
break
}
args, err := ec.field_Mutation_updateTaskGroupLocation_args(context.TODO(), rawArgs)
if err != nil {
return 0, false
}
return e.complexity.Mutation.UpdateTaskGroupLocation(childComplexity, args["input"].(NewTaskGroupLocation)), true
case "Mutation.updateTaskLocation":
if e.complexity.Mutation.UpdateTaskLocation == nil {
break
@ -826,6 +840,11 @@ input UpdateTaskName {
name: String!
}
input NewTaskGroupLocation {
taskGroupID: UUID!
position: Float!
}
type Mutation {
createRefreshToken(input: NewRefreshToken!): RefreshToken!
createUserAccount(input: NewUserAccount!): UserAccount!
@ -833,6 +852,7 @@ type Mutation {
createTeam(input: NewTeam!): Team!
createProject(input: NewProject!): Project!
createTaskGroup(input: NewTaskGroup!): TaskGroup!
updateTaskGroupLocation(input: NewTaskGroupLocation!): TaskGroup!
createTask(input: NewTask!): Task!
updateTaskLocation(input: NewTaskLocation!): Task!
logoutUser(input: LogoutUser!): Boolean!
@ -973,6 +993,20 @@ func (ec *executionContext) field_Mutation_logoutUser_args(ctx context.Context,
return args, nil
}
func (ec *executionContext) field_Mutation_updateTaskGroupLocation_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {
var err error
args := map[string]interface{}{}
var arg0 NewTaskGroupLocation
if tmp, ok := rawArgs["input"]; ok {
arg0, err = ec.unmarshalNNewTaskGroupLocation2githubᚗcomᚋjordanknottᚋprojectᚑcitadelᚋapiᚋgraphᚐNewTaskGroupLocation(ctx, tmp)
if err != nil {
return nil, err
}
}
args["input"] = arg0
return args, nil
}
func (ec *executionContext) field_Mutation_updateTaskLocation_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {
var err error
args := map[string]interface{}{}
@ -1373,6 +1407,47 @@ func (ec *executionContext) _Mutation_createTaskGroup(ctx context.Context, field
return ec.marshalNTaskGroup2ᚖgithubᚗcomᚋjordanknottᚋprojectᚑcitadelᚋapiᚋpgᚐTaskGroup(ctx, field.Selections, res)
}
func (ec *executionContext) _Mutation_updateTaskGroupLocation(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) {
defer func() {
if r := recover(); r != nil {
ec.Error(ctx, ec.Recover(ctx, r))
ret = graphql.Null
}
}()
fc := &graphql.FieldContext{
Object: "Mutation",
Field: field,
Args: nil,
IsMethod: true,
}
ctx = graphql.WithFieldContext(ctx, fc)
rawArgs := field.ArgumentMap(ec.Variables)
args, err := ec.field_Mutation_updateTaskGroupLocation_args(ctx, rawArgs)
if err != nil {
ec.Error(ctx, err)
return graphql.Null
}
fc.Args = args
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
ctx = rctx // use context from middleware stack in children
return ec.resolvers.Mutation().UpdateTaskGroupLocation(rctx, args["input"].(NewTaskGroupLocation))
})
if err != nil {
ec.Error(ctx, err)
return graphql.Null
}
if resTmp == nil {
if !graphql.HasFieldError(ctx, fc) {
ec.Errorf(ctx, "must not be null")
}
return graphql.Null
}
res := resTmp.(*pg.TaskGroup)
fc.Result = res
return ec.marshalNTaskGroup2ᚖgithubᚗcomᚋjordanknottᚋprojectᚑcitadelᚋapiᚋpgᚐTaskGroup(ctx, field.Selections, res)
}
func (ec *executionContext) _Mutation_createTask(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) {
defer func() {
if r := recover(); r != nil {
@ -4275,6 +4350,30 @@ func (ec *executionContext) unmarshalInputNewTaskGroup(ctx context.Context, obj
return it, nil
}
func (ec *executionContext) unmarshalInputNewTaskGroupLocation(ctx context.Context, obj interface{}) (NewTaskGroupLocation, error) {
var it NewTaskGroupLocation
var asMap = obj.(map[string]interface{})
for k, v := range asMap {
switch k {
case "taskGroupID":
var err error
it.TaskGroupID, err = ec.unmarshalNUUID2githubᚗcomᚋgoogleᚋuuidᚐUUID(ctx, v)
if err != nil {
return it, err
}
case "position":
var err error
it.Position, err = ec.unmarshalNFloat2float64(ctx, v)
if err != nil {
return it, err
}
}
}
return it, nil
}
func (ec *executionContext) unmarshalInputNewTaskLocation(ctx context.Context, obj interface{}) (NewTaskLocation, error) {
var it NewTaskLocation
var asMap = obj.(map[string]interface{})
@ -4487,6 +4586,11 @@ func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet)
if out.Values[i] == graphql.Null {
invalids++
}
case "updateTaskGroupLocation":
out.Values[i] = ec._Mutation_updateTaskGroupLocation(ctx, field)
if out.Values[i] == graphql.Null {
invalids++
}
case "createTask":
out.Values[i] = ec._Mutation_createTask(ctx, field)
if out.Values[i] == graphql.Null {
@ -5370,6 +5474,10 @@ func (ec *executionContext) unmarshalNNewTaskGroup2githubᚗcomᚋjordanknottᚋ
return ec.unmarshalInputNewTaskGroup(ctx, v)
}
func (ec *executionContext) unmarshalNNewTaskGroupLocation2githubᚗcomᚋjordanknottᚋprojectᚑcitadelᚋapiᚋgraphᚐNewTaskGroupLocation(ctx context.Context, v interface{}) (NewTaskGroupLocation, error) {
return ec.unmarshalInputNewTaskGroupLocation(ctx, v)
}
func (ec *executionContext) unmarshalNNewTaskLocation2githubᚗcomᚋjordanknottᚋprojectᚑcitadelᚋapiᚋgraphᚐNewTaskLocation(ctx context.Context, v interface{}) (NewTaskLocation, error) {
return ec.unmarshalInputNewTaskLocation(ctx, v)
}

View File

@ -2,6 +2,10 @@
package graph
import (
"github.com/google/uuid"
)
type DeleteTaskInput struct {
TaskID string `json:"taskID"`
}
@ -47,6 +51,11 @@ type NewTaskGroup struct {
Position float64 `json:"position"`
}
type NewTaskGroupLocation struct {
TaskGroupID uuid.UUID `json:"taskGroupID"`
Position float64 `json:"position"`
}
type NewTaskLocation struct {
TaskID string `json:"taskID"`
TaskGroupID string `json:"taskGroupID"`

View File

@ -136,6 +136,11 @@ input UpdateTaskName {
name: String!
}
input NewTaskGroupLocation {
taskGroupID: UUID!
position: Float!
}
type Mutation {
createRefreshToken(input: NewRefreshToken!): RefreshToken!
createUserAccount(input: NewUserAccount!): UserAccount!
@ -143,6 +148,7 @@ type Mutation {
createTeam(input: NewTeam!): Team!
createProject(input: NewProject!): Project!
createTaskGroup(input: NewTaskGroup!): TaskGroup!
updateTaskGroupLocation(input: NewTaskGroupLocation!): TaskGroup!
createTask(input: NewTask!): Task!
updateTaskLocation(input: NewTaskLocation!): Task!
logoutUser(input: LogoutUser!): Boolean!

View File

@ -65,6 +65,14 @@ func (r *mutationResolver) CreateTaskGroup(ctx context.Context, input NewTaskGro
return &project, err
}
func (r *mutationResolver) UpdateTaskGroupLocation(ctx context.Context, input NewTaskGroupLocation) (*pg.TaskGroup, error) {
taskGroup, err := r.Repository.UpdateTaskGroupLocation(ctx, pg.UpdateTaskGroupLocationParams{
input.TaskGroupID,
input.Position,
})
return &taskGroup, err
}
func (r *mutationResolver) CreateTask(ctx context.Context, input NewTask) (*pg.Task, error) {
taskGroupID, err := uuid.Parse(input.TaskGroupID)
createdAt := time.Now().UTC()

View File

@ -16,6 +16,7 @@ type Repository interface {
GetAllProjectsForTeam(ctx context.Context, teamID uuid.UUID) ([]Project, error)
GetProjectByID(ctx context.Context, projectID uuid.UUID) (Project, error)
GetAllUserAccounts(ctx context.Context) ([]UserAccount, error)
UpdateTaskGroupLocation(ctx context.Context, arg UpdateTaskGroupLocationParams) (TaskGroup, error)
GetUserAccountByID(ctx context.Context, userID uuid.UUID) (UserAccount, error)
CreateUserAccount(ctx context.Context, arg CreateUserAccountParams) (UserAccount, error)
GetUserAccountByUsername(ctx context.Context, username string) (UserAccount, error)

View File

@ -37,6 +37,7 @@ type Querier interface {
GetTeamsForOrganization(ctx context.Context, organizationID uuid.UUID) ([]Team, error)
GetUserAccountByID(ctx context.Context, userID uuid.UUID) (UserAccount, error)
GetUserAccountByUsername(ctx context.Context, username string) (UserAccount, error)
UpdateTaskGroupLocation(ctx context.Context, arg UpdateTaskGroupLocationParams) (TaskGroup, error)
UpdateTaskLocation(ctx context.Context, arg UpdateTaskLocationParams) (Task, error)
UpdateTaskName(ctx context.Context, arg UpdateTaskNameParams) (Task, error)
}

View File

@ -122,3 +122,25 @@ func (q *Queries) GetTaskGroupsForProject(ctx context.Context, projectID uuid.UU
}
return items, nil
}
const updateTaskGroupLocation = `-- name: UpdateTaskGroupLocation :one
UPDATE task_group SET position = $2 WHERE task_group_id = $1 RETURNING task_group_id, project_id, created_at, name, position
`
type UpdateTaskGroupLocationParams struct {
TaskGroupID uuid.UUID `json:"task_group_id"`
Position float64 `json:"position"`
}
func (q *Queries) UpdateTaskGroupLocation(ctx context.Context, arg UpdateTaskGroupLocationParams) (TaskGroup, error) {
row := q.db.QueryRowContext(ctx, updateTaskGroupLocation, arg.TaskGroupID, arg.Position)
var i TaskGroup
err := row.Scan(
&i.TaskGroupID,
&i.ProjectID,
&i.CreatedAt,
&i.Name,
&i.Position,
)
return i, err
}

View File

@ -10,3 +10,6 @@ SELECT * FROM task_group;
-- name: GetTaskGroupByID :one
SELECT * FROM task_group WHERE task_group_id = $1;
-- name: UpdateTaskGroupLocation :one
UPDATE task_group SET position = $2 WHERE task_group_id = $1 RETURNING *;