Change code generator (#4)

* Change code generator
* Remove gin
This commit is contained in:
Jonas Plum
2022-01-08 00:48:44 +01:00
committed by GitHub
parent b5dd0cfacd
commit 8333ea88a8
148 changed files with 3077 additions and 23976 deletions

View File

@@ -7,11 +7,11 @@ import (
"github.com/arangodb/go-driver"
"github.com/SecurityBrewery/catalyst/database/busdb"
"github.com/SecurityBrewery/catalyst/generated/models"
"github.com/SecurityBrewery/catalyst/generated/model"
)
func toAutomation(doc *models.AutomationForm) interface{} {
return &models.Automation{
func toAutomation(doc *model.AutomationForm) interface{} {
return &model.Automation{
Image: doc.Image,
Script: doc.Script,
Schema: doc.Schema,
@@ -19,8 +19,8 @@ func toAutomation(doc *models.AutomationForm) interface{} {
}
}
func toAutomationResponse(id string, doc models.Automation) *models.AutomationResponse {
return &models.AutomationResponse{
func toAutomationResponse(id string, doc model.Automation) *model.AutomationResponse {
return &model.AutomationResponse{
ID: id,
Image: doc.Image,
Script: doc.Script,
@@ -29,7 +29,7 @@ func toAutomationResponse(id string, doc models.Automation) *models.AutomationRe
}
}
func (db *Database) AutomationCreate(ctx context.Context, automation *models.AutomationForm) (*models.AutomationResponse, error) {
func (db *Database) AutomationCreate(ctx context.Context, automation *model.AutomationForm) (*model.AutomationResponse, error) {
if automation == nil {
return nil, errors.New("requires automation")
}
@@ -37,7 +37,7 @@ func (db *Database) AutomationCreate(ctx context.Context, automation *models.Aut
return nil, errors.New("requires automation ID")
}
var doc models.Automation
var doc model.Automation
newctx := driver.WithReturnNew(ctx, &doc)
meta, err := db.automationCollection.CreateDocument(ctx, newctx, automation.ID, toAutomation(automation))
@@ -48,8 +48,8 @@ func (db *Database) AutomationCreate(ctx context.Context, automation *models.Aut
return toAutomationResponse(meta.Key, doc), nil
}
func (db *Database) AutomationGet(ctx context.Context, id string) (*models.AutomationResponse, error) {
var doc models.Automation
func (db *Database) AutomationGet(ctx context.Context, id string) (*model.AutomationResponse, error) {
var doc model.Automation
meta, err := db.automationCollection.ReadDocument(ctx, id, &doc)
if err != nil {
return nil, err
@@ -58,8 +58,8 @@ func (db *Database) AutomationGet(ctx context.Context, id string) (*models.Autom
return toAutomationResponse(meta.Key, doc), nil
}
func (db *Database) AutomationUpdate(ctx context.Context, id string, automation *models.AutomationForm) (*models.AutomationResponse, error) {
var doc models.Automation
func (db *Database) AutomationUpdate(ctx context.Context, id string, automation *model.AutomationForm) (*model.AutomationResponse, error) {
var doc model.Automation
ctx = driver.WithReturnNew(ctx, &doc)
meta, err := db.automationCollection.ReplaceDocument(ctx, id, toAutomation(automation))
@@ -75,16 +75,16 @@ func (db *Database) AutomationDelete(ctx context.Context, id string) error {
return err
}
func (db *Database) AutomationList(ctx context.Context) ([]*models.AutomationResponse, error) {
func (db *Database) AutomationList(ctx context.Context) ([]*model.AutomationResponse, error) {
query := "FOR d IN @@collection SORT d._key ASC RETURN UNSET(d, 'script')"
cursor, _, err := db.Query(ctx, query, map[string]interface{}{"@collection": AutomationCollectionName}, busdb.ReadOperation)
if err != nil {
return nil, err
}
defer cursor.Close()
var docs []*models.AutomationResponse
var docs []*model.AutomationResponse
for {
var doc models.Automation
var doc model.Automation
meta, err := cursor.ReadDocument(ctx, &doc)
if driver.IsNoMoreDocuments(err) {
break