mirror of
https://github.com/SecurityBrewery/catalyst.git
synced 2025-12-06 15:22:47 +01:00
@@ -2,27 +2,40 @@ package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/arangodb/go-driver"
|
||||
|
||||
"github.com/SecurityBrewery/catalyst/database"
|
||||
"github.com/SecurityBrewery/catalyst/generated/restapi/api"
|
||||
"github.com/SecurityBrewery/catalyst/generated/restapi/operations/automations"
|
||||
)
|
||||
|
||||
func automationID(id string) []driver.DocumentID {
|
||||
return []driver.DocumentID{driver.DocumentID(fmt.Sprintf("%s/%s", database.AutomationCollectionName, id))}
|
||||
}
|
||||
|
||||
func (s *Service) CreateAutomation(ctx context.Context, params *automations.CreateAutomationParams) *api.Response {
|
||||
return response(s.database.AutomationCreate(ctx, params.Automation))
|
||||
i, err := s.database.AutomationCreate(ctx, params.Automation)
|
||||
return s.response(ctx, "CreateAutomation", automationID(i.ID), i, err)
|
||||
}
|
||||
|
||||
func (s *Service) GetAutomation(ctx context.Context, params *automations.GetAutomationParams) *api.Response {
|
||||
return response(s.database.AutomationGet(ctx, params.ID))
|
||||
i, err := s.database.AutomationGet(ctx, params.ID)
|
||||
return s.response(ctx, "GetAutomation", nil, i, err)
|
||||
}
|
||||
|
||||
func (s *Service) UpdateAutomation(ctx context.Context, params *automations.UpdateAutomationParams) *api.Response {
|
||||
return response(s.database.AutomationUpdate(ctx, params.ID, params.Automation))
|
||||
i, err := s.database.AutomationUpdate(ctx, params.ID, params.Automation)
|
||||
return s.response(ctx, "UpdateAutomation", automationID(i.ID), i, err)
|
||||
}
|
||||
|
||||
func (s *Service) DeleteAutomation(ctx context.Context, params *automations.DeleteAutomationParams) *api.Response {
|
||||
return response(nil, s.database.AutomationDelete(ctx, params.ID))
|
||||
err := s.database.AutomationDelete(ctx, params.ID)
|
||||
return s.response(ctx, "DeleteAutomation", automationID(params.ID), nil, err)
|
||||
}
|
||||
|
||||
func (s *Service) ListAutomations(ctx context.Context) *api.Response {
|
||||
return response(s.database.AutomationList(ctx))
|
||||
i, err := s.database.AutomationList(ctx)
|
||||
return s.response(ctx, "ListAutomations", nil, i, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user