Skip to content

Commit

Permalink
write service/project module (#6)
Browse files Browse the repository at this point in the history
* commit for rebasing

* created project module
  • Loading branch information
dannelmlj authored Jul 26, 2023
1 parent 4e1fb95 commit 0fb377c
Show file tree
Hide file tree
Showing 7 changed files with 201 additions and 6 deletions.
102 changes: 102 additions & 0 deletions api/generated/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ go 1.20
require github.com/Yamashou/gqlgenc v0.14.0

require (
github.com/99designs/gqlgen v0.17.34 // indirect
github.com/vektah/gqlparser/v2 v2.5.6 // indirect
github.com/99designs/gqlgen v0.17.35 // indirect
github.com/vektah/gqlparser/v2 v2.5.8 // indirect
)
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/99designs/gqlgen v0.17.34 h1:5cS5/OKFguQt+Ws56uj9FlG2xm1IlcJWNF2jrMIKYFQ=
github.com/99designs/gqlgen v0.17.34/go.mod h1:Axcd3jIFHBVcqzixujJQr1wGqE+lGTpz6u4iZBZg1G8=
github.com/99designs/gqlgen v0.17.35 h1:r0KF1xL3cPMyUArNWeC3e2Ckuc4iiLm7bj5xzYZQYbQ=
github.com/99designs/gqlgen v0.17.35/go.mod h1:Vlf7TeY3ZdVI9SagB5IZE8CYhpq8kJPCVPJ7MrlVoX0=
github.com/Yamashou/gqlgenc v0.14.0 h1:KVzUuVQKfl4Phm5Cw4yeFThDAxZoIBR9XLoK/4O1O6U=
github.com/Yamashou/gqlgenc v0.14.0/go.mod h1:+z+FRCtGrNmgTxweAUiCodOmQJLTCNtnRNAqhewf1Q8=
github.com/agnivade/levenshtein v1.1.1/go.mod h1:veldBMzWxcCG2ZvUTKD2kJNRdCk5hVbJomOvKkmgYbo=
Expand All @@ -21,8 +21,8 @@ github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NF
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/vektah/gqlparser/v2 v2.5.6 h1:Ou14T0N1s191eRMZ1gARVqohcbe1e8FrcONScsq8cRU=
github.com/vektah/gqlparser/v2 v2.5.6/go.mod h1:z8xXUff237NntSuH8mLFijZ+1tjV1swDbpDqjJmk6ME=
github.com/vektah/gqlparser/v2 v2.5.8 h1:pm6WOnGdzFOCfcQo9L3+xzW51mKrlwTEg4Wr7AH1JW4=
github.com/vektah/gqlparser/v2 v2.5.8/go.mod h1:z8xXUff237NntSuH8mLFijZ+1tjV1swDbpDqjJmk6ME=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
Expand Down
29 changes: 29 additions & 0 deletions service/project/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package project

import (
"github.com/deploifai/sdk-go/api"
"github.com/deploifai/sdk-go/config"
"github.com/deploifai/sdk-go/credentials"
)

type Client struct {
options Options
}

type Options struct {
Credentials credentials.Provider
API api.Provider
}

func New(options Options) *Client {
return &Client{options: options}
}

func NewFromConfig(cfg config.Config) *Client {
opts := Options{
Credentials: cfg.Credentials,
API: cfg.API,
}

return New(opts)
}
20 changes: 20 additions & 0 deletions service/project/create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package project

import (
"context"

"github.com/deploifai/sdk-go/api/generated"
)

//Create a new project for the given account.

func (c *Client) Create(ctx context.Context, whereAccount generated.AccountWhereUniqueInput, data generated.CreateProjectInput) (project generated.ProjectFragment, err error) {

responseData, err := c.options.API.GetGQLClient().CreateProject(ctx, whereAccount, data)
if err != nil {
return project, c.options.API.ProcessGQLError(err)
}

return *responseData.GetCreateProject(), nil

}
22 changes: 22 additions & 0 deletions service/project/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package project

import (
"context"

"github.com/deploifai/sdk-go/api/generated"
)

// Returns a list of cloud profiles for the given account

func (c *Client) List(ctx context.Context, whereAccount generated.AccountWhereUniqueInput, whereProject *generated.ProjectWhereInput) (projects []generated.ProjectFragment, err error) {

data, err := c.options.API.GetGQLClient().GetProjects(ctx, whereAccount, whereProject)
if err != nil {
return nil, c.options.API.ProcessGQLError(err)
}
for _, proj := range data.GetProjects() {
projects = append(projects, *proj)
}

return projects, nil
}
22 changes: 22 additions & 0 deletions service/project/query.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
fragment ProjectFragment on Project {
id
name
createdAt
}


query GetProjects($whereAccount: AccountWhereUniqueInput!, $whereProject: ProjectWhereInput) {
projects(whereAccount: $whereAccount, whereProject: $whereProject) {
...ProjectFragment
}
}


mutation CreateProject($whereAccount: AccountWhereUniqueInput!, $data: CreateProjectInput!){
createProject(
data: $data,
whereAccount: $whereAccount
){
...ProjectFragment
}
}

0 comments on commit 0fb377c

Please sign in to comment.