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"
|
2018-07-29 20:37:06 +03:00
|
|
|
"github.com/MichaelMure/git-bug/graphql/models"
|
2018-09-11 23:04:16 +03:00
|
|
|
"github.com/MichaelMure/git-bug/operations"
|
2018-07-29 19:11:33 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
type addCommentOperationResolver struct{}
|
|
|
|
|
2018-09-25 18:55:20 +03:00
|
|
|
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{}
|
|
|
|
|
2018-09-25 18:55:20 +03:00
|
|
|
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{}
|
|
|
|
|
2018-09-25 18:55:20 +03:00
|
|
|
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{}
|
|
|
|
|
2018-09-25 18:55:20 +03:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2018-07-29 20:37:06 +03:00
|
|
|
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{}
|
|
|
|
|
2018-09-25 18:55:20 +03:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2018-07-29 20:37:06 +03:00
|
|
|
func convertStatus(status bug.Status) (models.Status, error) {
|
2018-07-29 19:11:33 +03:00
|
|
|
switch status {
|
|
|
|
case bug.OpenStatus:
|
2018-07-29 20:37:06 +03:00
|
|
|
return models.StatusOpen, nil
|
2018-07-29 19:11:33 +03:00
|
|
|
case bug.ClosedStatus:
|
2018-07-29 20:37:06 +03:00
|
|
|
return models.StatusClosed, nil
|
2018-07-29 19:11:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return "", fmt.Errorf("Unknown status")
|
|
|
|
}
|