Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mco/feat(Workflow) can be published, listed and deleted #123

Merged
merged 4 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion client_web/src/Config/backend.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,14 @@ const auth = {
health: `${endpoint}/auth/health`,
}

const workflow = {
create: `${endpoint}/workflow/create`,
}

export {
instance,
instanceWithAuth,
root,
auth
auth,
workflow
}
11 changes: 10 additions & 1 deletion client_web/src/Pages/Workflows/CreateWorkflow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { normalizeName } from "@/Pages/Workflows/CreateWorkflow.utils";
// Import types correctly
import { About, Service, Action, Reaction, Workflow, Parameter } from "@/types";
import {toast} from "react-toastify";
import {instanceWithAuth} from "@/Config/backend.routes";
import {workflow as workflowRoute} from "@/Config/backend.routes";

const { Title, Text } = Typography;
const { Panel } = Collapse;
Expand Down Expand Up @@ -274,7 +276,14 @@ const CreateWorkflow: React.FC = () => {
})
};

toast.error("API not connected yet");
instanceWithAuth.post(workflowRoute.create, workflow)
.then(() => {
toast.success("Workflow successfully published")
//TODO: Go to /workflow/{id}
})
.catch((error) => {
console.error(error);
});
};

const handleFoldAllActions = () => {
Expand Down
2 changes: 1 addition & 1 deletion server/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
"swagger": true,
"cors_origins": [
"https://localhost:8081",
"http://example.com"
"http://localhost:8080"
]
}
262 changes: 225 additions & 37 deletions server/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,46 @@ const docTemplate = `{
}
}
},
"/login": {
"/auth/health": {
"get": {
"description": "Validate the token and return 200 if valid, 401 if expired or invalid",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"auth"
],
"summary": "Check if the JWT is valid",
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
},
"401": {
"description": "Unauthorized",
"schema": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
}
}
}
},
"/auth/login": {
"post": {
"description": "Authenticate a user and return a JWT token",
"consumes": [
"application/x-www-form-urlencoded"
"application/json"
],
"produces": [
"application/json"
Expand All @@ -62,18 +97,13 @@ const docTemplate = `{
"summary": "Login a user",
"parameters": [
{
"type": "string",
"description": "Email",
"name": "email",
"in": "formData",
"required": true
},
{
"type": "string",
"description": "Password",
"name": "password",
"in": "formData",
"required": true
"description": "Login",
"name": "Login",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/models.LoginRequest"
}
}
],
"responses": {
Expand All @@ -98,6 +128,61 @@ const docTemplate = `{
}
}
},
"/auth/register": {
"post": {
"description": "Create a new user and return a JWT token",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"auth"
],
"summary": "Register a user",
"parameters": [
{
"description": "Register",
"name": "Register",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/models.RegisterRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
},
"409": {
"description": "Conflict",
"schema": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
}
}
}
},
"/ping": {
"get": {
"description": "ping",
Expand Down Expand Up @@ -153,39 +238,68 @@ const docTemplate = `{
}
}
},
"/register": {
"/workflow/create": {
"post": {
"description": "Create a new user and return a JWT token",
"description": "Create a new workflow",
"consumes": [
"application/x-www-form-urlencoded"
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"auth"
"workflow"
],
"summary": "Register a user",
"summary": "Create a workflow",
"parameters": [
{
"type": "string",
"description": "Email",
"name": "email",
"in": "formData",
"required": true
},
{
"type": "string",
"description": "Username",
"name": "username",
"in": "formData",
"required": true
"description": "workflow",
"name": "workflow",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/models.Workflow"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/models.Workflow"
}
},
"400": {
"description": "Bad Request",
"schema": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
}
}
}
},
"/workflow/delete/{id}": {
"delete": {
"description": "Delete a workflow by ID",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"workflow"
],
"summary": "Delete a workflow",
"parameters": [
{
"type": "string",
"description": "Password",
"name": "password",
"in": "formData",
"type": "integer",
"description": "workflow ID",
"name": "id",
"in": "path",
"required": true
}
],
Expand All @@ -199,8 +313,17 @@ const docTemplate = `{
}
}
},
"409": {
"description": "Conflict",
"400": {
"description": "Bad Request",
"schema": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
},
"404": {
"description": "Not Found",
"schema": {
"type": "object",
"additionalProperties": {
Expand All @@ -219,6 +342,71 @@ const docTemplate = `{
}
}
}
},
"/workflow/list": {
"get": {
"description": "List all workflows",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"workflow"
],
"summary": "List workflows",
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/models.Workflow"
}
}
}
}
}
}
},
"definitions": {
"models.LoginRequest": {
"type": "object",
"required": [
"email",
"password"
],
"properties": {
"email": {
"type": "string"
},
"password": {
"type": "string"
}
}
},
"models.RegisterRequest": {
"type": "object",
"required": [
"email",
"password",
"username"
],
"properties": {
"email": {
"type": "string"
},
"password": {
"type": "string"
},
"username": {
"type": "string"
}
}
},
"models.Workflow": {
"type": "object"
}
}
}`
Expand Down
Loading
Loading