From 42c9bde3693239295ab0cb7cd823b07c379ee717 Mon Sep 17 00:00:00 2001 From: Vadim Belov Date: Wed, 18 Dec 2024 19:31:53 -0800 Subject: [PATCH] Refactor BackupStatus model to include ID and update related components for improved backup job tracking --- .../Controllers/AuthController.cs | 1 - .../Controllers/BackupController.cs | 8 +++--- .../Octockup.Server/Models/BackupStatus.cs | 2 +- Sources/octockup.client/src/api/types.ts | 1 + .../src/components/Dashboard.tsx | 26 +++++++++++++++++-- Sources/octockup.client/src/locales/en.json | 1 + Sources/octockup.client/src/locales/ru.json | 1 + 7 files changed, 32 insertions(+), 8 deletions(-) diff --git a/Sources/Octockup.Server/Controllers/AuthController.cs b/Sources/Octockup.Server/Controllers/AuthController.cs index 80bc8f2..471bfce 100644 --- a/Sources/Octockup.Server/Controllers/AuthController.cs +++ b/Sources/Octockup.Server/Controllers/AuthController.cs @@ -2,7 +2,6 @@ using Octockup.Server.Models; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Authorization; -using EasyExtensions; namespace Octockup.Server.Controllers { diff --git a/Sources/Octockup.Server/Controllers/BackupController.cs b/Sources/Octockup.Server/Controllers/BackupController.cs index ccdd2ca..1d0e537 100644 --- a/Sources/Octockup.Server/Controllers/BackupController.cs +++ b/Sources/Octockup.Server/Controllers/BackupController.cs @@ -5,7 +5,7 @@ namespace Octockup.Server.Controllers { [ApiController] - [Route("api/[controller]")] + [Route("/api/v1/[controller]")] public class BackupController : ControllerBase { [HttpGet(nameof(Status))] @@ -14,9 +14,9 @@ public async Task> Status() // mock data return new List { - new BackupStatus("Job1", DateTime.UtcNow, TimeSpan.FromMinutes(10), BackupStatusType.Completed), - new BackupStatus("Job2", DateTime.UtcNow.AddDays(-1), TimeSpan.FromMinutes(5), BackupStatusType.Running), - new BackupStatus("Job3", DateTime.Now, TimeSpan.FromMinutes(15), BackupStatusType.Failed), + new BackupStatus(51, "Job1", DateTime.UtcNow, TimeSpan.FromMinutes(10), BackupStatusType.Completed), + new BackupStatus(52, "Job2", DateTime.UtcNow.AddDays(-1), TimeSpan.FromMinutes(5), BackupStatusType.Running), + new BackupStatus(53, "Job3", DateTime.Now, TimeSpan.FromMinutes(15), BackupStatusType.Failed), }; } } diff --git a/Sources/Octockup.Server/Models/BackupStatus.cs b/Sources/Octockup.Server/Models/BackupStatus.cs index 5e4bbb2..3d74d75 100644 --- a/Sources/Octockup.Server/Models/BackupStatus.cs +++ b/Sources/Octockup.Server/Models/BackupStatus.cs @@ -2,5 +2,5 @@ namespace Octockup.Server.Models { - public record BackupStatus(string JobName, DateTime LastRun, TimeSpan Duration, BackupStatusType Status); + public record BackupStatus(int Id, string JobName, DateTime LastRun, TimeSpan Duration, BackupStatusType Status); } diff --git a/Sources/octockup.client/src/api/types.ts b/Sources/octockup.client/src/api/types.ts index c69c768..67b56cd 100644 --- a/Sources/octockup.client/src/api/types.ts +++ b/Sources/octockup.client/src/api/types.ts @@ -23,6 +23,7 @@ export enum UserRole { } export interface BackupStatus { + id: number; jobName: string; lastRun: string; duration: string; diff --git a/Sources/octockup.client/src/components/Dashboard.tsx b/Sources/octockup.client/src/components/Dashboard.tsx index 3ecbb26..2199b62 100644 --- a/Sources/octockup.client/src/components/Dashboard.tsx +++ b/Sources/octockup.client/src/components/Dashboard.tsx @@ -1,11 +1,25 @@ -import { User } from "../api/types"; +import { useEffect, useState } from "react"; import { useTranslation } from "react-i18next"; import { Box, Typography } from "@mui/material"; +import { BackupStatus, User } from "../api/types"; import useAuthUser from "react-auth-kit/hooks/useAuthUser"; +import { getBackupStatus } from "../api/api"; +import { toast } from "react-toastify"; const Dashboard: React.FC = () => { const { t } = useTranslation(); const authUser = useAuthUser(); + const [status, setStatus] = useState([]); + + useEffect(() => { + getBackupStatus() + .then((response) => { + setStatus(response); + }) + .catch((error) => { + toast.error(t("dataLoadError", { error: error.message })); + }); + }, [t]); return ( { - {/* Main content goes here */} + {status.map((backup, index) => ( + + {backup.id} + {backup.jobName} + {backup.lastRun} + {backup.duration} + {backup.status} + + ))} ); diff --git a/Sources/octockup.client/src/locales/en.json b/Sources/octockup.client/src/locales/en.json index 0b66590..f61b6b7 100644 --- a/Sources/octockup.client/src/locales/en.json +++ b/Sources/octockup.client/src/locales/en.json @@ -1,4 +1,5 @@ { + "dataLoadError": "Error loading data: {{error}}", "profile": { "title": "Profile", "newPassword": "New Password", diff --git a/Sources/octockup.client/src/locales/ru.json b/Sources/octockup.client/src/locales/ru.json index 7f389bd..491473d 100644 --- a/Sources/octockup.client/src/locales/ru.json +++ b/Sources/octockup.client/src/locales/ru.json @@ -1,4 +1,5 @@ { + "dataLoadError": "Ошибка загрузки данных: {{error}}", "profile": { "title": "Профиль", "newPassword": "Новый пароль",