From 6550ffb94930440c6f17eb42a719f811e99f68cc Mon Sep 17 00:00:00 2001 From: kozyradamian Date: Thu, 19 Dec 2024 13:27:13 +0100 Subject: [PATCH 01/34] Add docker-compose step --- .github/workflows/python-app.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 1168bd9..ecfdb62 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -37,3 +37,6 @@ jobs: - name: Test with pytest run: | pytest + - name: Start app using Docker Compose + run: | + docker-compose up -d From e6644c27daff50c103186887524a80d37648934d Mon Sep 17 00:00:00 2001 From: kozyradamian Date: Thu, 19 Dec 2024 13:28:16 +0100 Subject: [PATCH 02/34] Fix syntax --- .github/workflows/python-app.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index ecfdb62..701b066 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -39,4 +39,4 @@ jobs: pytest - name: Start app using Docker Compose run: | - docker-compose up -d + docker-compose up -d From d46e527e9e59e6ab10cf8b36a2983eff0df24641 Mon Sep 17 00:00:00 2001 From: kozyradamian Date: Thu, 19 Dec 2024 13:33:07 +0100 Subject: [PATCH 03/34] Test docker-compose --- .github/workflows/python-app.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 701b066..a9dc3c7 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -5,7 +5,7 @@ name: Python application on: push: - branches: [ "main" ] + branches: [ "main" , "dockerfile"] pull_request: branches: [ "main" ] @@ -38,5 +38,8 @@ jobs: run: | pytest - name: Start app using Docker Compose + run: + runs-on: ubuntu-latest + steps: run: | docker-compose up -d From a292693482934f9824cb51d8f36a7053f4f55e79 Mon Sep 17 00:00:00 2001 From: kozyradamian Date: Thu, 19 Dec 2024 13:35:05 +0100 Subject: [PATCH 04/34] Test docker-compose --- .github/workflows/python-app.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index a9dc3c7..6162187 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -5,7 +5,8 @@ name: Python application on: push: - branches: [ "main" , "dockerfile"] + push: + branches: [ "main", "dockerfile" ] pull_request: branches: [ "main" ] @@ -38,8 +39,5 @@ jobs: run: | pytest - name: Start app using Docker Compose - run: - runs-on: ubuntu-latest - steps: run: | docker-compose up -d From 551eabc777049ade14de8e912e7de8d381c5d1b0 Mon Sep 17 00:00:00 2001 From: kozyradamian Date: Thu, 19 Dec 2024 13:43:08 +0100 Subject: [PATCH 05/34] Test docker-compose --- .github/workflows/python-app.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 6162187..f1b9296 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -38,6 +38,9 @@ jobs: - name: Test with pytest run: | pytest + - name: Verify docker compose version + run: | + docker compose version - name: Start app using Docker Compose run: | docker-compose up -d From bc589f45c6ad4b348692f08bc13353fbd7f90d0e Mon Sep 17 00:00:00 2001 From: kozyradamian Date: Thu, 19 Dec 2024 13:45:22 +0100 Subject: [PATCH 06/34] Test docker-compose --- .github/workflows/python-app.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index f1b9296..95e5f82 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -43,4 +43,4 @@ jobs: docker compose version - name: Start app using Docker Compose run: | - docker-compose up -d + docker compose up -d From 49e5c933e12dc303eed1a1fe3105cba18099e6ae Mon Sep 17 00:00:00 2001 From: kozyradamian Date: Thu, 19 Dec 2024 13:49:29 +0100 Subject: [PATCH 07/34] Test docker-compose --- backend/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/Dockerfile b/backend/Dockerfile index 626d869..c519415 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -4,7 +4,7 @@ FROM python:3.9-slim WORKDIR /app # Install dependencies -COPY requirements.txt . +COPY ../requirements.txt . RUN pip install -r requirements.txt # Copy the application code From ab2892f025bfe07f8cdd033eb63a5a94067c5d12 Mon Sep 17 00:00:00 2001 From: kozyradamian Date: Thu, 19 Dec 2024 13:50:27 +0100 Subject: [PATCH 08/34] Test docker-compose --- backend/Dockerfile | 2 +- requirements.txt => backend/requirements.txt | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename requirements.txt => backend/requirements.txt (100%) diff --git a/backend/Dockerfile b/backend/Dockerfile index c519415..626d869 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -4,7 +4,7 @@ FROM python:3.9-slim WORKDIR /app # Install dependencies -COPY ../requirements.txt . +COPY requirements.txt . RUN pip install -r requirements.txt # Copy the application code diff --git a/requirements.txt b/backend/requirements.txt similarity index 100% rename from requirements.txt rename to backend/requirements.txt From 6031923c23f1199e125fc2990eb1cfc44bf2bb02 Mon Sep 17 00:00:00 2001 From: kozyradamian Date: Thu, 19 Dec 2024 13:51:38 +0100 Subject: [PATCH 09/34] Test docker-compose --- requirements.txt | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 requirements.txt diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..b830796 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +Flask==2.0.1 +werkzeug==2.0.1 +flask-swagger-ui==4.11.1 +pytest==8.3.4 \ No newline at end of file From e83a7d428db2bd5c09c61b74c7b17f1832ccdb48 Mon Sep 17 00:00:00 2001 From: kozyradamian Date: Thu, 19 Dec 2024 13:55:15 +0100 Subject: [PATCH 10/34] Test docker-compose --- frontend/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/Dockerfile b/frontend/Dockerfile index 2307839..0eb327d 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -8,7 +8,7 @@ WORKDIR /app COPY package*.json ./ # Install the dependencies specified in package.json -RUN npm ci +npm install # Copy the rest of the application code to the working directory COPY . . From bc0962bfd68ef3059af8cac06b2b4daf7f2966b2 Mon Sep 17 00:00:00 2001 From: kozyradamian Date: Thu, 19 Dec 2024 13:55:50 +0100 Subject: [PATCH 11/34] Test docker-compose --- frontend/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/Dockerfile b/frontend/Dockerfile index 0eb327d..6fcaa24 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -8,7 +8,7 @@ WORKDIR /app COPY package*.json ./ # Install the dependencies specified in package.json -npm install +RUN npm install # Copy the rest of the application code to the working directory COPY . . From f99cc65ee76deefb2c63de2b6ae46bb316d7d10f Mon Sep 17 00:00:00 2001 From: kozyradamian Date: Thu, 19 Dec 2024 13:58:57 +0100 Subject: [PATCH 12/34] Test docker-compose --- frontend/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/Dockerfile b/frontend/Dockerfile index 6fcaa24..381a953 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -1,5 +1,5 @@ # Use the official Node.js 14 image as the base image for the frontend build stage -FROM node:14.17.0 as frontend +FROM node:14.20.0 as frontend # Set the working directory inside the container to /app WORKDIR /app From f33127a2266a3dcd1a198ebf8c35cce2a4ce539b Mon Sep 17 00:00:00 2001 From: kozyradamian Date: Thu, 19 Dec 2024 14:04:40 +0100 Subject: [PATCH 13/34] Test docker-compose --- frontend/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/Dockerfile b/frontend/Dockerfile index 381a953..3cac80e 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -1,5 +1,5 @@ # Use the official Node.js 14 image as the base image for the frontend build stage -FROM node:14.20.0 as frontend +FROM node:20 as frontend # Set the working directory inside the container to /app WORKDIR /app From f3fdddb2b36ab3a30970b0ff222c371fcd048f15 Mon Sep 17 00:00:00 2001 From: kozyradamian Date: Thu, 19 Dec 2024 14:10:35 +0100 Subject: [PATCH 14/34] Test docker-compose --- backend/requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backend/requirements.txt b/backend/requirements.txt index b830796..bb36676 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -1,4 +1,5 @@ Flask==2.0.1 werkzeug==2.0.1 flask-swagger-ui==4.11.1 -pytest==8.3.4 \ No newline at end of file +pytest==8.3.4 +uvicorn==0.34.0 \ No newline at end of file From 292f7fc8b1b40105cfdb7567f0710ea07a9053ad Mon Sep 17 00:00:00 2001 From: kozyradamian Date: Thu, 19 Dec 2024 14:13:20 +0100 Subject: [PATCH 15/34] Test docker-compose --- .github/workflows/python-app.yml | 2 +- requirements.txt | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) delete mode 100644 requirements.txt diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 95e5f82..94a3e0e 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -28,7 +28,7 @@ jobs: run: | python -m pip install --upgrade pip pip install flake8 pytest - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + if [ -f backend\requirements.txt ]; then pip install -r backend\requirements.txt; fi - name: Lint with flake8 run: | # stop the build if there are Python syntax errors or undefined names diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index b830796..0000000 --- a/requirements.txt +++ /dev/null @@ -1,4 +0,0 @@ -Flask==2.0.1 -werkzeug==2.0.1 -flask-swagger-ui==4.11.1 -pytest==8.3.4 \ No newline at end of file From 17b7df6d82065f998257fe0616a2b5d5e860e5f3 Mon Sep 17 00:00:00 2001 From: kozyradamian Date: Thu, 19 Dec 2024 14:15:01 +0100 Subject: [PATCH 16/34] Test docker-compose --- .github/workflows/python-app.yml | 2 +- requirements.txt | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 requirements.txt diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 94a3e0e..95e5f82 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -28,7 +28,7 @@ jobs: run: | python -m pip install --upgrade pip pip install flake8 pytest - if [ -f backend\requirements.txt ]; then pip install -r backend\requirements.txt; fi + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - name: Lint with flake8 run: | # stop the build if there are Python syntax errors or undefined names diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..b830796 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +Flask==2.0.1 +werkzeug==2.0.1 +flask-swagger-ui==4.11.1 +pytest==8.3.4 \ No newline at end of file From 12971180de3ebd46b9213a3f2fcc5256348d3167 Mon Sep 17 00:00:00 2001 From: kozyradamian Date: Thu, 19 Dec 2024 14:20:12 +0100 Subject: [PATCH 17/34] Remove test changes --- .github/workflows/python-app.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 95e5f82..aab0185 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -6,7 +6,7 @@ name: Python application on: push: push: - branches: [ "main", "dockerfile" ] + branches: [ "main"] pull_request: branches: [ "main" ] From 828ba6d3280090539c51d050e3063a3ec88eb421 Mon Sep 17 00:00:00 2001 From: kozyradamian Date: Thu, 19 Dec 2024 14:31:42 +0100 Subject: [PATCH 18/34] Remove test changes --- .github/workflows/python-app.yml | 2 +- requirements.txt | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index aab0185..95e5f82 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -6,7 +6,7 @@ name: Python application on: push: push: - branches: [ "main"] + branches: [ "main", "dockerfile" ] pull_request: branches: [ "main" ] diff --git a/requirements.txt b/requirements.txt index b830796..bb36676 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ Flask==2.0.1 werkzeug==2.0.1 flask-swagger-ui==4.11.1 -pytest==8.3.4 \ No newline at end of file +pytest==8.3.4 +uvicorn==0.34.0 \ No newline at end of file From 6a8e6c0b3e8be388116e7e4f2ad682636ae63861 Mon Sep 17 00:00:00 2001 From: kozyradamian Date: Thu, 19 Dec 2024 14:33:23 +0100 Subject: [PATCH 19/34] Test docker-compose --- backend/Dockerfile | 2 +- backend/requirements.txt | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) delete mode 100644 backend/requirements.txt diff --git a/backend/Dockerfile b/backend/Dockerfile index 626d869..aabe684 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -4,7 +4,7 @@ FROM python:3.9-slim WORKDIR /app # Install dependencies -COPY requirements.txt . +COPY ../../requirements.txt . RUN pip install -r requirements.txt # Copy the application code diff --git a/backend/requirements.txt b/backend/requirements.txt deleted file mode 100644 index bb36676..0000000 --- a/backend/requirements.txt +++ /dev/null @@ -1,5 +0,0 @@ -Flask==2.0.1 -werkzeug==2.0.1 -flask-swagger-ui==4.11.1 -pytest==8.3.4 -uvicorn==0.34.0 \ No newline at end of file From 252b4f4d17845ae436cde0e89ae7f684b23f9ee7 Mon Sep 17 00:00:00 2001 From: kozyradamian Date: Thu, 19 Dec 2024 14:35:12 +0100 Subject: [PATCH 20/34] Test docker-compose --- backend/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/Dockerfile b/backend/Dockerfile index aabe684..c519415 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -4,7 +4,7 @@ FROM python:3.9-slim WORKDIR /app # Install dependencies -COPY ../../requirements.txt . +COPY ../requirements.txt . RUN pip install -r requirements.txt # Copy the application code From edf8b05fb3f8a9fb9dd3fadb90bc56cdf5a0466f Mon Sep 17 00:00:00 2001 From: kozyradamian Date: Thu, 19 Dec 2024 14:38:34 +0100 Subject: [PATCH 21/34] Test docker-compose --- backend/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/Dockerfile b/backend/Dockerfile index c519415..626d869 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -4,7 +4,7 @@ FROM python:3.9-slim WORKDIR /app # Install dependencies -COPY ../requirements.txt . +COPY requirements.txt . RUN pip install -r requirements.txt # Copy the application code From 6998844af019500d48f96c908c14c42220d90367 Mon Sep 17 00:00:00 2001 From: kozyradamian Date: Thu, 19 Dec 2024 14:39:44 +0100 Subject: [PATCH 22/34] Test docker-compose --- backend/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/Dockerfile b/backend/Dockerfile index 626d869..975adf4 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -4,7 +4,7 @@ FROM python:3.9-slim WORKDIR /app # Install dependencies -COPY requirements.txt . +COPY ../../../requirements.txt . RUN pip install -r requirements.txt # Copy the application code From 62b9e34c76cdb461fbd2c833b5d44f64249ce004 Mon Sep 17 00:00:00 2001 From: kozyradamian Date: Thu, 19 Dec 2024 14:40:44 +0100 Subject: [PATCH 23/34] Test docker-compose --- backend/Dockerfile | 2 +- backend/requirements.txt | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 backend/requirements.txt diff --git a/backend/Dockerfile b/backend/Dockerfile index 975adf4..626d869 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -4,7 +4,7 @@ FROM python:3.9-slim WORKDIR /app # Install dependencies -COPY ../../../requirements.txt . +COPY requirements.txt . RUN pip install -r requirements.txt # Copy the application code diff --git a/backend/requirements.txt b/backend/requirements.txt new file mode 100644 index 0000000..bb36676 --- /dev/null +++ b/backend/requirements.txt @@ -0,0 +1,5 @@ +Flask==2.0.1 +werkzeug==2.0.1 +flask-swagger-ui==4.11.1 +pytest==8.3.4 +uvicorn==0.34.0 \ No newline at end of file From e8d8e952815eb4ca87748b4d194eb032cb97490c Mon Sep 17 00:00:00 2001 From: kozyradamian Date: Thu, 19 Dec 2024 14:42:05 +0100 Subject: [PATCH 24/34] Test docker-compose --- backend/requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backend/requirements.txt b/backend/requirements.txt index bb36676..f12093c 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -2,4 +2,5 @@ Flask==2.0.1 werkzeug==2.0.1 flask-swagger-ui==4.11.1 pytest==8.3.4 -uvicorn==0.34.0 \ No newline at end of file +uvicorn==0.34.0 +psycopg2==2.9.3 \ No newline at end of file From 6fdadd4ea7afefe0657187763ebe9a791b2a23ec Mon Sep 17 00:00:00 2001 From: kozyradamian Date: Thu, 19 Dec 2024 14:43:20 +0100 Subject: [PATCH 25/34] Test docker-compose --- backend/requirements.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/backend/requirements.txt b/backend/requirements.txt index f12093c..bb36676 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -2,5 +2,4 @@ Flask==2.0.1 werkzeug==2.0.1 flask-swagger-ui==4.11.1 pytest==8.3.4 -uvicorn==0.34.0 -psycopg2==2.9.3 \ No newline at end of file +uvicorn==0.34.0 \ No newline at end of file From f410a4efb97213bca82743f2f1f007783bd1e86f Mon Sep 17 00:00:00 2001 From: kozyradamian Date: Thu, 19 Dec 2024 14:43:37 +0100 Subject: [PATCH 26/34] Test docker-compose --- .github/workflows/python-app.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 95e5f82..aab0185 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -6,7 +6,7 @@ name: Python application on: push: push: - branches: [ "main", "dockerfile" ] + branches: [ "main"] pull_request: branches: [ "main" ] From 4c98396c69454226ebc5057ad85f4a4774dc1116 Mon Sep 17 00:00:00 2001 From: kozyradamian Date: Thu, 19 Dec 2024 14:56:58 +0100 Subject: [PATCH 27/34] Test docker-compose --- backend/requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backend/requirements.txt b/backend/requirements.txt index bb36676..87a041f 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -2,4 +2,5 @@ Flask==2.0.1 werkzeug==2.0.1 flask-swagger-ui==4.11.1 pytest==8.3.4 -uvicorn==0.34.0 \ No newline at end of file +psycopg2==2.9.3 +flask-cors==3.0.10 \ No newline at end of file From 17c63a53e560297d3fd3c0c9478dc6f0aa699517 Mon Sep 17 00:00:00 2001 From: kozyradamian Date: Thu, 19 Dec 2024 15:01:40 +0100 Subject: [PATCH 28/34] Test docker-compose --- backend/requirements.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/backend/requirements.txt b/backend/requirements.txt index 87a041f..67dd2e9 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -2,5 +2,4 @@ Flask==2.0.1 werkzeug==2.0.1 flask-swagger-ui==4.11.1 pytest==8.3.4 -psycopg2==2.9.3 flask-cors==3.0.10 \ No newline at end of file From 7f8200f1c93a8418def71ade3b721f7aab2a42d4 Mon Sep 17 00:00:00 2001 From: kozyradamian Date: Thu, 19 Dec 2024 15:06:01 +0100 Subject: [PATCH 29/34] Test docker-compose --- backend/requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/backend/requirements.txt b/backend/requirements.txt index 67dd2e9..2bdf050 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -2,4 +2,5 @@ Flask==2.0.1 werkzeug==2.0.1 flask-swagger-ui==4.11.1 pytest==8.3.4 +uvicorn==0.34.0 flask-cors==3.0.10 \ No newline at end of file From 1da5378d2177dc1a7ce16811fbffd008900ce30f Mon Sep 17 00:00:00 2001 From: kozyradamian Date: Thu, 19 Dec 2024 15:09:45 +0100 Subject: [PATCH 30/34] Remove test changes --- .github/workflows/python-app.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 95e5f82..4b09480 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -6,7 +6,7 @@ name: Python application on: push: push: - branches: [ "main", "dockerfile" ] + branches: [ "main" ] pull_request: branches: [ "main" ] From f9e984a6da8e9374de2aa8a28ad1fc4862049945 Mon Sep 17 00:00:00 2001 From: Palacz Adam Date: Thu, 19 Dec 2024 15:12:10 +0100 Subject: [PATCH 31/34] adjust flask api to Project table --- backend/app/app.py | 100 ++++++++++++++++++++++----------------- backend/app/test_app.py | 59 ++++++++++++----------- backend/app/test_data.py | 32 ++++++------- backend/db/db.py | 48 +++++++++++++++++++ 4 files changed, 149 insertions(+), 90 deletions(-) diff --git a/backend/app/app.py b/backend/app/app.py index e8b66de..44a7274 100644 --- a/backend/app/app.py +++ b/backend/app/app.py @@ -3,7 +3,7 @@ import sys import os sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) -from db.db import db_connect, db_insert_user, db_update_user, db_delete_user, db_get_user_by_username, db_insert_snippet, db_update_snippet, db_delete_snippet, db_get_snippet_by_id, db_filter_snippets, db_insert_comment, User, Comment, Snippet +from db.db import db_connect, db_insert_user, db_update_user, db_delete_user, db_get_user_by_username, db_insert_snippet, db_update_snippet, db_delete_snippet, db_get_snippet_by_id, db_filter_snippets, db_insert_comment, db_get_comments_by_snippet_id, db_insert_project, db_get_project_by_id, db_update_project, db_insert_user_project, db_get_all_comments, db_get_all_projects, User, Comment, Snippet, Project, UserProject app = Flask(__name__) CORS(app) # Enable CORS @@ -142,49 +142,61 @@ def get_comments(snippet_id): return jsonify([]), 200 return jsonify(comments[snippet_id]), 200 -# @app.route('/projects', methods=['POST']) -# def create_project(): -# conn = db_connect() -# project = Project( -# id=request.json.get('id'), -# name=request.json.get('name'), -# description=request.json.get('description') -# ) -# project_id = db_insert_project(conn, project) -# if project_id: -# return jsonify({'id': project_id, 'name': project.name, 'description': project.description}), 201 -# else: -# return jsonify({'error': 'Failed to create project'}), 500 - -# @app.route('/projects/', methods=['GET']) -# def get_project(project_id): -# conn = db_connect() -# project = db_get_project_by_id(conn, project_id) -# if project: -# return jsonify({'id': project.id, 'name': project.name, 'description': project.description}) -# else: -# return jsonify({'error': 'Project not found'}), 404 - -# @app.route('/projects/', methods=['PUT']) -# def update_project(project_id): -# conn = db_connect() -# project = Project( -# id=project_id, -# name=request.json.get('name'), -# description=request.json.get('description') -# ) -# db_update_project(conn, project) -# return jsonify({'id': project.id, 'name': project.name, 'description': project.description}) - -# @app.route('/projects//members', methods=['POST']) -# def add_project_member(project_id): -# conn = db_connect() -# project_member = ProjectMember( -# project_id=project_id, -# user_id=request.json.get('id') -# ) -# db_insert_project_member(conn, project_member) -# return jsonify({'project_id': project_id, 'user_id': project_member.user_id}), 201 +@app.route('/comments', methods=['GET']) +def get_all_comments(): + conn = db_connect() + comments = db_get_all_comments(conn) + return jsonify([{'id': comment.id, 'snippet_id': comment.snippet_id, 'user_name': comment.user_name, 'content': comment.content, 'created_at': comment.created_at} for comment in comments]) + +@app.route('/projects', methods=['POST']) +def create_project(): + conn = db_connect() + project = Project( + id=None, # ID will be generated by the database + name=request.json.get('name'), + description=request.json.get('description') + ) + project_id = db_insert_project(conn, project) + if project_id: + return jsonify({'id': project_id, 'name': project.name, 'description': project.description}), 201 + else: + return jsonify({'error': 'Failed to create project'}), 500 + +@app.route('/projects/', methods=['PUT']) +def update_project(project_id): + conn = db_connect() + project = Project( + id=project_id, + name=request.json.get('name'), + description=request.json.get('description') + ) + db_update_project(conn, project) + return jsonify({'id': project.id, 'name': project.name, 'description': project.description}) + +@app.route('/projects/', methods=['GET']) +def get_project(project_id): + conn = db_connect() + project = db_get_project_by_id(conn, project_id) + if project: + return jsonify({'id': project.id, 'name': project.name, 'description': project.description}) + else: + return jsonify({'error': 'Project not found'}), 404 + +@app.route('/projects', methods=['GET']) +def get_all_projects(): + conn = db_connect() + projects = db_get_all_projects(conn) + return jsonify([{'id': project.id, 'name': project.name, 'description': project.description} for project in projects]) + +@app.route('/projects//members', methods=['POST']) +def add_project_member(project_id): + conn = db_connect() + project_member = UserProject( + user_name=request.json.get('user_name'), + project_id=project_id + ) + db_insert_user_project(conn, project_member) + return jsonify({'project_id': project_id, 'user_name': project_member.user_name}), 201 if __name__ == '__main__': app.run(debug=True) \ No newline at end of file diff --git a/backend/app/test_app.py b/backend/app/test_app.py index 4b5d238..139c308 100644 --- a/backend/app/test_app.py +++ b/backend/app/test_app.py @@ -3,7 +3,7 @@ import sys import os sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) -from db.db import db_connect, db_insert_user, db_update_user, db_delete_user, db_get_user_by_username, db_insert_snippet, db_update_snippet, db_delete_snippet, db_get_snippet_by_id, db_filter_snippets, db_insert_comment, User, Comment, Snippet +from db.db import db_connect, db_insert_user, db_update_user, db_delete_user, db_get_user_by_username, db_insert_snippet, db_update_snippet, db_delete_snippet, db_get_snippet_by_id, db_filter_snippets, db_insert_comment, db_insert_project, User, Comment, Snippet, Project, UserProject @pytest.fixture def client(): @@ -136,35 +136,34 @@ def test_get_comments(client): assert response.status_code == 200 assert isinstance(response.json, list) -# def test_create_project(client): -# response = client.post('/projects', json={ -# 'id': 'project1', -# 'name': 'Project One', -# 'description': 'A sample project' -# }) -# assert response.status_code == 201 -# assert response.json['name'] == 'Project One' +def test_create_project(client): + response = client.post('/projects', json={ + 'name': 'Project One', + 'description': 'A sample project' + }) + assert response.status_code == 201 + assert response.json['name'] == 'Project One' -# def test_get_project(client): -# conn = db_connect() -# project = Project('project1', 'Project One', 'A sample project') -# db_insert_project(conn, project) -# response = client.get('/projects/project1') -# assert response.status_code == 200 -# assert response.json['name'] == 'Project One' +def test_get_project(client): + conn = db_connect() + project = Project(None, 'Project One', 'A sample project') + project_id = db_insert_project(conn, project) + response = client.get(f'/projects/{project_id}') + assert response.status_code == 200 + assert response.json['name'] == 'Project One' -# def test_update_project(client): -# conn = db_connect() -# project = Project('project1', 'Project One', 'A sample project') -# db_insert_project(conn, project) -# response = client.put('/projects/project1', json={'name': 'Updated Project One'}) -# assert response.status_code == 200 -# assert response.json['name'] == 'Updated Project One' +def test_update_project(client): + conn = db_connect() + project = Project(None, 'Project One', 'A sample project') + project_id = db_insert_project(conn, project) + response = client.put(f'/projects/{project_id}', json={'name': 'Updated Project One'}) + assert response.status_code == 200 + assert response.json['name'] == 'Updated Project One' -# def test_add_project_member(client): -# conn = db_connect() -# project = Project('project1', 'Project One', 'A sample project') -# db_insert_project(conn, project) -# response = client.post('/projects/project1/members', json={'id': 'member1'}) -# assert response.status_code == 201 -# assert 'member1' in response.json['user_id'] \ No newline at end of file +def test_add_project_member(client): + conn = db_connect() + project = Project(None, 'Project One', 'A sample project') + project_id = db_insert_project(conn, project) + response = client.post(f'/projects/{project_id}/members', json={'user_name': 'johndoe'}) + assert response.status_code == 201 + assert response.json['user_name'] == 'johndoe' \ No newline at end of file diff --git a/backend/app/test_data.py b/backend/app/test_data.py index 8128e74..789a147 100644 --- a/backend/app/test_data.py +++ b/backend/app/test_data.py @@ -1,7 +1,7 @@ import sys import os sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) -from db.db import db_connect, db_insert_user, db_update_user, db_delete_user, db_get_user_by_username, db_insert_snippet, db_update_snippet, db_delete_snippet, db_get_snippet_by_id, db_filter_snippets, db_insert_comment, User, Comment, Snippet +from db.db import db_connect, db_insert_user, db_insert_snippet, db_insert_comment, db_insert_project, db_insert_user_project, User, Comment, Snippet, Project, UserProject import datetime def generate_test_data(): @@ -32,21 +32,21 @@ def generate_test_data(): db_insert_comment(conn, comment) # Create projects - # projects = [ - # Project(None, 'Project One', 'A sample project'), - # Project(None, 'Project Two', 'Another sample project'), - # ] - # for project in projects: - # db_insert_project(conn, project) - - # # Create project members - # project_members = [ - # ProjectMember(1, 'johndoe'), - # ProjectMember(1, 'janedoe'), - # ProjectMember(2, 'johndoe'), - # ] - # for project_member in project_members: - # db_insert_project_member(conn, project_member) + projects = [ + Project(None, 'Project One', 'A sample project'), + Project(None, 'Project Two', 'Another sample project'), + ] + for project in projects: + db_insert_project(conn, project) + + # Create project members + project_members = [ + UserProject('johndoe', 1), + UserProject('janedoe', 1), + UserProject('johndoe', 2), + ] + for project_member in project_members: + db_insert_user_project(conn, project_member) conn.close() diff --git a/backend/db/db.py b/backend/db/db.py index c0b59f6..8e24f62 100644 --- a/backend/db/db.py +++ b/backend/db/db.py @@ -259,6 +259,20 @@ def db_get_comments_by_snippet_id(conn, snippet_id): print(f"Error fetching comments: {e}") return [] +def db_get_all_comments(conn): + try: + with conn.cursor() as cursor: + select_query = sql.SQL(""" + SELECT id, snippet_id, user_name, content, created_at + FROM comments + """) + cursor.execute(select_query) + comments_data = cursor.fetchall() + return [Comment(*comment) for comment in comments_data] + except Exception as e: + print(f"Error fetching comments: {e}") + return [] + def db_insert_project(conn, project): try: with conn.cursor() as cursor: @@ -306,6 +320,40 @@ def db_delete_project(conn, project_id): print(f"Error deleting project: {e}") conn.rollback() +def db_get_all_projects(conn): + try: + with conn.cursor() as cursor: + select_query = sql.SQL(""" + SELECT id, name, description + FROM projects + """) + cursor.execute(select_query) + projects_data = cursor.fetchall() + return [Project(*project) for project in projects_data] + except Exception as e: + print(f"Error fetching projects: {e}") + return [] + +def db_get_project_by_id(conn, project_id): + try: + with conn.cursor() as cursor: + select_query = sql.SQL(""" + SELECT id, name, description + FROM projects + WHERE id = %s + """) + cursor.execute(select_query, (project_id,)) + project_data = cursor.fetchone() + if project_data: + project = Project(*project_data) + return project + else: + print("Project not found") + return None + except Exception as e: + print(f"Error fetching project: {e}") + return None + def db_insert_user_project(conn, user_project): try: with conn.cursor() as cursor: From 2b02dc3037ab8baf0074c82e43a27ca963ccd2f0 Mon Sep 17 00:00:00 2001 From: Palacz Adam Date: Thu, 19 Dec 2024 15:15:15 +0100 Subject: [PATCH 32/34] delete test data injection --- backend/app/test_data.py | 55 ---------------------------------------- 1 file changed, 55 deletions(-) delete mode 100644 backend/app/test_data.py diff --git a/backend/app/test_data.py b/backend/app/test_data.py deleted file mode 100644 index 789a147..0000000 --- a/backend/app/test_data.py +++ /dev/null @@ -1,55 +0,0 @@ -import sys -import os -sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) -from db.db import db_connect, db_insert_user, db_insert_snippet, db_insert_comment, db_insert_project, db_insert_user_project, User, Comment, Snippet, Project, UserProject -import datetime - -def generate_test_data(): - conn = db_connect() - - # Create users - users = [ - User('johndoe', 'john@example.com', 'password123', 'John', 'Doe', 'A software developer with 10 years of experience.', ['Python', 'Flask', 'JavaScript']), - User('janedoe', 'jane@example.com', 'password123', 'Jane', 'Doe', 'A front-end developer.', ['HTML', 'CSS', 'JavaScript']), - ] - for user in users: - db_insert_user(conn, user) - - # Create snippets - snippets = [ - Snippet(None, 'print("Hello, World!")', ['example', 'hello world'], 'Python', 'johndoe'), - Snippet(None, '

