From c38dbca84e865d3232a67095b4356a3055ba6155 Mon Sep 17 00:00:00 2001 From: Brian Zoetewey Date: Tue, 29 Oct 2024 10:00:45 -0400 Subject: [PATCH] Add project.type Add response scheme when creating a project Add body to project update Fix create/update project not saving some fields. Add demo flag to Project Request --- api-docs.yml | 29 ++++++++++++++++++++++++----- db/sql/project.go | 7 ++++--- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/api-docs.yml b/api-docs.yml index 8e0b9726..fe4cc024 100644 --- a/api-docs.yml +++ b/api-docs.yml @@ -136,7 +136,7 @@ definitions: ProjectBackup: type: object - example: {"meta":{"name":"homelab","alert":true,"alert_chat":"Test","max_parallel_tasks":0},"templates":[{"inventory":"Build","repository":"Demo","environment":"Empty","name":"Build","playbook":"build.yml","arguments":"[]","allow_override_args_in_task":false,"description":"Build Job","vault_key":null,"type":"build","start_version":"1.0.0","build_template":null,"view":"Build","autorun":false,"survey_vars":[],"suppress_success_alerts":false,"cron":"* * * * *"}],"repositories":[{"name":"Demo","git_url":"https://github.com/semaphoreui/demo-project.git","git_branch":"main","ssh_key":"None"}],"keys":[{"name":"None","type":"none"},{"name":"Vault Password","type":"login_password"}],"views":[{"title":"Build","position":0}],"inventories":[{"name":"Build","inventory":"","ssh_key":"None","become_key":"None","type":"static"},{"name":"Dev","inventory":"","ssh_key":"None","become_key":"None","type":"file"},{"name":"Prod","inventory":"","ssh_key":"None","become_key":"None","type":"file"}],"environments":[{"name":"Empty","password":null,"json":"{}","env":null}]} + example: {"meta":{"name":"homelab","alert":true,"alert_chat":"Test","max_parallel_tasks":0,"type":null},"templates":[{"inventory":"Build","repository":"Demo","environment":"Empty","name":"Build","playbook":"build.yml","arguments":"[]","allow_override_args_in_task":false,"description":"Build Job","vault_key":null,"type":"build","start_version":"1.0.0","build_template":null,"view":"Build","autorun":false,"survey_vars":[],"suppress_success_alerts":false,"cron":"* * * * *"}],"repositories":[{"name":"Demo","git_url":"https://github.com/semaphoreui/demo-project.git","git_branch":"main","ssh_key":"None"}],"keys":[{"name":"None","type":"none"},{"name":"Vault Password","type":"login_password"}],"views":[{"title":"Build","position":0}],"inventories":[{"name":"Build","inventory":"","ssh_key":"None","become_key":"None","type":"static"},{"name":"Dev","inventory":"","ssh_key":"None","become_key":"None","type":"file"},{"name":"Prod","inventory":"","ssh_key":"None","become_key":"None","type":"file"}],"environments":[{"name":"Empty","password":null,"json":"{}","env":null}]} properties: meta: type: object @@ -152,6 +152,10 @@ definitions: max_parallel_tasks: type: integer minimum: 0 + type: + type: + - string + - 'null' templates: type: array items: @@ -304,6 +308,13 @@ definitions: max_parallel_tasks: type: integer minimum: 0 + type: + type: + - string + - 'null' + demo: + description: Create Demo project resources? + type: boolean Project: type: object properties: @@ -326,6 +337,10 @@ definitions: max_parallel_tasks: type: integer minimum: 0 + type: + type: + - string + - 'null' AccessKeyRequest: type: object @@ -1283,6 +1298,8 @@ paths: responses: 201: description: Created project + schema: + $ref: "#/definitions/Project" /projects/restore: post: tags: @@ -1344,10 +1361,12 @@ paths: in: body required: true schema: - type: object - properties: - name: - type: string + allOf: + - $ref: '#/definitions/ProjectRequest' + - properties: + id: + type: integer + minimum: 1 responses: 204: description: Project saved diff --git a/db/sql/project.go b/db/sql/project.go index ba13d5ac..508eb9e3 100644 --- a/db/sql/project.go +++ b/db/sql/project.go @@ -11,8 +11,8 @@ func (d *SqlDb) CreateProject(project db.Project) (newProject db.Project, err er insertId, err := d.insert( "id", - "insert into project(name, created, type) values (?, ?, ?)", - project.Name, project.Created, project.Type) + "insert into project(name, created, type, alert, alert_chat, max_parallel_tasks) values (?, ?, ?, ?, ?, ?)", + project.Name, project.Created, project.Type, project.Alert, project.AlertChat, project.MaxParallelTasks) if err != nil { return @@ -110,11 +110,12 @@ func (d *SqlDb) DeleteProject(projectID int) error { func (d *SqlDb) UpdateProject(project db.Project) error { _, err := d.exec( - "update project set name=?, alert=?, alert_chat=?, max_parallel_tasks=? where id=?", + "update project set name=?, alert=?, alert_chat=?, max_parallel_tasks=?, type=? where id=?", project.Name, project.Alert, project.AlertChat, project.MaxParallelTasks, + project.Type, project.ID) return err }