Skip to content

Commit

Permalink
Merge pull request #156 from ans-group/create-API-application-return-key
Browse files Browse the repository at this point in the history
Create application now returns the key value in a struct with the ID
  • Loading branch information
PCloughster authored Aug 16, 2024
2 parents 3a5dfa8 + ac4c676 commit 60cec46
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
6 changes: 6 additions & 0 deletions pkg/service/account/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,18 @@ type Client struct {
// Application represents an API Application
type Application struct {
ID string `json:"id"`
Key string `json:"key"`
Name string `json:"name"`
Description string `json:"description"`
CreatedAt connection.DateTime `json:"created_at"`
CreatedBy string `json:"created_by"`
}

type CreateApplicationResponse struct {
ID string `json:"id"`
Key string `json:"key"`
}

type ApplicationService struct {
ID string `json:"id"`
Name string `json:"name"`
Expand Down
5 changes: 5 additions & 0 deletions pkg/service/account/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ type CreateApplicationRequest struct {
Description string `json:"description"`
}

type UpdateApplicationRequest struct {
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
}

type SetServiceRequest struct {
Scopes []ApplicationServiceScope `json:"scopes"`
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/service/account/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ type AccountService interface {
GetServices(parameters connection.APIRequestParameters) ([]ApplicationService, error)
GetServicesPaginated(parameters connection.APIRequestParameters) (*connection.Paginated[ApplicationService], error)
GetApplication(appID string) (Application, error)
CreateApplication(req CreateApplicationRequest) (string, error)
CreateApplication(req CreateApplicationRequest) (CreateApplicationResponse, error)
UpdateApplication(req UpdateApplicationRequest) error
GetApplicationServices(appID string) (ApplicationServiceMapping, error)
SetApplicationServices(appID string, req SetServiceRequest) error
GetApplicationRestrictions(appID string) (ApplicationRestriction, error)
Expand Down
22 changes: 18 additions & 4 deletions pkg/service/account/service_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,28 @@ func (s *Service) getServicesPaginatedResponseBody(parameters connection.APIRequ
return body, response.HandleResponse(body, nil)
}

func (s *Service) CreateApplication(req CreateApplicationRequest) (string, error) {
func (s *Service) CreateApplication(req CreateApplicationRequest) (CreateApplicationResponse, error) {
body, err := s.createApplicationResponseBody(req)

return body.Data.ID, err
return body.Data, err
}

func (s *Service) createApplicationResponseBody(req CreateApplicationRequest) (*connection.APIResponseBodyData[CreateApplicationResponse], error) {
return connection.Post[CreateApplicationResponse](s.connection, "/account/v1/applications", &req)
}

func (s *Service) createApplicationResponseBody(req CreateApplicationRequest) (*connection.APIResponseBodyData[Application], error) {
return connection.Post[Application](s.connection, "/account/v1/applications", &req)
func (s *Service) UpdateApplication(appID string, req UpdateApplicationRequest) error {
_, err := s.updateApplicationResponseBody(appID, req)

return err
}

func (s *Service) updateApplicationResponseBody(appID string, req UpdateApplicationRequest) (*connection.APIResponseBodyData[Application], error) {
if appID == "" {
return &connection.APIResponseBodyData[Application]{}, fmt.Errorf("invalid application id")
}

return connection.Patch[Application](s.connection, fmt.Sprintf("/account/v1/applications/%s", appID), &req)
}

// GetApplicationServices retrieves the services and roles of an application by id
Expand Down

0 comments on commit 60cec46

Please sign in to comment.