From 44353a15f7c7f3cc299a5644e6b69499d6523c3f Mon Sep 17 00:00:00 2001 From: Milla Martinez Date: Mon, 5 Jul 2021 12:44:48 +0200 Subject: [PATCH 01/13] '1' --- .../files/clonetemplatesfolder.md | 18 ++ CRUD-Python-CobiGen/files/context.xml | 168 ++++++++++++++++++ CRUD-Python-CobiGen/files/initialCommit.md | 5 + CRUD-Python-CobiGen/files/postmanTest.md | 21 +++ CRUD-Python-CobiGen/files/user.yml | 39 ++++ CRUD-Python-CobiGen/index.asciidoc | 65 +++++++ CRUD-Python-CobiGen/index2.asciidoc | 117 ++++++++++++ 7 files changed, 433 insertions(+) create mode 100644 CRUD-Python-CobiGen/files/clonetemplatesfolder.md create mode 100644 CRUD-Python-CobiGen/files/context.xml create mode 100644 CRUD-Python-CobiGen/files/initialCommit.md create mode 100644 CRUD-Python-CobiGen/files/postmanTest.md create mode 100644 CRUD-Python-CobiGen/files/user.yml create mode 100644 CRUD-Python-CobiGen/index.asciidoc create mode 100644 CRUD-Python-CobiGen/index2.asciidoc diff --git a/CRUD-Python-CobiGen/files/clonetemplatesfolder.md b/CRUD-Python-CobiGen/files/clonetemplatesfolder.md new file mode 100644 index 00000000..f57713b2 --- /dev/null +++ b/CRUD-Python-CobiGen/files/clonetemplatesfolder.md @@ -0,0 +1,18 @@ +The templates folder is typically found at: + +`C:\Users\[yourName]\.cobigen\templates\CobiGen_Templates\src\main\templates` + +Open the command line in this location and clone the `CRUD-openapi-python` project using: + +`git clone https://github.com/devonfw-forge/cobigen-python-templates.git` + +You should now find the `CRUD-openapi-python` folder in your templates directory. Let's briefly explore its contents: + +* `templates.xml`: a file for code generation purposes detailing the increments that will be available for selection from the CobiGen CLI. +* templates: the folder containing the basic application structure including all the files that will be generated. + * `requirements.txt`: a list of all packages required to run the application and the database. Encoded in UTF-8. + * `config.py`: declares the `Config` class which represents the Flask-SQLAlchemy database configuration. + * app: + * `__init__.py.ftl`: FreeMarker template declaring the application and the database. + * `${variables.entityName#cap_first}Model.py.ftl`: FreeMarker template declarating the table with the entity's attributes as columns + * `${variables.entityName#cap_first}Routes.py.ftl`: FreeMarker template declaring the service returning JSON objects for the GET, POST, PUT and DELETE methods. diff --git a/CRUD-Python-CobiGen/files/context.xml b/CRUD-Python-CobiGen/files/context.xml new file mode 100644 index 00000000..4ecb8857 --- /dev/null +++ b/CRUD-Python-CobiGen/files/context.xml @@ -0,0 +1,168 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/CRUD-Python-CobiGen/files/initialCommit.md b/CRUD-Python-CobiGen/files/initialCommit.md new file mode 100644 index 00000000..d14d0d9d --- /dev/null +++ b/CRUD-Python-CobiGen/files/initialCommit.md @@ -0,0 +1,5 @@ +In order to upload the table declared in our "Model.py" we need a migration script. This command requires an attached message whenever it runs, for instance: + +`flask db migrate -m` "`first migration`" + +In this case, the terminal should print in return `Detected added table user`, among others. We can now upload the migration script. \ No newline at end of file diff --git a/CRUD-Python-CobiGen/files/postmanTest.md b/CRUD-Python-CobiGen/files/postmanTest.md new file mode 100644 index 00000000..f0413ea8 --- /dev/null +++ b/CRUD-Python-CobiGen/files/postmanTest.md @@ -0,0 +1,21 @@ +We can test our application using Postman. Paste the main path on a new Postman tab, for instance: + +http://127.0.0.1:5000/user + +Our table is empty for the moment, so we will select the POST method to add new data. We can submit JSON requests by clicking on the "Body" tab and selecting "raw". For example, submit: + + + { "name" : "elena", "age" : 26, "phone" : "555123", "email" : "elena@devon.com" } + + +Our new user should now be accessible from the database under "id" number 1. Check this by submitting a GET request to the following path: + +http://127.0.0.1:5000/user/1 + +We will now edit our entry by sending a PUT request. Submit the following body to http://127.0.0.1:5000/user/1: + + { "phone" : "777123" } + +Now send another GET request and check whether the column was properly updated. + +Lastly, you can check the DELETE method by sending this request to http://127.0.0.1:5000/user/1. Then send a GET request to http://127.0.0.1:5000/user. The application returns "User list is empty". diff --git a/CRUD-Python-CobiGen/files/user.yml b/CRUD-Python-CobiGen/files/user.yml new file mode 100644 index 00000000..01117901 --- /dev/null +++ b/CRUD-Python-CobiGen/files/user.yml @@ -0,0 +1,39 @@ +openapi: 3.0.0 +servers: + - url: 'https://localhost:8081/server/services/rest' + description: Just some data +info: + title: devonfw Example + description: Example of a API definition + version: 1.0.0 + x-rootpackage: com.devonfw.poc.jwtsample +paths: + /: + post: + responses: + '200': + description: Any +components: + schemas: + User: + x-component: usermanagement + description: Entity definiton of User + type: object + properties: + name: + type: string + maxLength: 100 + uniqueItems: true + age: + type: integer + phone : + type: string + maxLength: 100 + uniqueItems: true + email: + type: string + maxLength: 100 + uniqueItems: true + required: + - name + - email \ No newline at end of file diff --git a/CRUD-Python-CobiGen/index.asciidoc b/CRUD-Python-CobiGen/index.asciidoc new file mode 100644 index 00000000..79abf4a7 --- /dev/null +++ b/CRUD-Python-CobiGen/index.asciidoc @@ -0,0 +1,65 @@ += Create a CRUD Python Flask application using CobiGen's OpenAPI plugin +==== + +The aim of this tutorial is to create a basic CRUD Python Flask application from a single OpenAPI .yml file declaring an entity. + +The code will be generated using devonfw's CobiGen. This will result in a basic application layout, the declaration of a Flask-SQLAlchemy table with the entity's attributes as columns, and a service returning JSON objects for the GET, POST, PUT and DELETE methods. + +### Prerequisites: + +* devonfw workspace set up, including the CobiGen code generator and the corresponding `CobiGen_Templates` folder. +* Python 3 + +==== + +[step] +-- +installDevonfwIde(["java","mvn"]) +installCobiGen() +executeCommand("devon","devon") +-- + +[step] +-- +adaptTemplatesCobiGen() +cloneRepository("/root/.cobigen/templates/CobiGen_Templates/src/main/templates", "https://github.com/devonfw-forge/cobigen-python-templates.git") +-- + +[step] +-- +changeFile("/root/.cobigen/templates/CobiGen_Templates/src/main/templates/context.xml", {"file": "files/context.xml"}) +-- + +[step] +-- +executeCommand("cd /root/devonfw/workspaces/main","cd /root/devonfw/workspaces/main") +createFile("cobigen-python-example/user.yml", "files/user.yml") +-- + +[step] +-- +executeCommand("cobigen generate user.yml -i 1","cobigen generate user.yml -i 1",{"dir":"cobigen-python-example"}) +-- + +[step] +-- +executeCommand("python3 -m pip install virtualenv","python3 -m pip install virtualenv",{"dir":"cobigen-python-example"}) +executeCommand("python3 -m virtualenv venv","python3 -m virtualenv venv",{"dir":"cobigen-python-example"}) +executeCommand("activate.ps1","source activate", {"dir":"venv/bin"} ) +executeCommand("cd /root/devonfw/workspaces/main/cobigen-python-example","cd /root/devonfw/workspaces/main/cobigen-python-example") +executeCommand("pip install -r requirements.txt","pip install -r requirements.txt") +-- + +[step] +-- +executeCommand("flask db init","flask db init") +nextKatacodaStep("Initial commit", [{ "file": "files/initialCommit.md" }]) +executeCommand("flask db upgrade","flask db upgrade") +-- + +[step] +-- +executeCommand("flask run","flask run") +nextKatacodaStep("Postman test", [{ "file": "files/postmanTest.md" }]) +-- + diff --git a/CRUD-Python-CobiGen/index2.asciidoc b/CRUD-Python-CobiGen/index2.asciidoc new file mode 100644 index 00000000..ac9a83e4 --- /dev/null +++ b/CRUD-Python-CobiGen/index2.asciidoc @@ -0,0 +1,117 @@ += Create a CRUD Python Flask application using CobiGen's OpenAPI plugin +==== + +The aim of this tutorial is to create a basic CRUD Python Flask application from a single OpenAPI .yml file declaring an entity. + +The code will be generated using devonfw's CobiGen. This will result in a basic application layout, the declaration of a Flask-SQLAlchemy table with the entity's attributes as columns, and a service returning JSON objects for the GET, POST, PUT and DELETE methods. + +### Prerequisites: + +* devonfw workspace set up, including the CobiGen code generator and the corresponding `CobiGen_Templates` folder. +* Python 3 + +==== + +[step] +-- +nextKatacodaStep("Clone the templates folder", [{ "file": "files/clonetemplatesfolder.md" }]) +-- + + +We shall now return to: + +`C:\Users\[yourName]\.cobigen\templates\CobiGen_Templates\src\main\templates` + +Inspect the `context.xml` file. For code generation purposes, this lists a trigger for each template folder available to CobiGen. + +We need to edit this file by adding another trigger referring to our new `CRUD-openapi-python` folder. On Visual Studio, for instance, paste at the top of the trigger list the contents from `pythonTrigger.xml`: + +[step] + +-- +createFile("main/pythonTrigger.xml", "files/pythonTrigger.xml") +-- + +We now have our `CobiGen_Templates` folder all set up. Next, head to the `\workspaces\main` folder in the devonfw environment. + +The only thing we are missing now is a .yml input in v3.0.0 format declaring a component and its properties. Take `user.yaml` as an example. + +[step] +-- +createFile("main/cobigen-python-example/user.yml", "files/user.yml") +-- + + +Inspect `user.yml`. Note that the entity is declared under the `components: schemas:` section. In this case, we declared four typed attributes. + +Properties called `id` will be ignored, since the code generator automatically sets `id` as the table's primary key. + +Besides the type, the project considers the following constraints: + +* *maxLength* +* *uniqueItems*: sets `unique=True` for the column declaration. +* *required*: sets `nullable=False` for the column declaration. + +==== + +Now open the command line at your project folder. You can check whether the CobiGen CLI is properly set up by running `devon cobigen`. + +Let's generate the code now. Type: + +[step] +-- +executeCommand("cobigen generate user.yml","cobigen generate user.yml") +installCobiGen() +-- + + +If the command is not working properly you might want to run `cobigen update` or `cobigen adapt-templates` first. + +Otherwise the command line should return a full list of the available increments. + +Assuming that the `context.xml` and `templates.xml` files were properly set up, this should include the "CRUD Python Flask" option. Select this option. The command line should print out "Successful generation" shortly. + + +Now open the folder containing the .yml input on Visual Studio, for instance. Observe that Cobigen has generated and named the five files mentioned above. We are now set to run the application. + +The safest way to install the required packages is to do so locally, by setting up a virtual environment. + +executeCommand(".\venv\Scripts\activate",".\venv\Scripts\activate") + +[step] +-- +executeCommand("python -m pip install virtualenv","python -m pip install virtualenv") + +executeCommand("pip install -r requirements.txt","pip install -r requirements.txt") +-- + + +You should now see a new "venv" folder in your package explorer. To check whether the virtual environment activated properly make sure the terminal is printing "(venv)", followed by your directory. + +If any packages failed to install automatically, try to do so manually. + + +Let's initialize the database now. + +[step] +-- +executeCommand("flask db init","flask db init") +executeCommand("flask db migrate -m 'first migration'","flask db migrate -m 'first migration'") +executeCommand("flask db upgrade","flask db upgrade") +-- + +This should create the `migrations` folder and the respective `__pycache__` folders in your directory. + +In order to upload the table declared in our "Model.py" we need a migration script. This command requires an attached message whenever it runs. + +In this case, the terminal should print in return `Detected added table user`, among others. + +The migration script can be then uploaded. This way our database is all set up. + + + +[step] +-- +executeCommand("flask run","flask run") +nextKatacodaStep("Test on Postman", [{ "file": "files/postmantest.md" }]) +-- \ No newline at end of file From 7e2cad0f4c7ffd337060fb23e739a5c5cd84ed53 Mon Sep 17 00:00:00 2001 From: Milla Martinez Date: Tue, 6 Jul 2021 09:27:48 +0200 Subject: [PATCH 02/13] '2' --- .../files/clonetemplatesfolder.md | 18 --- CRUD-Python-CobiGen/index.asciidoc | 20 +-- CRUD-Python-CobiGen/index2.asciidoc | 117 ------------------ 3 files changed, 5 insertions(+), 150 deletions(-) delete mode 100644 CRUD-Python-CobiGen/files/clonetemplatesfolder.md delete mode 100644 CRUD-Python-CobiGen/index2.asciidoc diff --git a/CRUD-Python-CobiGen/files/clonetemplatesfolder.md b/CRUD-Python-CobiGen/files/clonetemplatesfolder.md deleted file mode 100644 index f57713b2..00000000 --- a/CRUD-Python-CobiGen/files/clonetemplatesfolder.md +++ /dev/null @@ -1,18 +0,0 @@ -The templates folder is typically found at: - -`C:\Users\[yourName]\.cobigen\templates\CobiGen_Templates\src\main\templates` - -Open the command line in this location and clone the `CRUD-openapi-python` project using: - -`git clone https://github.com/devonfw-forge/cobigen-python-templates.git` - -You should now find the `CRUD-openapi-python` folder in your templates directory. Let's briefly explore its contents: - -* `templates.xml`: a file for code generation purposes detailing the increments that will be available for selection from the CobiGen CLI. -* templates: the folder containing the basic application structure including all the files that will be generated. - * `requirements.txt`: a list of all packages required to run the application and the database. Encoded in UTF-8. - * `config.py`: declares the `Config` class which represents the Flask-SQLAlchemy database configuration. - * app: - * `__init__.py.ftl`: FreeMarker template declaring the application and the database. - * `${variables.entityName#cap_first}Model.py.ftl`: FreeMarker template declarating the table with the entity's attributes as columns - * `${variables.entityName#cap_first}Routes.py.ftl`: FreeMarker template declaring the service returning JSON objects for the GET, POST, PUT and DELETE methods. diff --git a/CRUD-Python-CobiGen/index.asciidoc b/CRUD-Python-CobiGen/index.asciidoc index 79abf4a7..6fc8bacb 100644 --- a/CRUD-Python-CobiGen/index.asciidoc +++ b/CRUD-Python-CobiGen/index.asciidoc @@ -1,17 +1,6 @@ = Create a CRUD Python Flask application using CobiGen's OpenAPI plugin ==== -The aim of this tutorial is to create a basic CRUD Python Flask application from a single OpenAPI .yml file declaring an entity. - -The code will be generated using devonfw's CobiGen. This will result in a basic application layout, the declaration of a Flask-SQLAlchemy table with the entity's attributes as columns, and a service returning JSON objects for the GET, POST, PUT and DELETE methods. - -### Prerequisites: - -* devonfw workspace set up, including the CobiGen code generator and the corresponding `CobiGen_Templates` folder. -* Python 3 - -==== - [step] -- installDevonfwIde(["java","mvn"]) @@ -22,12 +11,13 @@ executeCommand("devon","devon") [step] -- adaptTemplatesCobiGen() -cloneRepository("/root/.cobigen/templates/CobiGen_Templates/src/main/templates", "https://github.com/devonfw-forge/cobigen-python-templates.git") +executeCommand("cd /root/.cobigen/templates/CobiGen_Templates/src/main/templates","cd /root/.cobigen/templates/CobiGen_Templates/src/main/templates") +cloneRepository("", "https://github.com/devonfw-forge/cobigen-python-templates.git") -- [step] -- -changeFile("/root/.cobigen/templates/CobiGen_Templates/src/main/templates/context.xml", {"file": "files/context.xml"}) +createFile("context.xml", {"file": "files/context.xml"}) -- [step] @@ -43,8 +33,8 @@ executeCommand("cobigen generate user.yml -i 1","cobigen generate user.yml -i 1" [step] -- -executeCommand("python3 -m pip install virtualenv","python3 -m pip install virtualenv",{"dir":"cobigen-python-example"}) -executeCommand("python3 -m virtualenv venv","python3 -m virtualenv venv",{"dir":"cobigen-python-example"}) +executeCommand("python3 -m pip install virtualenv","python3 -m pip install virtualenv") +executeCommand("python3 -m virtualenv venv","python3 -m virtualenv venv") executeCommand("activate.ps1","source activate", {"dir":"venv/bin"} ) executeCommand("cd /root/devonfw/workspaces/main/cobigen-python-example","cd /root/devonfw/workspaces/main/cobigen-python-example") executeCommand("pip install -r requirements.txt","pip install -r requirements.txt") diff --git a/CRUD-Python-CobiGen/index2.asciidoc b/CRUD-Python-CobiGen/index2.asciidoc deleted file mode 100644 index ac9a83e4..00000000 --- a/CRUD-Python-CobiGen/index2.asciidoc +++ /dev/null @@ -1,117 +0,0 @@ -= Create a CRUD Python Flask application using CobiGen's OpenAPI plugin -==== - -The aim of this tutorial is to create a basic CRUD Python Flask application from a single OpenAPI .yml file declaring an entity. - -The code will be generated using devonfw's CobiGen. This will result in a basic application layout, the declaration of a Flask-SQLAlchemy table with the entity's attributes as columns, and a service returning JSON objects for the GET, POST, PUT and DELETE methods. - -### Prerequisites: - -* devonfw workspace set up, including the CobiGen code generator and the corresponding `CobiGen_Templates` folder. -* Python 3 - -==== - -[step] --- -nextKatacodaStep("Clone the templates folder", [{ "file": "files/clonetemplatesfolder.md" }]) --- - - -We shall now return to: - -`C:\Users\[yourName]\.cobigen\templates\CobiGen_Templates\src\main\templates` - -Inspect the `context.xml` file. For code generation purposes, this lists a trigger for each template folder available to CobiGen. - -We need to edit this file by adding another trigger referring to our new `CRUD-openapi-python` folder. On Visual Studio, for instance, paste at the top of the trigger list the contents from `pythonTrigger.xml`: - -[step] - --- -createFile("main/pythonTrigger.xml", "files/pythonTrigger.xml") --- - -We now have our `CobiGen_Templates` folder all set up. Next, head to the `\workspaces\main` folder in the devonfw environment. - -The only thing we are missing now is a .yml input in v3.0.0 format declaring a component and its properties. Take `user.yaml` as an example. - -[step] --- -createFile("main/cobigen-python-example/user.yml", "files/user.yml") --- - - -Inspect `user.yml`. Note that the entity is declared under the `components: schemas:` section. In this case, we declared four typed attributes. - -Properties called `id` will be ignored, since the code generator automatically sets `id` as the table's primary key. - -Besides the type, the project considers the following constraints: - -* *maxLength* -* *uniqueItems*: sets `unique=True` for the column declaration. -* *required*: sets `nullable=False` for the column declaration. - -==== - -Now open the command line at your project folder. You can check whether the CobiGen CLI is properly set up by running `devon cobigen`. - -Let's generate the code now. Type: - -[step] --- -executeCommand("cobigen generate user.yml","cobigen generate user.yml") -installCobiGen() --- - - -If the command is not working properly you might want to run `cobigen update` or `cobigen adapt-templates` first. - -Otherwise the command line should return a full list of the available increments. - -Assuming that the `context.xml` and `templates.xml` files were properly set up, this should include the "CRUD Python Flask" option. Select this option. The command line should print out "Successful generation" shortly. - - -Now open the folder containing the .yml input on Visual Studio, for instance. Observe that Cobigen has generated and named the five files mentioned above. We are now set to run the application. - -The safest way to install the required packages is to do so locally, by setting up a virtual environment. - -executeCommand(".\venv\Scripts\activate",".\venv\Scripts\activate") - -[step] --- -executeCommand("python -m pip install virtualenv","python -m pip install virtualenv") - -executeCommand("pip install -r requirements.txt","pip install -r requirements.txt") --- - - -You should now see a new "venv" folder in your package explorer. To check whether the virtual environment activated properly make sure the terminal is printing "(venv)", followed by your directory. - -If any packages failed to install automatically, try to do so manually. - - -Let's initialize the database now. - -[step] --- -executeCommand("flask db init","flask db init") -executeCommand("flask db migrate -m 'first migration'","flask db migrate -m 'first migration'") -executeCommand("flask db upgrade","flask db upgrade") --- - -This should create the `migrations` folder and the respective `__pycache__` folders in your directory. - -In order to upload the table declared in our "Model.py" we need a migration script. This command requires an attached message whenever it runs. - -In this case, the terminal should print in return `Detected added table user`, among others. - -The migration script can be then uploaded. This way our database is all set up. - - - -[step] --- -executeCommand("flask run","flask run") -nextKatacodaStep("Test on Postman", [{ "file": "files/postmantest.md" }]) --- \ No newline at end of file From 87cb6f06a46bcfc11ade6e05fb5eac7dbbed1700 Mon Sep 17 00:00:00 2001 From: Milla Martinez Date: Tue, 6 Jul 2021 09:33:03 +0200 Subject: [PATCH 03/13] '3' --- CRUD-Python-CobiGen/index.asciidoc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CRUD-Python-CobiGen/index.asciidoc b/CRUD-Python-CobiGen/index.asciidoc index 6fc8bacb..106b2d17 100644 --- a/CRUD-Python-CobiGen/index.asciidoc +++ b/CRUD-Python-CobiGen/index.asciidoc @@ -1,5 +1,9 @@ = Create a CRUD Python Flask application using CobiGen's OpenAPI plugin ==== +The aim of this tutorial is to create a basic CRUD Python Flask application from a single OpenAPI .yml file declaring an entity. + +The code will be generated using devonfw's CobiGen. This will result in a basic application layout, the declaration of a Flask-SQLAlchemy table with the entity's attributes as columns, and a service returning JSON objects for the GET, POST, PUT and DELETE methods. +==== [step] -- @@ -17,7 +21,7 @@ cloneRepository("", "https://github.com/devonfw-forge/cobigen-python-templates.g [step] -- -createFile("context.xml", {"file": "files/context.xml"}) +createFile("context.xml", "files/context.xml") -- [step] From 5b4e0d2fc394c1b124155f94bdcc4aa3546a3605 Mon Sep 17 00:00:00 2001 From: Milla Martinez Date: Tue, 6 Jul 2021 09:43:15 +0200 Subject: [PATCH 04/13] '4' --- CRUD-Python-CobiGen/index.asciidoc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CRUD-Python-CobiGen/index.asciidoc b/CRUD-Python-CobiGen/index.asciidoc index 106b2d17..d0105d76 100644 --- a/CRUD-Python-CobiGen/index.asciidoc +++ b/CRUD-Python-CobiGen/index.asciidoc @@ -15,18 +15,18 @@ executeCommand("devon","devon") [step] -- adaptTemplatesCobiGen() -executeCommand("cd /root/.cobigen/templates/CobiGen_Templates/src/main/templates","cd /root/.cobigen/templates/CobiGen_Templates/src/main/templates") +changeWorkspace(".cobigen/templates/CobiGen_Templates/src/main/templates") cloneRepository("", "https://github.com/devonfw-forge/cobigen-python-templates.git") -- [step] -- -createFile("context.xml", "files/context.xml") +changeFile("context.xml", { "file": "files/context.xml"}) -- [step] -- -executeCommand("cd /root/devonfw/workspaces/main","cd /root/devonfw/workspaces/main") +changeWorkspace("devonfw/workspaces/main") createFile("cobigen-python-example/user.yml", "files/user.yml") -- From b0a24e5c639bdb5b1cc5890e1b1e69d016315453 Mon Sep 17 00:00:00 2001 From: Milla Martinez Date: Tue, 6 Jul 2021 09:58:02 +0200 Subject: [PATCH 05/13] '5' --- CRUD-Python-CobiGen/index.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CRUD-Python-CobiGen/index.asciidoc b/CRUD-Python-CobiGen/index.asciidoc index d0105d76..a5f7b500 100644 --- a/CRUD-Python-CobiGen/index.asciidoc +++ b/CRUD-Python-CobiGen/index.asciidoc @@ -26,7 +26,7 @@ changeFile("context.xml", { "file": "files/context.xml"}) [step] -- -changeWorkspace("devonfw/workspaces/main") +executeCommand("cd /root/devonfw/workspaces/main","cd /root/devonfw/workspaces/main") createFile("cobigen-python-example/user.yml", "files/user.yml") -- From cb7ffc7605e458adfbc1ff7d79ebd3139730ad8d Mon Sep 17 00:00:00 2001 From: Milla Martinez Date: Tue, 6 Jul 2021 10:23:27 +0200 Subject: [PATCH 06/13] '6' --- CRUD-Python-CobiGen/index.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CRUD-Python-CobiGen/index.asciidoc b/CRUD-Python-CobiGen/index.asciidoc index a5f7b500..d0105d76 100644 --- a/CRUD-Python-CobiGen/index.asciidoc +++ b/CRUD-Python-CobiGen/index.asciidoc @@ -26,7 +26,7 @@ changeFile("context.xml", { "file": "files/context.xml"}) [step] -- -executeCommand("cd /root/devonfw/workspaces/main","cd /root/devonfw/workspaces/main") +changeWorkspace("devonfw/workspaces/main") createFile("cobigen-python-example/user.yml", "files/user.yml") -- From 6a58b47160ec13c2ccd1f3f0f7f5ba119443d5e7 Mon Sep 17 00:00:00 2001 From: Milla Martinez Date: Tue, 6 Jul 2021 10:34:24 +0200 Subject: [PATCH 07/13] 7 --- CRUD-Python-CobiGen/index.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CRUD-Python-CobiGen/index.asciidoc b/CRUD-Python-CobiGen/index.asciidoc index d0105d76..4fd704bf 100644 --- a/CRUD-Python-CobiGen/index.asciidoc +++ b/CRUD-Python-CobiGen/index.asciidoc @@ -26,7 +26,7 @@ changeFile("context.xml", { "file": "files/context.xml"}) [step] -- -changeWorkspace("devonfw/workspaces/main") +restoreWorkspace("devonfw/workspaces/main") createFile("cobigen-python-example/user.yml", "files/user.yml") -- From 7cf3454bdba3a93501a7d202c100db3ea68e648d Mon Sep 17 00:00:00 2001 From: Milla Martinez Date: Tue, 6 Jul 2021 10:38:20 +0200 Subject: [PATCH 08/13] '8' --- CRUD-Python-CobiGen/index.asciidoc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CRUD-Python-CobiGen/index.asciidoc b/CRUD-Python-CobiGen/index.asciidoc index 4fd704bf..2dfdc2ef 100644 --- a/CRUD-Python-CobiGen/index.asciidoc +++ b/CRUD-Python-CobiGen/index.asciidoc @@ -26,7 +26,8 @@ changeFile("context.xml", { "file": "files/context.xml"}) [step] -- -restoreWorkspace("devonfw/workspaces/main") +executeCommand("cd /root/devonfw/workspaces/main","cd /root/devonfw/workspaces/main") +changeWorkspace("devonfw/workspaces/main") createFile("cobigen-python-example/user.yml", "files/user.yml") -- From b573a2300dd34a1b8e1f9915e9d08ad9c338e33c Mon Sep 17 00:00:00 2001 From: Milla Martinez Date: Tue, 13 Jul 2021 12:34:23 +0200 Subject: [PATCH 09/13] '10' --- CRUD-Python-CobiGen/index.asciidoc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CRUD-Python-CobiGen/index.asciidoc b/CRUD-Python-CobiGen/index.asciidoc index 2dfdc2ef..b5113d31 100644 --- a/CRUD-Python-CobiGen/index.asciidoc +++ b/CRUD-Python-CobiGen/index.asciidoc @@ -48,13 +48,13 @@ executeCommand("pip install -r requirements.txt","pip install -r requirements.tx [step] -- executeCommand("flask db init","flask db init") -nextKatacodaStep("Initial commit", [{ "file": "files/initialCommit.md" }]) +display("Initial commit", [{ "file": "files/initialCommit.md" }]) executeCommand("flask db upgrade","flask db upgrade") -- [step] -- executeCommand("flask run","flask run") -nextKatacodaStep("Postman test", [{ "file": "files/postmanTest.md" }]) +display("Postman test", [{ "file": "files/postmanTest.md" }]) -- From ca9fad599bb716197a425c40c8523aa94afa17ee Mon Sep 17 00:00:00 2001 From: Milla Martinez Date: Tue, 13 Jul 2021 12:37:48 +0200 Subject: [PATCH 10/13] '11' --- CRUD-Python-CobiGen/index.asciidoc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CRUD-Python-CobiGen/index.asciidoc b/CRUD-Python-CobiGen/index.asciidoc index b5113d31..80225b6b 100644 --- a/CRUD-Python-CobiGen/index.asciidoc +++ b/CRUD-Python-CobiGen/index.asciidoc @@ -48,13 +48,13 @@ executeCommand("pip install -r requirements.txt","pip install -r requirements.tx [step] -- executeCommand("flask db init","flask db init") -display("Initial commit", [{ "file": "files/initialCommit.md" }]) +displayContent("Initial commit", [{ "file": "files/initialCommit.md" }]) executeCommand("flask db upgrade","flask db upgrade") -- [step] -- executeCommand("flask run","flask run") -display("Postman test", [{ "file": "files/postmanTest.md" }]) +displayContent("Postman test", [{ "file": "files/postmanTest.md" }]) -- From fa2cc138fe5409e5c528443456e3fbc981c57a67 Mon Sep 17 00:00:00 2001 From: Milla Martinez Date: Wed, 14 Jul 2021 10:05:05 +0200 Subject: [PATCH 11/13] '12' --- CRUD-Python-CobiGen/files/postmanTest.md | 2 +- CRUD-Python-CobiGen/index.asciidoc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CRUD-Python-CobiGen/files/postmanTest.md b/CRUD-Python-CobiGen/files/postmanTest.md index f0413ea8..81b1d195 100644 --- a/CRUD-Python-CobiGen/files/postmanTest.md +++ b/CRUD-Python-CobiGen/files/postmanTest.md @@ -1,6 +1,6 @@ We can test our application using Postman. Paste the main path on a new Postman tab, for instance: -http://127.0.0.1:5000/user +Render port 80:
https://[[HOST_SUBDOMAIN]]-80-[[KATACODA_HOST]].environments.katacoda.com/user
Our table is empty for the moment, so we will select the POST method to add new data. We can submit JSON requests by clicking on the "Body" tab and selecting "raw". For example, submit: diff --git a/CRUD-Python-CobiGen/index.asciidoc b/CRUD-Python-CobiGen/index.asciidoc index 80225b6b..f8ba074e 100644 --- a/CRUD-Python-CobiGen/index.asciidoc +++ b/CRUD-Python-CobiGen/index.asciidoc @@ -54,7 +54,7 @@ executeCommand("flask db upgrade","flask db upgrade") [step] -- -executeCommand("flask run","flask run") +executeCommand("flask run --host=0.0.0.0 --port=80","flask run --host=0.0.0.0 --port=80") displayContent("Postman test", [{ "file": "files/postmanTest.md" }]) -- From 528650b7967aee622e7e14d52dc0bab1c52c041e Mon Sep 17 00:00:00 2001 From: Milla Martinez Date: Wed, 14 Jul 2021 10:12:38 +0200 Subject: [PATCH 12/13] '13' --- CRUD-Python-CobiGen/files/postmanTest.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CRUD-Python-CobiGen/files/postmanTest.md b/CRUD-Python-CobiGen/files/postmanTest.md index 81b1d195..8c4b3989 100644 --- a/CRUD-Python-CobiGen/files/postmanTest.md +++ b/CRUD-Python-CobiGen/files/postmanTest.md @@ -10,6 +10,8 @@ Our table is empty for the moment, so we will select the POST method to add new Our new user should now be accessible from the database under "id" number 1. Check this by submitting a GET request to the following path: +Render port 80:
https://[[HOST_SUBDOMAIN]]-80-[[KATACODA_HOST]].environments.katacoda.com/user/1
+ http://127.0.0.1:5000/user/1 We will now edit our entry by sending a PUT request. Submit the following body to http://127.0.0.1:5000/user/1: From de161daf09fde57243d0f1d7a675288695f9fb57 Mon Sep 17 00:00:00 2001 From: Milla Martinez Date: Thu, 15 Jul 2021 10:51:59 +0200 Subject: [PATCH 13/13] '9' --- CRUD-Python-CobiGen/files/postmanTest.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/CRUD-Python-CobiGen/files/postmanTest.md b/CRUD-Python-CobiGen/files/postmanTest.md index 8c4b3989..018c3b5d 100644 --- a/CRUD-Python-CobiGen/files/postmanTest.md +++ b/CRUD-Python-CobiGen/files/postmanTest.md @@ -1,6 +1,6 @@ -We can test our application using Postman. Paste the main path on a new Postman tab, for instance: +We can test our application using Postman. Paste the following path on a new Postman tab: -Render port 80:
https://[[HOST_SUBDOMAIN]]-80-[[KATACODA_HOST]].environments.katacoda.com/user
+https://[[HOST_SUBDOMAIN]]-80-[[KATACODA_HOST]].environments.katacoda.com/user Our table is empty for the moment, so we will select the POST method to add new data. We can submit JSON requests by clicking on the "Body" tab and selecting "raw". For example, submit: @@ -10,14 +10,13 @@ Our table is empty for the moment, so we will select the POST method to add new Our new user should now be accessible from the database under "id" number 1. Check this by submitting a GET request to the following path: -Render port 80:
https://[[HOST_SUBDOMAIN]]-80-[[KATACODA_HOST]].environments.katacoda.com/user/1
+https://[[HOST_SUBDOMAIN]]-80-[[KATACODA_HOST]].environments.katacoda.com/user/1 -http://127.0.0.1:5000/user/1 -We will now edit our entry by sending a PUT request. Submit the following body to http://127.0.0.1:5000/user/1: +We will now edit our entry by sending a PUT request. Submit the following body to https://[[HOST_SUBDOMAIN]]-80-[[KATACODA_HOST]].environments.katacoda.com/user/1: { "phone" : "777123" } Now send another GET request and check whether the column was properly updated. -Lastly, you can check the DELETE method by sending this request to http://127.0.0.1:5000/user/1. Then send a GET request to http://127.0.0.1:5000/user. The application returns "User list is empty". +Lastly, you can check the DELETE method by sending this request to https://[[HOST_SUBDOMAIN]]-80-[[KATACODA_HOST]].environments.katacoda.com/user/1. Then send a GET request to https://[[HOST_SUBDOMAIN]]-80-[[KATACODA_HOST]].environments.katacoda.com/user. The application returns "User list is empty".