From 4b1b328f072381ce42f5100ad45336a86c1e8bdb Mon Sep 17 00:00:00 2001
From: Ruslan Rabadanov <ruslanrabadanov2101@gmail.com>
Date: Mon, 3 Mar 2025 20:45:40 +0100
Subject: [PATCH] FE-6 Mock chart data and add fetch API methods

---
 src/app/api/configuration.api.ts              |  2 +-
 src/app/api/dashboard.api.ts                  | 56 ++++++++++++++-
 src/app/interceptor/interceptor.ts            | 36 +++++++++-
 src/app/interceptor/mocks/frames-current.json |  4 ++
 .../interceptor/mocks/frames-historical.json  | 64 +++++++++++++++++
 src/app/interceptor/mocks/ipv4-current.json   |  4 ++
 .../interceptor/mocks/ipv4-historical.json    | 68 +++++++++++++++++++
 src/app/interceptor/mocks/ir-current.json     |  4 ++
 src/app/interceptor/mocks/ir-historical.json  | 52 ++++++++++++++
 src/app/models/chart-frames.ts                |  4 ++
 src/app/models/chart-information-rate.ts      |  4 ++
 src/app/models/chart-protocol.ts              |  4 ++
 12 files changed, 295 insertions(+), 7 deletions(-)
 create mode 100644 src/app/interceptor/mocks/frames-current.json
 create mode 100644 src/app/interceptor/mocks/frames-historical.json
 create mode 100644 src/app/interceptor/mocks/ipv4-current.json
 create mode 100644 src/app/interceptor/mocks/ipv4-historical.json
 create mode 100644 src/app/interceptor/mocks/ir-current.json
 create mode 100644 src/app/interceptor/mocks/ir-historical.json
 create mode 100644 src/app/models/chart-frames.ts
 create mode 100644 src/app/models/chart-information-rate.ts
 create mode 100644 src/app/models/chart-protocol.ts

diff --git a/src/app/api/configuration.api.ts b/src/app/api/configuration.api.ts
index 064fd85..b134ce5 100644
--- a/src/app/api/configuration.api.ts
+++ b/src/app/api/configuration.api.ts
@@ -9,7 +9,7 @@ import {
 } from '../models/configuration';
 import { ApiResponse } from '../models/api-response';
 
