diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index fe3853ca..c50350bf 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,4 +1,4 @@ -name: Build frontend +name: Build on: pull_request: @@ -8,11 +8,8 @@ on: jobs: build: - name: Build frontend + name: Build Jar with static frontend runs-on: ubuntu-latest - defaults: - run: - working-directory: db-scheduler-ui-frontend steps: - name: Checkout repo @@ -23,12 +20,33 @@ jobs: - name: Install dependencies run: npm install + working-directory: db-scheduler-ui-frontend - name: Build project run: npm run build + working-directory: db-scheduler-ui-frontend + + - name: Create static folder in backend + run: mkdir db-scheduler-ui-backend/src/main/resources/static + + - name: Copy static frontend to java package + run: cp -r db-scheduler-ui-frontend/dist/. db-scheduler-ui-backend/src/main/resources/static/ + + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + + - name: Build java module with Maven + run: mvn --batch-mode --update-snapshots package + working-directory: db-scheduler-ui-backend + + - name: look for jar file + run: ls -R db-scheduler-ui-backend - name: Upload production-ready build files uses: actions/upload-artifact@v3 with: name: production-files - path: db-scheduler-ui-frontend/dist + path: db-scheduler-ui-backend/target/*.jar diff --git a/db-scheduler-ui-backend/src/main/java/com/github/bekk/dbscheduleruibackend/controller/TestController.java b/db-scheduler-ui-backend/src/main/java/com/github/bekk/dbscheduleruibackend/controller/TestController.java index 0190984c..8fa98ed9 100644 --- a/db-scheduler-ui-backend/src/main/java/com/github/bekk/dbscheduleruibackend/controller/TestController.java +++ b/db-scheduler-ui-backend/src/main/java/com/github/bekk/dbscheduleruibackend/controller/TestController.java @@ -55,7 +55,7 @@ public void runNow(@RequestParam String id, @RequestParam String name) { public void deleteTaskNow(@RequestParam String id, @RequestParam String name) { taskService.deleteTask(id, name); } - + @GetMapping("api/run/all") public void runAllTasks(){ taskService.runAllTasks(); diff --git a/db-scheduler-ui-frontend/src/services/deleteTask.ts b/db-scheduler-ui-frontend/src/services/deleteTask.ts index 42840be1..9cce2cfd 100644 --- a/db-scheduler-ui-frontend/src/services/deleteTask.ts +++ b/db-scheduler-ui-frontend/src/services/deleteTask.ts @@ -1,4 +1,4 @@ -const API_BASE_URL: string = import.meta.env.VITE_API_BASE_URL as string; +const API_BASE_URL: string = import.meta.env.VITE_API_BASE_URL as string ?? window.location.origin + '/api'; const deleteTask = async (id: string, name: string) => { const response = await fetch(`${API_BASE_URL}/delete?id=${id}&name=${name}`, { diff --git a/db-scheduler-ui-frontend/src/services/getTaskById.ts b/db-scheduler-ui-frontend/src/services/getTaskById.ts deleted file mode 100644 index ad1eb43a..00000000 --- a/db-scheduler-ui-frontend/src/services/getTaskById.ts +++ /dev/null @@ -1,13 +0,0 @@ -const API_BASE_URL: string = import.meta.env.VITE_API_BASE_URL as string; - -const getTaskById = async (id: number) => { - const response = await fetch(`${API_BASE_URL}:8080/tasks/${id}`); - if (!response.ok) { - throw new Error( - `Error fetching task with ID: ${id}. Status: ${response.statusText}`, - ); - } - return await response.json(); -}; - -export default getTaskById; diff --git a/db-scheduler-ui-frontend/src/services/getTasks.ts b/db-scheduler-ui-frontend/src/services/getTasks.ts index 78db8639..b8fd9ea3 100644 --- a/db-scheduler-ui-frontend/src/services/getTasks.ts +++ b/db-scheduler-ui-frontend/src/services/getTasks.ts @@ -1,6 +1,6 @@ import { TasksResponse } from "src/models/TasksResponse"; -const API_BASE_URL: string = import.meta.env.VITE_API_BASE_URL as string; +const API_BASE_URL: string = import.meta.env.VITE_API_BASE_URL as string ?? window.location.origin + '/api'; export enum FilterBy { All = 'All', @@ -22,7 +22,7 @@ export enum SortBy { export const TASK_QUERY_KEY = `tasks`; export const getTasks = async ( - filter = FilterBy.All, + filter = FilterBy.All, { pageNumber = 1, limit = 10 }: PaginationParams, sorting = SortBy.Default, isAsc = true @@ -34,7 +34,7 @@ export const getTasks = async ( queryParams.append('size', limit.toString()); queryParams.append('sorting', sorting.toUpperCase()); queryParams.append('asc', isAsc.toString()); - + const response = await fetch(`${API_BASE_URL}/tasks?${queryParams}`, { method: 'GET', headers: { diff --git a/db-scheduler-ui-frontend/src/services/runTask.ts b/db-scheduler-ui-frontend/src/services/runTask.ts index ccb1255d..7edaa01f 100644 --- a/db-scheduler-ui-frontend/src/services/runTask.ts +++ b/db-scheduler-ui-frontend/src/services/runTask.ts @@ -1,4 +1,4 @@ -const API_BASE_URL: string = import.meta.env.VITE_API_BASE_URL as string; +const API_BASE_URL: string = import.meta.env.VITE_API_BASE_URL as string ?? window.location.origin + '/api'; const runTask = async (id: string, name: string) => { const response = await fetch(`${API_BASE_URL}/rerun?id=${id}&name=${name}`, {