Hello, World!

', ['example', 'hello world'], 'HTML', 'janedoe'), - ] - for snippet in snippets: - db_insert_snippet(conn, snippet) - - # Create comments - comments = [ - Comment(None, 1, 'janedoe', 'Great snippet!', datetime.datetime.now()), - Comment(None, 2, 'johndoe', 'Nice HTML example!', datetime.datetime.now()), - ] - for comment in comments: - db_insert_comment(conn, comment) - - # Create projects - projects = [ - Project(None, 'Project One', 'A sample project'), - Project(None, 'Project Two', 'Another sample project'), - ] - for project in projects: - db_insert_project(conn, project) - - # Create project members - project_members = [ - UserProject('johndoe', 1), - UserProject('janedoe', 1), - UserProject('johndoe', 2), - ] - for project_member in project_members: - db_insert_user_project(conn, project_member) - - conn.close() - -if __name__ == "__main__": - generate_test_data() - print("Test data generated successfully.") \ No newline at end of file From 4afe481fe66747b9e15428f8bdc041aa78d3069b Mon Sep 17 00:00:00 2001 From: Palacz Adam Date: Thu, 19 Dec 2024 15:20:46 +0100 Subject: [PATCH 33/34] add GET for project members --- backend/app/app.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/backend/app/app.py b/backend/app/app.py index 44a7274..88ac130 100644 --- a/backend/app/app.py +++ b/backend/app/app.py @@ -3,7 +3,7 @@ import sys import os sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) -from db.db import db_connect, db_insert_user, db_update_user, db_delete_user, db_get_user_by_username, db_insert_snippet, db_update_snippet, db_delete_snippet, db_get_snippet_by_id, db_filter_snippets, db_insert_comment, db_get_comments_by_snippet_id, db_insert_project, db_get_project_by_id, db_update_project, db_insert_user_project, db_get_all_comments, db_get_all_projects, User, Comment, Snippet, Project, UserProject +from db.db import db_connect, db_insert_user, db_update_user, db_delete_user, db_get_user_by_username, db_insert_snippet, db_update_snippet, db_delete_snippet, db_get_snippet_by_id, db_filter_snippets, db_insert_comment, db_get_comments_by_snippet_id, db_insert_project, db_get_project_by_id, db_update_project, db_insert_user_project, db_get_all_comments, db_get_all_projects, db_get_user_projects_by_project_id, User, Comment, Snippet, Project, UserProject app = Flask(__name__) CORS(app) # Enable CORS @@ -198,5 +198,11 @@ def add_project_member(project_id): db_insert_user_project(conn, project_member) return jsonify({'project_id': project_id, 'user_name': project_member.user_name}), 201 +@app.route('/projects//members', methods=['GET']) +def get_project_members(project_id): + conn = db_connect() + project_members = db_get_user_projects_by_project_id(conn, project_id) + return jsonify([{'user_name': member.user_name, 'project_id': member.project_id} for member in project_members]) + if __name__ == '__main__': app.run(debug=True) \ No newline at end of file From 00411f24184abece33c7628f781844b6a1ff3856 Mon Sep 17 00:00:00 2001 From: Jakub Ilski Date: Thu, 19 Dec 2024 15:34:18 +0100 Subject: [PATCH 34/34] added requirements --- requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 87a041f..fce4a26 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,4 +3,5 @@ werkzeug==2.0.1 flask-swagger-ui==4.11.1 pytest==8.3.4 psycopg2==2.9.3 -flask-cors==3.0.10 \ No newline at end of file +flask-cors==3.0.10 +requests \ No newline at end of file