From 74fd548fa91ed3d2ccf71485386f2b639fc293fa Mon Sep 17 00:00:00 2001 From: Denis Arh Date: Wed, 9 Jan 2019 19:54:41 +0100 Subject: [PATCH] Remove workflow & jobs stubs --- api/crm/spec.json | 313 ------------------------------- api/crm/spec/job.json | 184 ------------------ api/crm/spec/workflow.json | 134 -------------- crm/repository/job.go | 29 --- crm/repository/workflow.go | 29 --- crm/rest/handlers/job.go | 107 ----------- crm/rest/handlers/workflow.go | 97 ---------- crm/rest/job.go | 46 ----- crm/rest/request/job.go | 340 ---------------------------------- crm/rest/request/workflow.go | 266 -------------------------- crm/rest/workflow.go | 44 ----- crm/service/job.go | 36 ---- crm/service/workflow.go | 36 ---- crm/types/job.go | 5 - crm/types/workflow.go | 27 --- docs/crm/README.md | 102 ---------- 16 files changed, 1795 deletions(-) delete mode 100644 api/crm/spec/job.json delete mode 100644 api/crm/spec/workflow.json delete mode 100644 crm/repository/job.go delete mode 100644 crm/repository/workflow.go delete mode 100644 crm/rest/handlers/job.go delete mode 100644 crm/rest/handlers/workflow.go delete mode 100644 crm/rest/job.go delete mode 100644 crm/rest/request/job.go delete mode 100644 crm/rest/request/workflow.go delete mode 100644 crm/rest/workflow.go delete mode 100644 crm/service/job.go delete mode 100644 crm/service/workflow.go delete mode 100644 crm/types/job.go delete mode 100644 crm/types/workflow.go diff --git a/api/crm/spec.json b/api/crm/spec.json index 6baa2e962..c6ad59bfc 100644 --- a/api/crm/spec.json +++ b/api/crm/spec.json @@ -1,317 +1,4 @@ [ - { - "title": "Workflows", - "description": "CRM workflow definitions", - "package": "crm", - "entrypoint": "workflow", - "path": "/workflow", - "authentication": [], - "struct": [ - { - "imports": [ - "github.com/crusttech/crust/crm/types" - ] - } - ], - "apis": [ - { - "name": "list", - "method": "GET", - "path": "/", - "title": "List available workflows" - }, - { - "name": "create", - "path": "/", - "method": "POST", - "title": "Create new workflow", - "parameters": { - "post": [ - { - "type": "string", - "name": "name", - "required": true, - "title": "Workflow name" - }, - { - "type": "types.WorkflowTaskSet", - "name": "tasks", - "required": false, - "title": "Type ID" - }, - { - "type": "types.WorkflowTaskSet", - "name": "onError", - "required": false, - "title": "Type ID" - }, - { - "type": "int", - "name": "timeout", - "required": false, - "title": "Timeout in seconds" - } - ] - } - }, - { - "name": "get", - "method": "GET", - "path": "/{workflowID}", - "title": "Get workflow details", - "parameters": { - "path": [ - { - "type": "string", - "name": "workflowID", - "required": true, - "title": "Workflow ID" - } - ] - } - }, - { - "name": "update", - "method": "POST", - "path": "/{workflowID}", - "title": "Update workflow details", - "parameters": { - "path": [ - { - "type": "string", - "name": "workflowID", - "required": true, - "title": "Workflow ID" - } - ], - "post": [ - { - "type": "string", - "name": "name", - "required": true, - "title": "Workflow name" - }, - { - "type": "types.WorkflowTaskSet", - "name": "tasks", - "required": false, - "title": "Type ID" - }, - { - "type": "types.WorkflowTaskSet", - "name": "onError", - "required": false, - "title": "Type ID" - }, - { - "type": "int", - "name": "timeout", - "required": false, - "title": "Timeout in seconds" - } - ] - } - }, - { - "name": "delete", - "method": "DELETE", - "path": "/{workflowID}", - "title": "Delete workflow", - "parameters": { - "path": [ - { - "type": "string", - "name": "workflowID", - "required": true, - "title": "Workflow ID" - } - ] - } - } - ] - }, - { - "title": "Jobs", - "description": "Workflow Jobs", - "package": "crm", - "entrypoint": "job", - "path": "/job", - "authentication": [], - "struct": [ - { - "imports": [ - "github.com/crusttech/crust/crm/types", - "sqlxTypes github.com/jmoiron/sqlx/types" - ] - } - ], - "apis": [ - { - "name": "list", - "method": "GET", - "path": "/", - "title": "List jobs", - "parameters": { - "get": [ - { - "type": "string", - "name": "status", - "required": false, - "title": "Job status (`ok`, `error`, `running`, `cancelled` or `queued`)" - }, - { - "name": "page", - "type": "int", - "required": false, - "title": "Page number (0 based)" - }, - { - "name": "perPage", - "type": "int", - "required": false, - "title": "Returned items per page (default 50)" - } - ] - } - }, - { - "name": "run", - "path": "/", - "method": "POST", - "title": "Create a new job", - "parameters": { - "post": [ - { - "type": "string", - "name": "workflowID", - "required": true, - "title": "Workflow ID" - }, - { - "type": "string", - "name": "startAt", - "required": false, - "title": "Start datetime for a delayed job" - }, - { - "type": "types.JobParameterSet", - "name": "parameters", - "required": false, - "title": "Extra job parameters (map[string]string)" - } - ] - } - }, - { - "name": "get", - "method": "GET", - "path": "/{jobID}", - "title": "Get job details", - "parameters": { - "path": [ - { - "type": "string", - "name": "jobID", - "required": true, - "title": "Job ID" - } - ] - } - }, - { - "name": "logs", - "method": "GET", - "path": "/{jobID}/logs", - "title": "Get job logs", - "parameters": { - "path": [ - { - "type": "string", - "name": "jobID", - "required": true, - "title": "Job ID" - }, - { - "name": "page", - "type": "int", - "required": false, - "title": "Page number (0 based)" - }, - { - "name": "perPage", - "type": "int", - "required": false, - "title": "Returned items per page (default 50)" - } - ] - } - }, - { - "name": "update", - "method": "POST", - "path": "/{jobID}", - "title": "Update job details", - "parameters": { - "path": [ - { - "type": "string", - "name": "jobID", - "required": true, - "title": "Job ID" - } - ], - "post": [ - { - "type": "string", - "name": "status", - "required": false, - "title": "Job status (`ok`, `error`, `running`, `cancelled` or `queued`)" - }, - { - "type": "sqlxTypes.JSONText", - "name": "log", - "required": false, - "title": "Job log item (append-only)" - }, - { - "type": "string", - "name": "workflowID", - "required": false, - "title": "Workflow ID" - }, - { - "type": "string", - "name": "startAt", - "required": false, - "title": "Start datetime for a delayed job" - }, - { - "type": "types.JobParameterSet", - "name": "parameters", - "required": false, - "title": "Extra job parameters (map[string]string)" - } - ] - } - }, - { - "name": "delete", - "method": "DELETE", - "path": "/{jobID}", - "title": "Cancel job", - "parameters": { - "path": [ - { - "type": "string", - "name": "jobID", - "required": true, - "title": "Job ID" - } - ] - } - } - ] - }, { "title": "Pages", "description": "CRM module pages", diff --git a/api/crm/spec/job.json b/api/crm/spec/job.json deleted file mode 100644 index 18f7acb71..000000000 --- a/api/crm/spec/job.json +++ /dev/null @@ -1,184 +0,0 @@ -{ - "Title": "Jobs", - "Description": "Workflow Jobs", - "Package": "crm", - "Interface": "Job", - "Struct": [ - { - "imports": [ - "github.com/crusttech/crust/crm/types", - "sqlxTypes github.com/jmoiron/sqlx/types" - ] - } - ], - "Parameters": null, - "Protocol": "", - "Authentication": [], - "Path": "/job", - "APIs": [ - { - "Name": "list", - "Method": "GET", - "Title": "List jobs", - "Path": "/", - "Parameters": { - "get": [ - { - "name": "status", - "required": false, - "title": "Job status (`ok`, `error`, `running`, `cancelled` or `queued`)", - "type": "string" - }, - { - "name": "page", - "required": false, - "title": "Page number (0 based)", - "type": "int" - }, - { - "name": "perPage", - "required": false, - "title": "Returned items per page (default 50)", - "type": "int" - } - ] - } - }, - { - "Name": "run", - "Method": "POST", - "Title": "Create a new job", - "Path": "/", - "Parameters": { - "post": [ - { - "name": "workflowID", - "required": true, - "title": "Workflow ID", - "type": "string" - }, - { - "name": "startAt", - "required": false, - "title": "Start datetime for a delayed job", - "type": "string" - }, - { - "name": "parameters", - "required": false, - "title": "Extra job parameters (map[string]string)", - "type": "types.JobParameterSet" - } - ] - } - }, - { - "Name": "get", - "Method": "GET", - "Title": "Get job details", - "Path": "/{jobID}", - "Parameters": { - "path": [ - { - "name": "jobID", - "required": true, - "title": "Job ID", - "type": "string" - } - ] - } - }, - { - "Name": "logs", - "Method": "GET", - "Title": "Get job logs", - "Path": "/{jobID}/logs", - "Parameters": { - "path": [ - { - "name": "jobID", - "required": true, - "title": "Job ID", - "type": "string" - }, - { - "name": "page", - "required": false, - "title": "Page number (0 based)", - "type": "int" - }, - { - "name": "perPage", - "required": false, - "title": "Returned items per page (default 50)", - "type": "int" - } - ] - } - }, - { - "Name": "update", - "Method": "POST", - "Title": "Update job details", - "Path": "/{jobID}", - "Parameters": { - "path": [ - { - "name": "jobID", - "required": true, - "title": "Job ID", - "type": "string" - } - ], - "post": [ - { - "name": "status", - "required": false, - "title": "Job status (`ok`, `error`, `running`, `cancelled` or `queued`)", - "type": "string" - }, - { - "name": "log", - "required": false, - "title": "Job log item (append-only)", - "type": "sqlxTypes.JSONText" - }, - { - "name": "workflowID", - "required": false, - "title": "Workflow ID", - "type": "string" - }, - { - "name": "startAt", - "required": false, - "title": "Start datetime for a delayed job", - "type": "string" - }, - { - "name": "parameters", - "required": false, - "title": "Extra job parameters (map[string]string)", - "type": "types.JobParameterSet" - } - ] - } - }, - { - "Name": "delete", - "Method": "DELETE", - "Title": "Cancel job", - "Path": "/{jobID}", - "Parameters": { - "path": [ - { - "name": "jobID", - "required": true, - "title": "Job ID", - "type": "string" - } - ] - } - } - ] -} \ No newline at end of file diff --git a/api/crm/spec/workflow.json b/api/crm/spec/workflow.json deleted file mode 100644 index 2a7342cba..000000000 --- a/api/crm/spec/workflow.json +++ /dev/null @@ -1,134 +0,0 @@ -{ - "Title": "Workflows", - "Description": "CRM workflow definitions", - "Package": "crm", - "Interface": "Workflow", - "Struct": [ - { - "imports": [ - "github.com/crusttech/crust/crm/types" - ] - } - ], - "Parameters": null, - "Protocol": "", - "Authentication": [], - "Path": "/workflow", - "APIs": [ - { - "Name": "list", - "Method": "GET", - "Title": "List available workflows", - "Path": "/", - "Parameters": null - }, - { - "Name": "create", - "Method": "POST", - "Title": "Create new workflow", - "Path": "/", - "Parameters": { - "post": [ - { - "name": "name", - "required": true, - "title": "Workflow name", - "type": "string" - }, - { - "name": "tasks", - "required": false, - "title": "Type ID", - "type": "types.WorkflowTaskSet" - }, - { - "name": "onError", - "required": false, - "title": "Type ID", - "type": "types.WorkflowTaskSet" - }, - { - "name": "timeout", - "required": false, - "title": "Timeout in seconds", - "type": "int" - } - ] - } - }, - { - "Name": "get", - "Method": "GET", - "Title": "Get workflow details", - "Path": "/{workflowID}", - "Parameters": { - "path": [ - { - "name": "workflowID", - "required": true, - "title": "Workflow ID", - "type": "string" - } - ] - } - }, - { - "Name": "update", - "Method": "POST", - "Title": "Update workflow details", - "Path": "/{workflowID}", - "Parameters": { - "path": [ - { - "name": "workflowID", - "required": true, - "title": "Workflow ID", - "type": "string" - } - ], - "post": [ - { - "name": "name", - "required": true, - "title": "Workflow name", - "type": "string" - }, - { - "name": "tasks", - "required": false, - "title": "Type ID", - "type": "types.WorkflowTaskSet" - }, - { - "name": "onError", - "required": false, - "title": "Type ID", - "type": "types.WorkflowTaskSet" - }, - { - "name": "timeout", - "required": false, - "title": "Timeout in seconds", - "type": "int" - } - ] - } - }, - { - "Name": "delete", - "Method": "DELETE", - "Title": "Delete workflow", - "Path": "/{workflowID}", - "Parameters": { - "path": [ - { - "name": "workflowID", - "required": true, - "title": "Workflow ID", - "type": "string" - } - ] - } - } - ] -} \ No newline at end of file diff --git a/crm/repository/job.go b/crm/repository/job.go deleted file mode 100644 index c72a2533d..000000000 --- a/crm/repository/job.go +++ /dev/null @@ -1,29 +0,0 @@ -package repository - -import ( - "context" - - "github.com/titpetric/factory" - - _ "github.com/crusttech/crust/crm/types" -) - -type ( - JobRepository interface { - With(ctx context.Context, db *factory.DB) JobRepository - } - - job struct { - *repository - } -) - -func Job(ctx context.Context, db *factory.DB) JobRepository { - return (&job{}).With(ctx, db) -} - -func (r *job) With(ctx context.Context, db *factory.DB) JobRepository { - return &job{ - repository: r.repository.With(ctx, db), - } -} diff --git a/crm/repository/workflow.go b/crm/repository/workflow.go deleted file mode 100644 index f7053ec9a..000000000 --- a/crm/repository/workflow.go +++ /dev/null @@ -1,29 +0,0 @@ -package repository - -import ( - "context" - - "github.com/titpetric/factory" - - _ "github.com/crusttech/crust/crm/types" -) - -type ( - WorkflowRepository interface { - With(ctx context.Context, db *factory.DB) WorkflowRepository - } - - workflow struct { - *repository - } -) - -func Workflow(ctx context.Context, db *factory.DB) WorkflowRepository { - return (&workflow{}).With(ctx, db) -} - -func (r *workflow) With(ctx context.Context, db *factory.DB) WorkflowRepository { - return &workflow{ - repository: r.repository.With(ctx, db), - } -} diff --git a/crm/rest/handlers/job.go b/crm/rest/handlers/job.go deleted file mode 100644 index 5ed5b916e..000000000 --- a/crm/rest/handlers/job.go +++ /dev/null @@ -1,107 +0,0 @@ -package handlers - -/* - Hello! This file is auto-generated from `docs/src/spec.json`. - - For development: - In order to update the generated files, edit this file under the location, - add your struct fields, imports, API definitions and whatever you want, and: - - 1. run [spec](https://github.com/titpetric/spec) in the same folder, - 2. run `./_gen.php` in this folder. - - You may edit `job.go`, `job.util.go` or `job_test.go` to - implement your API calls, helper functions and tests. The file `job.go` - is only generated the first time, and will not be overwritten if it exists. -*/ - -import ( - "context" - "github.com/go-chi/chi" - "net/http" - - "github.com/titpetric/factory/resputil" - - "github.com/crusttech/crust/crm/rest/request" -) - -// Internal API interface -type JobAPI interface { - List(context.Context, *request.JobList) (interface{}, error) - Run(context.Context, *request.JobRun) (interface{}, error) - Get(context.Context, *request.JobGet) (interface{}, error) - Logs(context.Context, *request.JobLogs) (interface{}, error) - Update(context.Context, *request.JobUpdate) (interface{}, error) - Delete(context.Context, *request.JobDelete) (interface{}, error) -} - -// HTTP API interface -type Job struct { - List func(http.ResponseWriter, *http.Request) - Run func(http.ResponseWriter, *http.Request) - Get func(http.ResponseWriter, *http.Request) - Logs func(http.ResponseWriter, *http.Request) - Update func(http.ResponseWriter, *http.Request) - Delete func(http.ResponseWriter, *http.Request) -} - -func NewJob(jh JobAPI) *Job { - return &Job{ - List: func(w http.ResponseWriter, r *http.Request) { - defer r.Body.Close() - params := request.NewJobList() - resputil.JSON(w, params.Fill(r), func() (interface{}, error) { - return jh.List(r.Context(), params) - }) - }, - Run: func(w http.ResponseWriter, r *http.Request) { - defer r.Body.Close() - params := request.NewJobRun() - resputil.JSON(w, params.Fill(r), func() (interface{}, error) { - return jh.Run(r.Context(), params) - }) - }, - Get: func(w http.ResponseWriter, r *http.Request) { - defer r.Body.Close() - params := request.NewJobGet() - resputil.JSON(w, params.Fill(r), func() (interface{}, error) { - return jh.Get(r.Context(), params) - }) - }, - Logs: func(w http.ResponseWriter, r *http.Request) { - defer r.Body.Close() - params := request.NewJobLogs() - resputil.JSON(w, params.Fill(r), func() (interface{}, error) { - return jh.Logs(r.Context(), params) - }) - }, - Update: func(w http.ResponseWriter, r *http.Request) { - defer r.Body.Close() - params := request.NewJobUpdate() - resputil.JSON(w, params.Fill(r), func() (interface{}, error) { - return jh.Update(r.Context(), params) - }) - }, - Delete: func(w http.ResponseWriter, r *http.Request) { - defer r.Body.Close() - params := request.NewJobDelete() - resputil.JSON(w, params.Fill(r), func() (interface{}, error) { - return jh.Delete(r.Context(), params) - }) - }, - } -} - -func (jh *Job) MountRoutes(r chi.Router, middlewares ...func(http.Handler) http.Handler) { - r.Group(func(r chi.Router) { - r.Use(middlewares...) - r.Route("/job", func(r chi.Router) { - r.Get("/", jh.List) - r.Post("/", jh.Run) - r.Get("/{jobID}", jh.Get) - r.Get("/{jobID}/logs", jh.Logs) - r.Post("/{jobID}", jh.Update) - r.Delete("/{jobID}", jh.Delete) - }) - }) -} diff --git a/crm/rest/handlers/workflow.go b/crm/rest/handlers/workflow.go deleted file mode 100644 index 7523f8120..000000000 --- a/crm/rest/handlers/workflow.go +++ /dev/null @@ -1,97 +0,0 @@ -package handlers - -/* - Hello! This file is auto-generated from `docs/src/spec.json`. - - For development: - In order to update the generated files, edit this file under the location, - add your struct fields, imports, API definitions and whatever you want, and: - - 1. run [spec](https://github.com/titpetric/spec) in the same folder, - 2. run `./_gen.php` in this folder. - - You may edit `workflow.go`, `workflow.util.go` or `workflow_test.go` to - implement your API calls, helper functions and tests. The file `workflow.go` - is only generated the first time, and will not be overwritten if it exists. -*/ - -import ( - "context" - "github.com/go-chi/chi" - "net/http" - - "github.com/titpetric/factory/resputil" - - "github.com/crusttech/crust/crm/rest/request" -) - -// Internal API interface -type WorkflowAPI interface { - List(context.Context, *request.WorkflowList) (interface{}, error) - Create(context.Context, *request.WorkflowCreate) (interface{}, error) - Get(context.Context, *request.WorkflowGet) (interface{}, error) - Update(context.Context, *request.WorkflowUpdate) (interface{}, error) - Delete(context.Context, *request.WorkflowDelete) (interface{}, error) -} - -// HTTP API interface -type Workflow struct { - List func(http.ResponseWriter, *http.Request) - Create func(http.ResponseWriter, *http.Request) - Get func(http.ResponseWriter, *http.Request) - Update func(http.ResponseWriter, *http.Request) - Delete func(http.ResponseWriter, *http.Request) -} - -func NewWorkflow(wh WorkflowAPI) *Workflow { - return &Workflow{ - List: func(w http.ResponseWriter, r *http.Request) { - defer r.Body.Close() - params := request.NewWorkflowList() - resputil.JSON(w, params.Fill(r), func() (interface{}, error) { - return wh.List(r.Context(), params) - }) - }, - Create: func(w http.ResponseWriter, r *http.Request) { - defer r.Body.Close() - params := request.NewWorkflowCreate() - resputil.JSON(w, params.Fill(r), func() (interface{}, error) { - return wh.Create(r.Context(), params) - }) - }, - Get: func(w http.ResponseWriter, r *http.Request) { - defer r.Body.Close() - params := request.NewWorkflowGet() - resputil.JSON(w, params.Fill(r), func() (interface{}, error) { - return wh.Get(r.Context(), params) - }) - }, - Update: func(w http.ResponseWriter, r *http.Request) { - defer r.Body.Close() - params := request.NewWorkflowUpdate() - resputil.JSON(w, params.Fill(r), func() (interface{}, error) { - return wh.Update(r.Context(), params) - }) - }, - Delete: func(w http.ResponseWriter, r *http.Request) { - defer r.Body.Close() - params := request.NewWorkflowDelete() - resputil.JSON(w, params.Fill(r), func() (interface{}, error) { - return wh.Delete(r.Context(), params) - }) - }, - } -} - -func (wh *Workflow) MountRoutes(r chi.Router, middlewares ...func(http.Handler) http.Handler) { - r.Group(func(r chi.Router) { - r.Use(middlewares...) - r.Route("/workflow", func(r chi.Router) { - r.Get("/", wh.List) - r.Post("/", wh.Create) - r.Get("/{workflowID}", wh.Get) - r.Post("/{workflowID}", wh.Update) - r.Delete("/{workflowID}", wh.Delete) - }) - }) -} diff --git a/crm/rest/job.go b/crm/rest/job.go deleted file mode 100644 index d89deb695..000000000 --- a/crm/rest/job.go +++ /dev/null @@ -1,46 +0,0 @@ -package rest - -import ( - "context" - - "github.com/pkg/errors" - - "github.com/crusttech/crust/crm/rest/request" - "github.com/crusttech/crust/crm/service" -) - -var _ = errors.Wrap - -type ( - Job struct { - jobSvc service.JobService - } -) - -func (Job) New() *Job { - return &Job{jobSvc: service.DefaultJob} -} - -func (ctrl *Job) List(ctx context.Context, r *request.JobList) (interface{}, error) { - return nil, errors.New("Not implemented: Job.list") -} - -func (ctrl *Job) Run(ctx context.Context, r *request.JobRun) (interface{}, error) { - return nil, errors.New("Not implemented: Job.run") -} - -func (ctrl *Job) Get(ctx context.Context, r *request.JobGet) (interface{}, error) { - return nil, errors.New("Not implemented: Job.get") -} - -func (ctrl *Job) Logs(ctx context.Context, r *request.JobLogs) (interface{}, error) { - return nil, errors.New("Not implemented: Job.logs") -} - -func (ctrl *Job) Update(ctx context.Context, r *request.JobUpdate) (interface{}, error) { - return nil, errors.New("Not implemented: Job.update") -} - -func (ctrl *Job) Delete(ctx context.Context, r *request.JobDelete) (interface{}, error) { - return nil, errors.New("Not implemented: Job.delete") -} diff --git a/crm/rest/request/job.go b/crm/rest/request/job.go deleted file mode 100644 index f8269f736..000000000 --- a/crm/rest/request/job.go +++ /dev/null @@ -1,340 +0,0 @@ -package request - -/* - Hello! This file is auto-generated from `docs/src/spec.json`. - - For development: - In order to update the generated files, edit this file under the location, - add your struct fields, imports, API definitions and whatever you want, and: - - 1. run [spec](https://github.com/titpetric/spec) in the same folder, - 2. run `./_gen.php` in this folder. - - You may edit `job.go`, `job.util.go` or `job_test.go` to - implement your API calls, helper functions and tests. The file `job.go` - is only generated the first time, and will not be overwritten if it exists. -*/ - -import ( - "encoding/json" - "io" - "mime/multipart" - "net/http" - "strings" - - "github.com/go-chi/chi" - "github.com/pkg/errors" - - "github.com/crusttech/crust/crm/types" - sqlxTypes "github.com/jmoiron/sqlx/types" -) - -var _ = chi.URLParam -var _ = multipart.FileHeader{} - -// Job list request parameters -type JobList struct { - Status string - Page int - PerPage int -} - -func NewJobList() *JobList { - return &JobList{} -} - -func (j *JobList) Fill(r *http.Request) (err error) { - if strings.ToLower(r.Header.Get("content-type")) == "application/json" { - err = json.NewDecoder(r.Body).Decode(j) - - switch { - case err == io.EOF: - err = nil - case err != nil: - return errors.Wrap(err, "error parsing http request body") - } - } - - if err = r.ParseForm(); err != nil { - return err - } - - get := map[string]string{} - post := map[string]string{} - urlQuery := r.URL.Query() - for name, param := range urlQuery { - get[name] = string(param[0]) - } - postVars := r.Form - for name, param := range postVars { - post[name] = string(param[0]) - } - - if val, ok := get["status"]; ok { - - j.Status = val - } - if val, ok := get["page"]; ok { - - j.Page = parseInt(val) - } - if val, ok := get["perPage"]; ok { - - j.PerPage = parseInt(val) - } - - return err -} - -var _ RequestFiller = NewJobList() - -// Job run request parameters -type JobRun struct { - WorkflowID string - StartAt string - Parameters types.JobParameterSet -} - -func NewJobRun() *JobRun { - return &JobRun{} -} - -func (j *JobRun) Fill(r *http.Request) (err error) { - if strings.ToLower(r.Header.Get("content-type")) == "application/json" { - err = json.NewDecoder(r.Body).Decode(j) - - switch { - case err == io.EOF: - err = nil - case err != nil: - return errors.Wrap(err, "error parsing http request body") - } - } - - if err = r.ParseForm(); err != nil { - return err - } - - get := map[string]string{} - post := map[string]string{} - urlQuery := r.URL.Query() - for name, param := range urlQuery { - get[name] = string(param[0]) - } - postVars := r.Form - for name, param := range postVars { - post[name] = string(param[0]) - } - - if val, ok := post["workflowID"]; ok { - - j.WorkflowID = val - } - if val, ok := post["startAt"]; ok { - - j.StartAt = val - } - - return err -} - -var _ RequestFiller = NewJobRun() - -// Job get request parameters -type JobGet struct { - JobID string -} - -func NewJobGet() *JobGet { - return &JobGet{} -} - -func (j *JobGet) Fill(r *http.Request) (err error) { - if strings.ToLower(r.Header.Get("content-type")) == "application/json" { - err = json.NewDecoder(r.Body).Decode(j) - - switch { - case err == io.EOF: - err = nil - case err != nil: - return errors.Wrap(err, "error parsing http request body") - } - } - - if err = r.ParseForm(); err != nil { - return err - } - - get := map[string]string{} - post := map[string]string{} - urlQuery := r.URL.Query() - for name, param := range urlQuery { - get[name] = string(param[0]) - } - postVars := r.Form - for name, param := range postVars { - post[name] = string(param[0]) - } - - j.JobID = chi.URLParam(r, "jobID") - - return err -} - -var _ RequestFiller = NewJobGet() - -// Job logs request parameters -type JobLogs struct { - JobID string - Page int - PerPage int -} - -func NewJobLogs() *JobLogs { - return &JobLogs{} -} - -func (j *JobLogs) Fill(r *http.Request) (err error) { - if strings.ToLower(r.Header.Get("content-type")) == "application/json" { - err = json.NewDecoder(r.Body).Decode(j) - - switch { - case err == io.EOF: - err = nil - case err != nil: - return errors.Wrap(err, "error parsing http request body") - } - } - - if err = r.ParseForm(); err != nil { - return err - } - - get := map[string]string{} - post := map[string]string{} - urlQuery := r.URL.Query() - for name, param := range urlQuery { - get[name] = string(param[0]) - } - postVars := r.Form - for name, param := range postVars { - post[name] = string(param[0]) - } - - j.JobID = chi.URLParam(r, "jobID") - j.Page = parseInt(chi.URLParam(r, "page")) - j.PerPage = parseInt(chi.URLParam(r, "perPage")) - - return err -} - -var _ RequestFiller = NewJobLogs() - -// Job update request parameters -type JobUpdate struct { - JobID string - Status string - Log sqlxTypes.JSONText - WorkflowID string - StartAt string - Parameters types.JobParameterSet -} - -func NewJobUpdate() *JobUpdate { - return &JobUpdate{} -} - -func (j *JobUpdate) Fill(r *http.Request) (err error) { - if strings.ToLower(r.Header.Get("content-type")) == "application/json" { - err = json.NewDecoder(r.Body).Decode(j) - - switch { - case err == io.EOF: - err = nil - case err != nil: - return errors.Wrap(err, "error parsing http request body") - } - } - - if err = r.ParseForm(); err != nil { - return err - } - - get := map[string]string{} - post := map[string]string{} - urlQuery := r.URL.Query() - for name, param := range urlQuery { - get[name] = string(param[0]) - } - postVars := r.Form - for name, param := range postVars { - post[name] = string(param[0]) - } - - j.JobID = chi.URLParam(r, "jobID") - if val, ok := post["status"]; ok { - - j.Status = val - } - if val, ok := post["log"]; ok { - - if j.Log, err = parseJSONTextWithErr(val); err != nil { - return err - } - } - if val, ok := post["workflowID"]; ok { - - j.WorkflowID = val - } - if val, ok := post["startAt"]; ok { - - j.StartAt = val - } - - return err -} - -var _ RequestFiller = NewJobUpdate() - -// Job delete request parameters -type JobDelete struct { - JobID string -} - -func NewJobDelete() *JobDelete { - return &JobDelete{} -} - -func (j *JobDelete) Fill(r *http.Request) (err error) { - if strings.ToLower(r.Header.Get("content-type")) == "application/json" { - err = json.NewDecoder(r.Body).Decode(j) - - switch { - case err == io.EOF: - err = nil - case err != nil: - return errors.Wrap(err, "error parsing http request body") - } - } - - if err = r.ParseForm(); err != nil { - return err - } - - get := map[string]string{} - post := map[string]string{} - urlQuery := r.URL.Query() - for name, param := range urlQuery { - get[name] = string(param[0]) - } - postVars := r.Form - for name, param := range postVars { - post[name] = string(param[0]) - } - - j.JobID = chi.URLParam(r, "jobID") - - return err -} - -var _ RequestFiller = NewJobDelete() diff --git a/crm/rest/request/workflow.go b/crm/rest/request/workflow.go deleted file mode 100644 index 8485f301d..000000000 --- a/crm/rest/request/workflow.go +++ /dev/null @@ -1,266 +0,0 @@ -package request - -/* - Hello! This file is auto-generated from `docs/src/spec.json`. - - For development: - In order to update the generated files, edit this file under the location, - add your struct fields, imports, API definitions and whatever you want, and: - - 1. run [spec](https://github.com/titpetric/spec) in the same folder, - 2. run `./_gen.php` in this folder. - - You may edit `workflow.go`, `workflow.util.go` or `workflow_test.go` to - implement your API calls, helper functions and tests. The file `workflow.go` - is only generated the first time, and will not be overwritten if it exists. -*/ - -import ( - "encoding/json" - "io" - "mime/multipart" - "net/http" - "strings" - - "github.com/go-chi/chi" - "github.com/pkg/errors" - - "github.com/crusttech/crust/crm/types" -) - -var _ = chi.URLParam -var _ = multipart.FileHeader{} - -// Workflow list request parameters -type WorkflowList struct { -} - -func NewWorkflowList() *WorkflowList { - return &WorkflowList{} -} - -func (w *WorkflowList) Fill(r *http.Request) (err error) { - if strings.ToLower(r.Header.Get("content-type")) == "application/json" { - err = json.NewDecoder(r.Body).Decode(w) - - switch { - case err == io.EOF: - err = nil - case err != nil: - return errors.Wrap(err, "error parsing http request body") - } - } - - if err = r.ParseForm(); err != nil { - return err - } - - get := map[string]string{} - post := map[string]string{} - urlQuery := r.URL.Query() - for name, param := range urlQuery { - get[name] = string(param[0]) - } - postVars := r.Form - for name, param := range postVars { - post[name] = string(param[0]) - } - - return err -} - -var _ RequestFiller = NewWorkflowList() - -// Workflow create request parameters -type WorkflowCreate struct { - Name string - Tasks types.WorkflowTaskSet - OnError types.WorkflowTaskSet - Timeout int -} - -func NewWorkflowCreate() *WorkflowCreate { - return &WorkflowCreate{} -} - -func (w *WorkflowCreate) Fill(r *http.Request) (err error) { - if strings.ToLower(r.Header.Get("content-type")) == "application/json" { - err = json.NewDecoder(r.Body).Decode(w) - - switch { - case err == io.EOF: - err = nil - case err != nil: - return errors.Wrap(err, "error parsing http request body") - } - } - - if err = r.ParseForm(); err != nil { - return err - } - - get := map[string]string{} - post := map[string]string{} - urlQuery := r.URL.Query() - for name, param := range urlQuery { - get[name] = string(param[0]) - } - postVars := r.Form - for name, param := range postVars { - post[name] = string(param[0]) - } - - if val, ok := post["name"]; ok { - - w.Name = val - } - if val, ok := post["timeout"]; ok { - - w.Timeout = parseInt(val) - } - - return err -} - -var _ RequestFiller = NewWorkflowCreate() - -// Workflow get request parameters -type WorkflowGet struct { - WorkflowID string -} - -func NewWorkflowGet() *WorkflowGet { - return &WorkflowGet{} -} - -func (w *WorkflowGet) Fill(r *http.Request) (err error) { - if strings.ToLower(r.Header.Get("content-type")) == "application/json" { - err = json.NewDecoder(r.Body).Decode(w) - - switch { - case err == io.EOF: - err = nil - case err != nil: - return errors.Wrap(err, "error parsing http request body") - } - } - - if err = r.ParseForm(); err != nil { - return err - } - - get := map[string]string{} - post := map[string]string{} - urlQuery := r.URL.Query() - for name, param := range urlQuery { - get[name] = string(param[0]) - } - postVars := r.Form - for name, param := range postVars { - post[name] = string(param[0]) - } - - w.WorkflowID = chi.URLParam(r, "workflowID") - - return err -} - -var _ RequestFiller = NewWorkflowGet() - -// Workflow update request parameters -type WorkflowUpdate struct { - WorkflowID string - Name string - Tasks types.WorkflowTaskSet - OnError types.WorkflowTaskSet - Timeout int -} - -func NewWorkflowUpdate() *WorkflowUpdate { - return &WorkflowUpdate{} -} - -func (w *WorkflowUpdate) Fill(r *http.Request) (err error) { - if strings.ToLower(r.Header.Get("content-type")) == "application/json" { - err = json.NewDecoder(r.Body).Decode(w) - - switch { - case err == io.EOF: - err = nil - case err != nil: - return errors.Wrap(err, "error parsing http request body") - } - } - - if err = r.ParseForm(); err != nil { - return err - } - - get := map[string]string{} - post := map[string]string{} - urlQuery := r.URL.Query() - for name, param := range urlQuery { - get[name] = string(param[0]) - } - postVars := r.Form - for name, param := range postVars { - post[name] = string(param[0]) - } - - w.WorkflowID = chi.URLParam(r, "workflowID") - if val, ok := post["name"]; ok { - - w.Name = val - } - if val, ok := post["timeout"]; ok { - - w.Timeout = parseInt(val) - } - - return err -} - -var _ RequestFiller = NewWorkflowUpdate() - -// Workflow delete request parameters -type WorkflowDelete struct { - WorkflowID string -} - -func NewWorkflowDelete() *WorkflowDelete { - return &WorkflowDelete{} -} - -func (w *WorkflowDelete) Fill(r *http.Request) (err error) { - if strings.ToLower(r.Header.Get("content-type")) == "application/json" { - err = json.NewDecoder(r.Body).Decode(w) - - switch { - case err == io.EOF: - err = nil - case err != nil: - return errors.Wrap(err, "error parsing http request body") - } - } - - if err = r.ParseForm(); err != nil { - return err - } - - get := map[string]string{} - post := map[string]string{} - urlQuery := r.URL.Query() - for name, param := range urlQuery { - get[name] = string(param[0]) - } - postVars := r.Form - for name, param := range postVars { - post[name] = string(param[0]) - } - - w.WorkflowID = chi.URLParam(r, "workflowID") - - return err -} - -var _ RequestFiller = NewWorkflowDelete() diff --git a/crm/rest/workflow.go b/crm/rest/workflow.go deleted file mode 100644 index d9d9c7741..000000000 --- a/crm/rest/workflow.go +++ /dev/null @@ -1,44 +0,0 @@ -package rest - -import ( - "context" - - "github.com/pkg/errors" - - "github.com/crusttech/crust/crm/rest/request" - "github.com/crusttech/crust/crm/service" -) - -var _ = errors.Wrap - -type ( - Workflow struct { - workflowSvc service.WorkflowService - } -) - -func (Workflow) New() *Workflow { - return &Workflow{ - workflowSvc: service.DefaultWorkflow, - } -} - -func (ctrl *Workflow) List(ctx context.Context, r *request.WorkflowList) (interface{}, error) { - return nil, errors.New("Not implemented: Workflow.list") -} - -func (ctrl *Workflow) Create(ctx context.Context, r *request.WorkflowCreate) (interface{}, error) { - return nil, errors.New("Not implemented: Workflow.create") -} - -func (ctrl *Workflow) Get(ctx context.Context, r *request.WorkflowGet) (interface{}, error) { - return nil, errors.New("Not implemented: Workflow.get") -} - -func (ctrl *Workflow) Update(ctx context.Context, r *request.WorkflowUpdate) (interface{}, error) { - return nil, errors.New("Not implemented: Workflow.update") -} - -func (ctrl *Workflow) Delete(ctx context.Context, r *request.WorkflowDelete) (interface{}, error) { - return nil, errors.New("Not implemented: Workflow.delete") -} diff --git a/crm/service/job.go b/crm/service/job.go deleted file mode 100644 index 29b3b2cb3..000000000 --- a/crm/service/job.go +++ /dev/null @@ -1,36 +0,0 @@ -package service - -import ( - "context" - - "github.com/titpetric/factory" - - "github.com/crusttech/crust/crm/repository" - _ "github.com/crusttech/crust/crm/types" -) - -type ( - job struct { - db *factory.DB - ctx context.Context - - repository repository.JobRepository - } - - JobService interface { - With(ctx context.Context) JobService - } -) - -func Job() JobService { - return (&job{}).With(context.Background()) -} - -func (s *job) With(ctx context.Context) JobService { - db := repository.DB(ctx) - return &job{ - db: db, - ctx: ctx, - repository: repository.Job(ctx, db), - } -} diff --git a/crm/service/workflow.go b/crm/service/workflow.go deleted file mode 100644 index be06cdb68..000000000 --- a/crm/service/workflow.go +++ /dev/null @@ -1,36 +0,0 @@ -package service - -import ( - "context" - - "github.com/titpetric/factory" - - "github.com/crusttech/crust/crm/repository" - _ "github.com/crusttech/crust/crm/types" -) - -type ( - workflow struct { - db *factory.DB - ctx context.Context - - repository repository.WorkflowRepository - } - - WorkflowService interface { - With(ctx context.Context) WorkflowService - } -) - -func Workflow() WorkflowService { - return (&workflow{}).With(context.Background()) -} - -func (s *workflow) With(ctx context.Context) WorkflowService { - db := repository.DB(ctx) - return &workflow{ - db: db, - ctx: ctx, - repository: repository.Workflow(ctx, db), - } -} diff --git a/crm/types/job.go b/crm/types/job.go deleted file mode 100644 index f1ee7a159..000000000 --- a/crm/types/job.go +++ /dev/null @@ -1,5 +0,0 @@ -package types - -type ( - JobParameterSet map[string]string -) diff --git a/crm/types/workflow.go b/crm/types/workflow.go deleted file mode 100644 index d6f2476a0..000000000 --- a/crm/types/workflow.go +++ /dev/null @@ -1,27 +0,0 @@ -package types - -type ( - Workflow struct { - ID uint64 `json:"workflowID,string"` - Name string `json:"name"` - Tasks WorkflowTaskSet `json:"tasks"` - OnError WorkflowTaskSet `json:"onError"` - Timeout int `json:"timeout"` - } - - // WorkflowTask denotes a step in the workflow - // - // When it comes to Body and Fallback, we may invoke anything here. If we'll be doing this - // via os.Exec, then it makes sense to enforce some inputs and outputs, in the style of FAAS. - // If we're integrating against airflow, we need to provide basic credentials that allow each - // workflow step to proceed. The dependencies like a valid JWT sholud somehow be provisioned. - WorkflowTask struct { - Name string `json:"name"` - Body string `json:"body"` - Fallback string `json:"fallback"` - Retries []int `json:"retries"` - Timeout int `json:"timeout"` - } - - WorkflowTaskSet []WorkflowTask -) diff --git a/docs/crm/README.md b/docs/crm/README.md index e2d20502a..7efbbd7dd 100644 --- a/docs/crm/README.md +++ b/docs/crm/README.md @@ -75,108 +75,6 @@ -# Jobs - -Workflow Jobs - -## List jobs - -#### Method - -| URI | Protocol | Method | Authentication | -| --- | -------- | ------ | -------------- | -| `/job/` | HTTP/S | GET | | - -#### Request parameters - -| Parameter | Type | Method | Description | Default | Required? | -| --------- | ---- | ------ | ----------- | ------- | --------- | -| status | string | GET | Job status (`ok`, `error`, `running`, `cancelled` or `queued`) | N/A | NO | -| page | int | GET | Page number (0 based) | N/A | NO | -| perPage | int | GET | Returned items per page (default 50) | N/A | NO | - -## Create a new job - -#### Method - -| URI | Protocol | Method | Authentication | -| --- | -------- | ------ | -------------- | -| `/job/` | HTTP/S | POST | | - -#### Request parameters - -| Parameter | Type | Method | Description | Default | Required? | -| --------- | ---- | ------ | ----------- | ------- | --------- | -| workflowID | string | POST | Workflow ID | N/A | YES | -| startAt | string | POST | Start datetime for a delayed job | N/A | NO | -| parameters | types.JobParameterSet | POST | Extra job parameters (map[string]string) | N/A | NO | - -## Get job details - -#### Method - -| URI | Protocol | Method | Authentication | -| --- | -------- | ------ | -------------- | -| `/job/{jobID}` | HTTP/S | GET | | - -#### Request parameters - -| Parameter | Type | Method | Description | Default | Required? | -| --------- | ---- | ------ | ----------- | ------- | --------- | -| jobID | string | PATH | Job ID | N/A | YES | - -## Get job logs - -#### Method - -| URI | Protocol | Method | Authentication | -| --- | -------- | ------ | -------------- | -| `/job/{jobID}/logs` | HTTP/S | GET | | - -#### Request parameters - -| Parameter | Type | Method | Description | Default | Required? | -| --------- | ---- | ------ | ----------- | ------- | --------- | -| jobID | string | PATH | Job ID | N/A | YES | -| page | int | PATH | Page number (0 based) | N/A | NO | -| perPage | int | PATH | Returned items per page (default 50) | N/A | NO | - -## Update job details - -#### Method - -| URI | Protocol | Method | Authentication | -| --- | -------- | ------ | -------------- | -| `/job/{jobID}` | HTTP/S | POST | | - -#### Request parameters - -| Parameter | Type | Method | Description | Default | Required? | -| --------- | ---- | ------ | ----------- | ------- | --------- | -| jobID | string | PATH | Job ID | N/A | YES | -| status | string | POST | Job status (`ok`, `error`, `running`, `cancelled` or `queued`) | N/A | NO | -| log | sqlxTypes.JSONText | POST | Job log item (append-only) | N/A | NO | -| workflowID | string | POST | Workflow ID | N/A | NO | -| startAt | string | POST | Start datetime for a delayed job | N/A | NO | -| parameters | types.JobParameterSet | POST | Extra job parameters (map[string]string) | N/A | NO | - -## Cancel job - -#### Method - -| URI | Protocol | Method | Authentication | -| --- | -------- | ------ | -------------- | -| `/job/{jobID}` | HTTP/S | DELETE | | - -#### Request parameters - -| Parameter | Type | Method | Description | Default | Required? | -| --------- | ---- | ------ | ----------- | ------- | --------- | -| jobID | string | PATH | Job ID | N/A | YES | - - - - # Modules CRM module definitions