git-bug/graphql/resolvers/operations.go

62 lines
1.6 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"
2018-07-29 19:11:33 +03:00
)
2018-10-07 18:41:47 +03:00
type createOperationResolver struct{}
func (createOperationResolver) Date(ctx context.Context, obj *bug.CreateOperation) (time.Time, error) {
return obj.Time(), nil
}
2018-07-29 19:11:33 +03:00
type addCommentOperationResolver struct{}
func (addCommentOperationResolver) Date(ctx context.Context, obj *bug.AddCommentOperation) (time.Time, error) {
2018-07-29 19:11:33 +03:00
return obj.Time(), nil
}
2018-10-07 18:41:47 +03:00
type editCommentOperationResolver struct{}
2018-07-29 19:11:33 +03:00
2018-10-07 18:41:47 +03:00
func (editCommentOperationResolver) Date(ctx context.Context, obj *bug.EditCommentOperation) (time.Time, error) {
2018-07-29 19:11:33 +03:00
return obj.Time(), nil
}
type labelChangeOperation struct{}
func (labelChangeOperation) Date(ctx context.Context, obj *bug.LabelChangeOperation) (time.Time, error) {
2018-07-29 19:11:33 +03:00
return obj.Time(), nil
}
type setStatusOperationResolver struct{}
func (setStatusOperationResolver) Date(ctx context.Context, obj *bug.SetStatusOperation) (time.Time, error) {
2018-07-29 19:11:33 +03:00
return obj.Time(), nil
}
func (setStatusOperationResolver) Status(ctx context.Context, obj *bug.SetStatusOperation) (models.Status, error) {
2018-07-29 19:11:33 +03:00
return convertStatus(obj.Status)
}
type setTitleOperationResolver struct{}
func (setTitleOperationResolver) Date(ctx context.Context, obj *bug.SetTitleOperation) (time.Time, error) {
2018-07-29 19:11:33 +03:00
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")
}