-export const CONFIGURATION_API_URL = '/api/v1/configuration';
+export const CONFIGURATION_API_URL = '/configurations';
 
 @Injectable({
   providedIn: 'root',
diff --git a/src/app/api/dashboard.api.ts b/src/app/api/dashboard.api.ts
index 3f08285..c6fe7e8 100644
--- a/src/app/api/dashboard.api.ts
+++ b/src/app/api/dashboard.api.ts
@@ -1,8 +1,58 @@
-import { Injectable } from '@angular/core';
+import { inject, Injectable } from '@angular/core';
+import { HttpClient } from '@angular/common/http';
+import { ApiResponse } from '../models/api-response';
+import { ChartFrames } from '../models/chart-frames';
+import { map, Observable } from 'rxjs';
+import { ChartInformationRate } from '../models/chart-information-rate';
+import { ChartProtocol } from '../models/chart-protocol';
 
-export const DASHBOARD_API_URL = '/api/v1/dashboard';
+export const DASHBOARD_API_URL = '/statistics';
 
 @Injectable({
   providedIn: 'root',
 })
-export class DashboardApi {}
+export class DashboardApi {
+  private readonly httpClient = inject(HttpClient);
+
+  fetchFramesHistory(): Observable<ChartFrames[]> {
+    return this.httpClient
+      .get<ApiResponse<ChartFrames[]>>(`${DASHBOARD_API_URL}/frames/historical`)
+      .pipe(map(response => response.data));
+  }
+
+  fetchFrames(): Observable<ChartFrames> {
+    return this.httpClient
+      .get<ApiResponse<ChartFrames>>(`${DASHBOARD_API_URL}/frames/current`)
+      .pipe(map(response => response.data));
+  }
+
+  fetchInformationRateHistory(): Observable<ChartInformationRate[]> {
+    return this.httpClient
+      .get<
+        ApiResponse<ChartInformationRate[]>
+      >(`${DASHBOARD_API_URL}/information-rate/historical`)
+      .pipe(map(response => response.data));
+  }
+
+  fetchInformationRate(): Observable<ChartInformationRate> {
+    return this.httpClient
+      .get<
+        ApiResponse<ChartInformationRate>
+      >(`${DASHBOARD_API_URL}/information-rate/current`)
+      .pipe(map(response => response.data));
+  }
+
+  fetchProtocolHistory(): Observable<ChartProtocol[]> {
+    return this.httpClient
+      .get<
+        ApiResponse<ChartProtocol[]>
+      >(`${DASHBOARD_API_URL}/protocols/historical`)
+      .pipe(map(response => response.data));
+  }
+
+  fetchProtocol(): Observable<ChartProtocol> {
+    return this.httpClient
+      .get<ApiResponse<ChartProtocol>>(`${DASHBOARD_API_URL}/protocols/current`)
+      .pipe(map(response => response.data));
+  }
+}
diff --git a/src/app/interceptor/interceptor.ts b/src/app/interceptor/interceptor.ts
index 2dfdedf..21905b0 100644
--- a/src/app/interceptor/interceptor.ts
+++ b/src/app/interceptor/interceptor.ts
@@ -1,18 +1,48 @@
 import * as configurationList from './mocks/configurations.json';
 import * as configuration1 from './mocks/configuration-1.json';
 import * as configuration2 from './mocks/configuration-2.json';
+import * as framesCurrent from './mocks/frames-current.json';
+import * as framesHistorical from './mocks/frames-historical.json';
+import * as irCurrent from './mocks/ir-current.json';
+import * as irHistorical from './mocks/ir-historical.json';
+import * as ipv4Current from './mocks/ipv4-current.json';
+import * as ipv4Historical from './mocks/ipv4-historical.json';
 
 export const urls = [
   {
-    url: '/api/v1/configuration/1abc',
+    url: '/configurations/1abc',
     json: configuration1,
   },
   {
-    url: '/api/v1/configuration/2def',
+    url: '/configurations/2def',
     json: configuration2,
   },
   {
-    url: '/api/v1/configuration',
+    url: '/configurations',
     json: configurationList,
   },
+  {
+    url: '/statistics/frames/current',
+    json: framesCurrent,
+  },
+  {
+    url: '/statistics/frames/historical',
+    json: framesHistorical,
+  },
+  {
+    url: '/statistics/ir/current',
+    json: irCurrent,
+  },
+  {
+    url: '/statistics/ir/historical',
+    json: irHistorical,
+  },
+  {
+    url: '/statistics/ipv4/current',
+    json: ipv4Current,
+  },
+  {
+    url: '/statistics/ipv4/historical',
+    json: ipv4Historical,
+  },
 ];
diff --git a/src/app/interceptor/mocks/frames-current.json b/src/app/interceptor/mocks/frames-current.json
new file mode 100644
index 0000000..f336aa5
--- /dev/null
+++ b/src/app/interceptor/mocks/frames-current.json
@@ -0,0 +1,4 @@
+{
+  "valid": 2345,
+  "invalid": 234
+}
diff --git a/src/app/interceptor/mocks/frames-historical.json b/src/app/interceptor/mocks/frames-historical.json
new file mode 100644
index 0000000..134de06
--- /dev/null
+++ b/src/app/interceptor/mocks/frames-historical.json
@@ -0,0 +1,64 @@
+{
+  "frames": [
+    {
+      "valid": 1000,
+      "invalid": 15
+    },
+    {
+      "valid": 1500,
+      "invalid": 0
+    },
+    {
+      "valid": 100,
+      "invalid": 99
+    },
+    {
+      "valid": 1234,
+      "invalid": 123
+    },
+    {
+      "valid": 1555,
+      "invalid": 25
+    },
+    {
+      "valid": 1000,
+      "invalid": 15
+    },
+    {
+      "valid": 1500,
+      "invalid": 0
+    },
+    {
+      "valid": 100,
+      "invalid": 99
+    },
+    {
+      "valid": 1234,
+      "invalid": 123
+    },
+    {
+      "valid": 1555,
+      "invalid": 25
+    },
+    {
+      "valid": 1000,
+      "invalid": 15
+    },
+    {
+      "valid": 1500,
+      "invalid": 0
+    },
+    {
+      "valid": 100,
+      "invalid": 99
+    },
+    {
+      "valid": 1234,
+      "invalid": 123
+    },
+    {
+      "valid": 1555,
+      "invalid": 25
+    }
+  ]
+}
diff --git a/src/app/interceptor/mocks/ipv4-current.json b/src/app/interceptor/mocks/ipv4-current.json
new file mode 100644
index 0000000..7b75083
--- /dev/null
+++ b/src/app/interceptor/mocks/ipv4-current.json
@@ -0,0 +1,4 @@
+{
+  "bytes": 3000,
+  "packets": 58
+}
diff --git a/src/app/interceptor/mocks/ipv4-historical.json b/src/app/interceptor/mocks/ipv4-historical.json
new file mode 100644
index 0000000..d57ce55
--- /dev/null
+++ b/src/app/interceptor/mocks/ipv4-historical.json
@@ -0,0 +1,68 @@
+{
+  "statistics": [
+    {
+      "bytes": 2048,
+      "packets": 24
+    },
+    {
+      "bytes": 1024,
+      "packets": 16
+    },
+    {
+      "bytes": 1526,
+      "packets": 32
+    },
+    {
+      "bytes": 1920,
+      "packets": 48
+    },
+    {
+      "bytes": 2048,
+      "packets": 24
+    },
+    {
+      "bytes": 1024,
+      "packets": 16
+    },
+    {
+      "bytes": 1526,
+      "packets": 32
+    },
+    {
+      "bytes": 1920,
+      "packets": 48
+    },
+    {
+      "bytes": 2048,
+      "packets": 24
+    },
+    {
+      "bytes": 1024,
+      "packets": 16
+    },
+    {
+      "bytes": 1526,
+      "packets": 32
+    },
+    {
+      "bytes": 1920,
+      "packets": 48
+    },
+    {
+      "bytes": 2048,
+      "packets": 24
+    },
+    {
+      "bytes": 1024,
+      "packets": 16
+    },
+    {
+      "bytes": 1526,
+      "packets": 32
+    },
+    {
+      "bytes": 1920,
+      "packets": 48
+    }
+  ]
+}
diff --git a/src/app/interceptor/mocks/ir-current.json b/src/app/interceptor/mocks/ir-current.json
new file mode 100644
index 0000000..0aacc58
--- /dev/null
+++ b/src/app/interceptor/mocks/ir-current.json
@@ -0,0 +1,4 @@
+{
+  "current": 123.45,
+  "average": 123.4
+}
diff --git a/src/app/interceptor/mocks/ir-historical.json b/src/app/interceptor/mocks/ir-historical.json
new file mode 100644
index 0000000..593d659
--- /dev/null
+++ b/src/app/interceptor/mocks/ir-historical.json
@@ -0,0 +1,52 @@
+{
+  "statistics": [
+    {
+      "current": 123.45,
+      "average": 134.6
+    },
+    {
+      "current": 103.45,
+      "average": 114.6
+    },
+    {
+      "current": 153.45,
+      "average": 124.6
+    },
+    {
+      "current": 193.45,
+      "average": 144.6
+    },
+    {
+      "current": 123.45,
+      "average": 134.6
+    },
+    {
+      "current": 103.45,
+      "average": 114.6
+    },
+    {
+      "current": 153.45,
+      "average": 124.6
+    },
+    {
+      "current": 193.45,
+      "average": 144.6
+    },
+    {
+      "current": 123.45,
+      "average": 134.6
+    },
+    {
+      "current": 103.45,
+      "average": 114.6
+    },
+    {
+      "current": 153.45,
+      "average": 124.6
+    },
+    {
+      "current": 193.45,
+      "average": 144.6
+    }
+  ]
+}
diff --git a/src/app/models/chart-frames.ts b/src/app/models/chart-frames.ts
new file mode 100644
index 0000000..03956ce
--- /dev/null
+++ b/src/app/models/chart-frames.ts
@@ -0,0 +1,4 @@
+export interface ChartFrames {
+  valid: number;
+  invalid: number;
+}
diff --git a/src/app/models/chart-information-rate.ts b/src/app/models/chart-information-rate.ts
new file mode 100644
index 0000000..ee2919d
--- /dev/null
+++ b/src/app/models/chart-information-rate.ts
@@ -0,0 +1,4 @@
+export interface ChartInformationRate {
+  current: number;
+  average: number;
+}
diff --git a/src/app/models/chart-protocol.ts b/src/app/models/chart-protocol.ts
new file mode 100644
index 0000000..22844a0
--- /dev/null
+++ b/src/app/models/chart-protocol.ts
@@ -0,0 +1,4 @@
+export interface ChartProtocol {
+  bytes: number;
+  packets: number;
+}
-- 
GitLab