Skip to content

Commit

Permalink
Refactor BackupStatus model to include ID and update related componen…
Browse files Browse the repository at this point in the history
…ts for improved backup job tracking
  • Loading branch information
bvdcode committed Dec 19, 2024
1 parent 8c85dfb commit 42c9bde
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 8 deletions.
1 change: 0 additions & 1 deletion Sources/Octockup.Server/Controllers/AuthController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Octockup.Server.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using EasyExtensions;

namespace Octockup.Server.Controllers
{
Expand Down
8 changes: 4 additions & 4 deletions Sources/Octockup.Server/Controllers/BackupController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Octockup.Server.Controllers
{
[ApiController]
[Route("api/[controller]")]
[Route("/api/v1/[controller]")]
public class BackupController : ControllerBase
{
[HttpGet(nameof(Status))]
Expand All @@ -14,9 +14,9 @@ public async Task<IEnumerable<BackupStatus>> Status()
// mock data
return new List<BackupStatus>
{
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),
};
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Octockup.Server/Models/BackupStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
1 change: 1 addition & 0 deletions Sources/octockup.client/src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export enum UserRole {
}

export interface BackupStatus {
id: number;
jobName: string;
lastRun: string;
duration: string;
Expand Down
26 changes: 24 additions & 2 deletions Sources/octockup.client/src/components/Dashboard.tsx
Original file line number Diff line number Diff line change
@@ -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<User>();
const [status, setStatus] = useState<BackupStatus[]>([]);

useEffect(() => {
getBackupStatus()
.then((response) => {
setStatus(response);
})
.catch((error) => {
toast.error(t("dataLoadError", { error: error.message }));
});
}, [t]);

return (
<Box
Expand All @@ -22,7 +36,15 @@ const Dashboard: React.FC = () => {
</Typography>
</Box>
<Box mt={2} flexGrow={1}>
{/* Main content goes here */}
{status.map((backup, index) => (
<Box key={index} display="flex" justifyContent="space-between">
<Typography>{backup.id}</Typography>
<Typography>{backup.jobName}</Typography>
<Typography>{backup.lastRun}</Typography>
<Typography>{backup.duration}</Typography>
<Typography>{backup.status}</Typography>
</Box>
))}
</Box>
</Box>
);
Expand Down
1 change: 1 addition & 0 deletions Sources/octockup.client/src/locales/en.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"dataLoadError": "Error loading data: {{error}}",
"profile": {
"title": "Profile",
"newPassword": "New Password",
Expand Down
1 change: 1 addition & 0 deletions Sources/octockup.client/src/locales/ru.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"dataLoadError": "Ошибка загрузки данных: {{error}}",
"profile": {
"title": "Профиль",
"newPassword": "Новый пароль",
Expand Down

0 comments on commit 42c9bde

Please sign in to comment.