Add ControlState type

Signed-off-by: gearnode <bryan@frimin.fr>
This commit is contained in:
gearnode
2025-01-27 18:18:43 +01:00
parent 422c96a250
commit 6631543824
5 changed files with 169 additions and 7 deletions

View File

@@ -13,6 +13,14 @@ interface Node {
id: ID!
}
enum ControlState {
NotStarted
InProgress
NotApplicable
Implemented
}
type PageInfo {
hasNextPage: Boolean!
hasPreviousPage: Boolean!
@@ -75,7 +83,7 @@ type Control implements Node {
id: ID!
name: String!
description: String!
state: String!
state: ControlState!
tasks(
first: Int

View File

@@ -556,6 +556,14 @@ interface Node {
id: ID!
}
enum ControlState {
NotStarted
InProgress
NotApplicable
Implemented
}
type PageInfo {
hasNextPage: Boolean!
hasPreviousPage: Boolean!
@@ -618,7 +626,7 @@ type Control implements Node {
id: ID!
name: String!
description: String!
state: String!
state: ControlState!
tasks(
first: Int
@@ -1124,9 +1132,9 @@ func (ec *executionContext) _Control_state(ctx context.Context, field graphql.Co
}
return graphql.Null
}
res := resTmp.(string)
res := resTmp.(types.ControlState)
fc.Result = res
return ec.marshalNString2string(ctx, field.Selections, res)
return ec.marshalNControlState2githubᚗcomᚋgetproboᚋproboᚋpkgᚋapiᚋconsoleᚋv1ᚋtypesᚐControlState(ctx, field.Selections, res)
}
func (ec *executionContext) fieldContext_Control_state(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
@@ -1136,7 +1144,7 @@ func (ec *executionContext) fieldContext_Control_state(_ context.Context, field
IsMethod: false,
IsResolver: false,
Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
return nil, errors.New("field of type String does not have child fields")
return nil, errors.New("field of type ControlState does not have child fields")
},
}
return fc, nil
@@ -5415,6 +5423,16 @@ func (ec *executionContext) marshalNControlEdge2ᚖgithubᚗcomᚋgetproboᚋpro
return ec._ControlEdge(ctx, sel, v)
}
func (ec *executionContext) unmarshalNControlState2githubᚗcomᚋgetproboᚋproboᚋpkgᚋapiᚋconsoleᚋv1ᚋtypesᚐControlState(ctx context.Context, v any) (types.ControlState, error) {
var res types.ControlState
err := res.UnmarshalGQL(v)
return res, graphql.ErrorOnPath(ctx, err)
}
func (ec *executionContext) marshalNControlState2githubᚗcomᚋgetproboᚋproboᚋpkgᚋapiᚋconsoleᚋv1ᚋtypesᚐControlState(ctx context.Context, sel ast.SelectionSet, v types.ControlState) graphql.Marshaler {
return v
}
func (ec *executionContext) unmarshalNCursorKey2githubᚗcomᚋgetproboᚋproboᚋpkgᚋproboᚋcoredataᚋpageᚐCursorKey(ctx context.Context, v any) (page.CursorKey, error) {
res, err := types.UnmarshalCursorKeyScalar(v)
return res, graphql.ErrorOnPath(ctx, err)

View File

@@ -44,7 +44,7 @@ func NewControl(c *coredata.Control) *Control {
ID: c.ID,
Name: c.Name,
Description: c.Description,
State: string(c.State),
State: ControlState(c.State.String()),
CreatedAt: c.CreatedAt,
UpdatedAt: c.UpdatedAt,
}

View File

@@ -3,6 +3,9 @@
package types
import (
"fmt"
"io"
"strconv"
"time"
"github.com/getprobo/probo/pkg/probo/coredata/gid"
@@ -18,7 +21,7 @@ type Control struct {
ID gid.GID `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
State string `json:"state"`
State ControlState `json:"state"`
Tasks *TaskConnection `json:"tasks"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
@@ -99,3 +102,48 @@ type TaskEdge struct {
Cursor page.CursorKey `json:"cursor"`
Node *Task `json:"node"`
}
type ControlState string
const (
ControlStateNotStarted ControlState = "NotStarted"
ControlStateInProgress ControlState = "InProgress"
ControlStateNotApplicable ControlState = "NotApplicable"
ControlStateImplemented ControlState = "Implemented"
)
var AllControlState = []ControlState{
ControlStateNotStarted,
ControlStateInProgress,
ControlStateNotApplicable,
ControlStateImplemented,
}
func (e ControlState) IsValid() bool {
switch e {
case ControlStateNotStarted, ControlStateInProgress, ControlStateNotApplicable, ControlStateImplemented:
return true
}
return false
}
func (e ControlState) String() string {
return string(e)
}
func (e *ControlState) UnmarshalGQL(v any) error {
str, ok := v.(string)
if !ok {
return fmt.Errorf("enums must be strings")
}
*e = ControlState(str)
if !e.IsValid() {
return fmt.Errorf("%s is not a valid ControlState", str)
}
return nil
}
func (e ControlState) MarshalGQL(w io.Writer) {
fmt.Fprint(w, strconv.Quote(e.String()))
}