git-bug/graphql/resolvers/operations.go

77 lines
2.2 KiB
Go
Raw Normal View History

2018-07-29 19:11:33 +03:00
package resolvers
import (
"context"
"fmt"
2018-08-13 19:32:11 +03:00
"time"
2018-07-29 19:11:33 +03:00
"github.com/MichaelMure/git-bug/bug"
"github.com/MichaelMure/git-bug/graphql/models"
"github.com/MichaelMure/git-bug/operations"
2018-07-29 19:11:33 +03:00
)
type addCommentOperationResolver struct{}
func (addCommentOperationResolver) Author(ctx context.Context, obj *operations.AddCommentOperation) (bug.Person, error) {
return obj.Author, nil
}
2018-07-29 19:11:33 +03:00
func (addCommentOperationResolver) Date(ctx context.Context, obj *operations.AddCommentOperation) (time.Time, error) {
return obj.Time(), nil
}
type createOperationResolver struct{}
func (createOperationResolver) Author(ctx context.Context, obj *operations.CreateOperation) (bug.Person, error) {
return obj.Author, nil
}
2018-07-29 19:11:33 +03:00
func (createOperationResolver) Date(ctx context.Context, obj *operations.CreateOperation) (time.Time, error) {
return obj.Time(), nil
}
type labelChangeOperation struct{}
func (labelChangeOperation) Author(ctx context.Context, obj *operations.LabelChangeOperation) (bug.Person, error) {
return obj.Author, nil
}
2018-07-29 19:11:33 +03:00
func (labelChangeOperation) Date(ctx context.Context, obj *operations.LabelChangeOperation) (time.Time, error) {
return obj.Time(), nil
}
type setStatusOperationResolver struct{}
func (setStatusOperationResolver) Author(ctx context.Context, obj *operations.SetStatusOperation) (bug.Person, error) {
return obj.Author, nil
}
2018-07-29 19:11:33 +03:00
func (setStatusOperationResolver) Date(ctx context.Context, obj *operations.SetStatusOperation) (time.Time, error) {
return obj.Time(), nil
}
func (setStatusOperationResolver) Status(ctx context.Context, obj *operations.SetStatusOperation) (models.Status, error) {
2018-07-29 19:11:33 +03:00
return convertStatus(obj.Status)
}
type setTitleOperationResolver struct{}
func (setTitleOperationResolver) Author(ctx context.Context, obj *operations.SetTitleOperation) (bug.Person, error) {
return obj.Author, nil
}
2018-07-29 19:11:33 +03:00
func (setTitleOperationResolver) Date(ctx context.Context, obj *operations.SetTitleOperation) (time.Time, error) {
return obj.Time(), nil
}
func convertStatus(status bug.Status) (models.Status, error) {
2018-07-29 19:11:33 +03:00
switch status {
case bug.OpenStatus:
return models.StatusOpen, nil
2018-07-29 19:11:33 +03:00
case bug.ClosedStatus:
return models.StatusClosed, nil
2018-07-29 19:11:33 +03:00
}
return "", fmt.Errorf("Unknown status")
}