Add control state transitions graphql resolver
Signed-off-by: gearnode <bryan@frimin.fr>
This commit is contained in:
@@ -14,10 +14,10 @@ interface Node {
|
||||
}
|
||||
|
||||
enum ControlState {
|
||||
NotStarted
|
||||
InProgress
|
||||
NotApplicable
|
||||
Implemented
|
||||
NOT_STARTED
|
||||
IN_PROGRESS
|
||||
NOT_APPLICABLE
|
||||
IMPLEMENTED
|
||||
}
|
||||
|
||||
|
||||
@@ -85,6 +85,13 @@ type Control implements Node {
|
||||
description: String!
|
||||
state: ControlState!
|
||||
|
||||
stateTransisions(
|
||||
first: Int
|
||||
after: CursorKey
|
||||
last: Int
|
||||
before: CursorKey
|
||||
): ControlStateTransitionConnection! @goField(forceResolver: true)
|
||||
|
||||
tasks(
|
||||
first: Int
|
||||
after: CursorKey
|
||||
@@ -96,6 +103,25 @@ type Control implements Node {
|
||||
updatedAt: Datetime!
|
||||
}
|
||||
|
||||
type ControlStateTransitionConnection {
|
||||
edges: [ControlStateTransitionEdge!]!
|
||||
pageInfo: PageInfo!
|
||||
}
|
||||
|
||||
type ControlStateTransitionEdge {
|
||||
cursor: CursorKey!
|
||||
node: ControlStateTransition!
|
||||
}
|
||||
|
||||
type ControlStateTransition {
|
||||
id: ID!
|
||||
fromState: ControlState
|
||||
toState: ControlState!
|
||||
reason: String
|
||||
createdAt: Datetime!
|
||||
updatedAt: Datetime!
|
||||
}
|
||||
|
||||
type TaskConnection {
|
||||
edges: [TaskEdge!]!
|
||||
pageInfo: PageInfo!
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
59
pkg/api/console/v1/types/control_state_transition.go
Normal file
59
pkg/api/console/v1/types/control_state_transition.go
Normal file
@@ -0,0 +1,59 @@
|
||||
// Copyright (c) 2025 Probo Inc <hello@getprobo.com>.
|
||||
//
|
||||
// Permission to use, copy, modify, and/or distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice appear in all copies.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
// PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
package types
|
||||
|
||||
import (
|
||||
"github.com/getprobo/probo/pkg/probo/coredata"
|
||||
"github.com/getprobo/probo/pkg/probo/coredata/page"
|
||||
)
|
||||
|
||||
func NewControlStateTransitionConnection(
|
||||
p *page.Page[*coredata.ControlStateTransition],
|
||||
) *ControlStateTransitionConnection {
|
||||
var edges = make([]*ControlStateTransitionEdge, len(p.Data))
|
||||
|
||||
for i := range edges {
|
||||
edges[i] = NewControlStateTransitionEdge(p.Data[i])
|
||||
}
|
||||
|
||||
return &ControlStateTransitionConnection{
|
||||
Edges: edges,
|
||||
PageInfo: NewPageInfo(p),
|
||||
}
|
||||
}
|
||||
|
||||
func NewControlStateTransitionEdge(cst *coredata.ControlStateTransition) *ControlStateTransitionEdge {
|
||||
return &ControlStateTransitionEdge{
|
||||
Cursor: cst.CursorKey(),
|
||||
Node: NewControlStateTransition(cst),
|
||||
}
|
||||
}
|
||||
|
||||
func NewControlStateTransition(cst *coredata.ControlStateTransition) *ControlStateTransition {
|
||||
var fromState *ControlState
|
||||
if cst.FromState != nil {
|
||||
val := ControlState((*cst.FromState).String())
|
||||
fromState = &val
|
||||
}
|
||||
|
||||
return &ControlStateTransition{
|
||||
ID: cst.ID,
|
||||
FromState: fromState,
|
||||
ToState: ControlState(cst.ToState.String()),
|
||||
Reason: cst.Reason,
|
||||
CreatedAt: cst.CreatedAt,
|
||||
UpdatedAt: cst.UpdatedAt,
|
||||
}
|
||||
}
|
||||
@@ -18,13 +18,14 @@ type Node interface {
|
||||
}
|
||||
|
||||
type Control struct {
|
||||
ID gid.GID `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
State ControlState `json:"state"`
|
||||
Tasks *TaskConnection `json:"tasks"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
ID gid.GID `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
State ControlState `json:"state"`
|
||||
StateTransisions *ControlStateTransitionConnection `json:"stateTransisions"`
|
||||
Tasks *TaskConnection `json:"tasks"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
}
|
||||
|
||||
func (Control) IsNode() {}
|
||||
@@ -40,6 +41,25 @@ type ControlEdge struct {
|
||||
Node *Control `json:"node"`
|
||||
}
|
||||
|
||||
type ControlStateTransition struct {
|
||||
ID gid.GID `json:"id"`
|
||||
FromState *ControlState `json:"fromState,omitempty"`
|
||||
ToState ControlState `json:"toState"`
|
||||
Reason *string `json:"reason,omitempty"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
}
|
||||
|
||||
type ControlStateTransitionConnection struct {
|
||||
Edges []*ControlStateTransitionEdge `json:"edges"`
|
||||
PageInfo *PageInfo `json:"pageInfo"`
|
||||
}
|
||||
|
||||
type ControlStateTransitionEdge struct {
|
||||
Cursor page.CursorKey `json:"cursor"`
|
||||
Node *ControlStateTransition `json:"node"`
|
||||
}
|
||||
|
||||
type Framework struct {
|
||||
ID gid.GID `json:"id"`
|
||||
Name string `json:"name"`
|
||||
@@ -106,10 +126,10 @@ type TaskEdge struct {
|
||||
type ControlState string
|
||||
|
||||
const (
|
||||
ControlStateNotStarted ControlState = "NotStarted"
|
||||
ControlStateInProgress ControlState = "InProgress"
|
||||
ControlStateNotApplicable ControlState = "NotApplicable"
|
||||
ControlStateImplemented ControlState = "Implemented"
|
||||
ControlStateNotStarted ControlState = "NOT_STARTED"
|
||||
ControlStateInProgress ControlState = "IN_PROGRESS"
|
||||
ControlStateNotApplicable ControlState = "NOT_APPLICABLE"
|
||||
ControlStateImplemented ControlState = "IMPLEMENTED"
|
||||
)
|
||||
|
||||
var AllControlState = []ControlState{
|
||||
|
||||
@@ -16,6 +16,18 @@ import (
|
||||
"github.com/vektah/gqlparser/v2/gqlerror"
|
||||
)
|
||||
|
||||
// StateTransisions is the resolver for the stateTransisions field.
|
||||
func (r *controlResolver) StateTransisions(ctx context.Context, obj *types.Control, first *int, after *page.CursorKey, last *int, before *page.CursorKey) (*types.ControlStateTransitionConnection, error) {
|
||||
cursor := types.NewCursor(first, after, last, before)
|
||||
|
||||
page, err := r.svc.ListControlStateTransitions(ctx, obj.ID, cursor)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot list control tasks: %w", err)
|
||||
}
|
||||
|
||||
return types.NewControlStateTransitionConnection(page), nil
|
||||
}
|
||||
|
||||
// Tasks is the resolver for the tasks field.
|
||||
func (r *controlResolver) Tasks(ctx context.Context, obj *types.Control, first *int, after *page.CursorKey, last *int, before *page.CursorKey) (*types.TaskConnection, error) {
|
||||
cursor := types.NewCursor(first, after, last, before)
|
||||
|
||||
Reference in New Issue
Block a user