Skip to content

Commit

Permalink
Merge pull request #353 from bonitoo-io/chore/swagger-sync
Browse files Browse the repository at this point in the history
feat: simplified generated code and OSS swagger sync
  • Loading branch information
vlastahajek authored Sep 21, 2022
2 parents 41d5f32 + 37d55fb commit 388612e
Show file tree
Hide file tree
Showing 22 changed files with 17,121 additions and 29,819 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
## [unreleased]
### Features
- [#353](https://github.com/influxdata/influxdb-client-go/pull/353) Simplify generated code.
- [#353](https://github.com/influxdata/influxdb-client-go/pull/353) Regenerate code from swagger.
- [#355](https://github.com/influxdata/influxdb-client-go/pull/355) Upgrade of lib gopkg.in/yaml from v2 to v3

### Bug fixes
- [#354](https://github.com/influxdata/influxdb-client-go/pull/354) More efficient synchronization in WriteAPIBlocking.

### Breaking change
- [#353](https://github.com/influxdata/influxdb-client-go/pull/353):
- Interface `Client` has been extended with `APIClient()` function.
- The generated client API changed:
- Function names are simplified (was `PostDBRPWithResponse`, now `PostDBRP`)
- All functions now accept a context and a single wrapper structure with request body and HTTP parameters
- The functions return deserialized response body or an error (it was a response wrapper with a status code that had to be then validated)

## 2.10.0 [2022-08-25]
### Features
- [#348](https://github.com/influxdata/influxdb-client-go/pull/348) Added `write.Options.Consitency` parameter to support InfluxDB Enterprise.
Expand Down
60 changes: 19 additions & 41 deletions api/authorizations.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ type AuthorizationsAPI interface {

// authorizationsAPI implements AuthorizationsAPI
type authorizationsAPI struct {
apiClient *domain.ClientWithResponses
apiClient *domain.Client
}

// NewAuthorizationsAPI creates new instance of AuthorizationsAPI
func NewAuthorizationsAPI(apiClient *domain.ClientWithResponses) AuthorizationsAPI {
func NewAuthorizationsAPI(apiClient *domain.Client) AuthorizationsAPI {
return &authorizationsAPI{
apiClient: apiClient,
}
Expand Down Expand Up @@ -74,35 +74,23 @@ func (a *authorizationsAPI) FindAuthorizationsByOrgID(ctx context.Context, orgID
}

func (a *authorizationsAPI) listAuthorizations(ctx context.Context, query *domain.GetAuthorizationsParams) (*[]domain.Authorization, error) {
response, err := a.apiClient.GetAuthorizationsWithResponse(ctx, query)
response, err := a.apiClient.GetAuthorizations(ctx, query)
if err != nil {
return nil, err
}
if response.JSONDefault != nil {
return nil, domain.ErrorToHTTPError(response.JSONDefault, response.StatusCode())
}
return response.JSON200.Authorizations, nil
return response.Authorizations, nil
}

func (a *authorizationsAPI) CreateAuthorization(ctx context.Context, authorization *domain.Authorization) (*domain.Authorization, error) {
params := &domain.PostAuthorizationsParams{}
req := domain.PostAuthorizationsJSONRequestBody{
AuthorizationUpdateRequest: authorization.AuthorizationUpdateRequest,
OrgID: authorization.OrgID,
Permissions: authorization.Permissions,
UserID: authorization.UserID,
}
response, err := a.apiClient.PostAuthorizationsWithResponse(ctx, params, req)
if err != nil {
return nil, err
}
if response.JSONDefault != nil {
return nil, domain.ErrorToHTTPError(response.JSONDefault, response.StatusCode())
}
if response.JSON400 != nil {
return nil, domain.ErrorToHTTPError(response.JSON400, response.StatusCode())
params := &domain.PostAuthorizationsAllParams{
Body: domain.PostAuthorizationsJSONRequestBody{
AuthorizationUpdateRequest: authorization.AuthorizationUpdateRequest,
OrgID: authorization.OrgID,
Permissions: authorization.Permissions,
UserID: authorization.UserID,
},
}
return response.JSON201, nil
return a.apiClient.PostAuthorizations(ctx, params)
}

func (a *authorizationsAPI) CreateAuthorizationWithOrgID(ctx context.Context, orgID string, permissions []domain.Permission) (*domain.Authorization, error) {
Expand All @@ -116,16 +104,11 @@ func (a *authorizationsAPI) CreateAuthorizationWithOrgID(ctx context.Context, or
}

func (a *authorizationsAPI) UpdateAuthorizationStatusWithID(ctx context.Context, authID string, status domain.AuthorizationUpdateRequestStatus) (*domain.Authorization, error) {
params := &domain.PatchAuthorizationsIDParams{}
body := &domain.PatchAuthorizationsIDJSONRequestBody{Status: &status}
response, err := a.apiClient.PatchAuthorizationsIDWithResponse(ctx, authID, params, *body)
if err != nil {
return nil, err
}
if response.JSONDefault != nil {
return nil, domain.ErrorToHTTPError(response.JSONDefault, response.StatusCode())
params := &domain.PatchAuthorizationsIDAllParams{
Body: domain.PatchAuthorizationsIDJSONRequestBody{Status: &status},
AuthID: authID,
}
return response.JSON200, nil
return a.apiClient.PatchAuthorizationsID(ctx, params)
}

func (a *authorizationsAPI) UpdateAuthorizationStatus(ctx context.Context, authorization *domain.Authorization, status domain.AuthorizationUpdateRequestStatus) (*domain.Authorization, error) {
Expand All @@ -137,13 +120,8 @@ func (a *authorizationsAPI) DeleteAuthorization(ctx context.Context, authorizati
}

func (a *authorizationsAPI) DeleteAuthorizationWithID(ctx context.Context, authID string) error {
params := &domain.DeleteAuthorizationsIDParams{}
response, err := a.apiClient.DeleteAuthorizationsIDWithResponse(ctx, authID, params)
if err != nil {
return err
}
if response.JSONDefault != nil {
return domain.ErrorToHTTPError(response.JSONDefault, response.StatusCode())
params := &domain.DeleteAuthorizationsIDAllParams{
AuthID: authID,
}
return nil
return a.apiClient.DeleteAuthorizationsID(ctx, params)
}
Loading

0 comments on commit 388612e

Please sign in to comment.