generated from amosproj/amos202Xss0Y-projname
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #235 from amosproj/195-frontendbackend-module-over…
…view-about-total-backups 195 frontendbackend module overview about total backups
- Loading branch information
Showing
19 changed files
with
328 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
apps/backend/src/app/information/dto/backupInformation.dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
|
||
export class BackupInformationDto { | ||
@ApiProperty({ | ||
type: 'number', | ||
description: 'The total size of all backups in MB.', | ||
}) | ||
totalBackupSize!: number; | ||
|
||
@ApiProperty({ | ||
type: 'number', | ||
description: 'The number of backups that are stored.', | ||
}) | ||
numberOfBackups!: number; | ||
} |
19 changes: 19 additions & 0 deletions
19
apps/backend/src/app/information/information.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Controller, Get, Logger } from '@nestjs/common'; | ||
import { ApiOkResponse, ApiOperation, ApiTags } from '@nestjs/swagger'; | ||
import { InformationService } from './information.service'; | ||
import { BackupInformationDto } from './dto/backupInformation.dto'; | ||
|
||
@ApiTags('Informations') | ||
@Controller('information') | ||
export class InformationController { | ||
readonly logger = new Logger(InformationController.name); | ||
|
||
constructor(private readonly informationService: InformationService) {} | ||
|
||
@Get() | ||
@ApiOperation({ summary: 'Returns informations about metadata of our analysations' }) | ||
@ApiOkResponse() | ||
async findAll(): Promise<BackupInformationDto> { | ||
return this.informationService.getBackupInformation(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { InformationService } from './information.service'; | ||
import { InformationController } from './information.controller'; | ||
import { BackupDataModule } from '../backupData/backupData.module'; | ||
|
||
@Module({ | ||
providers: [InformationService], | ||
imports: [BackupDataModule], | ||
controllers: [InformationController], | ||
}) | ||
export class InformationModule {} |
44 changes: 44 additions & 0 deletions
44
apps/backend/src/app/information/information.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { InformationService } from './information.service'; | ||
import { BackupInformationDto } from './dto/backupInformation.dto'; | ||
import { BackupDataService } from '../backupData/backupData.service'; | ||
|
||
describe('InformationService', () => { | ||
let service: InformationService; | ||
let backupDataService: BackupDataService; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [ | ||
InformationService, | ||
{ | ||
provide: BackupDataService, | ||
useValue: { | ||
getTotalBackupInformation: jest.fn(), | ||
}, | ||
}, | ||
], | ||
}).compile(); | ||
|
||
backupDataService = module.get<BackupDataService>(BackupDataService); | ||
service = module.get<InformationService>(InformationService); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(service).toBeDefined(); | ||
}); | ||
|
||
it('should return backup information', async () => { | ||
const mockBackupInformation: BackupInformationDto = { | ||
totalBackupSize: 100, | ||
numberOfBackups: 10, | ||
}; | ||
|
||
jest | ||
.spyOn(backupDataService, 'getTotalBackupInformation') | ||
.mockResolvedValue(mockBackupInformation); | ||
|
||
const result = await service.getBackupInformation(); | ||
expect(result).toEqual(mockBackupInformation); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { BackupInformationDto } from './dto/backupInformation.dto'; | ||
import { BackupDataService } from '../backupData/backupData.service'; | ||
|
||
@Injectable() | ||
export class InformationService { | ||
constructor(private readonly backupDataService: BackupDataService) {} | ||
|
||
async getBackupInformation(): Promise<BackupInformationDto> { | ||
return await this.backupDataService.getTotalBackupInformation(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
apps/frontend/src/app/backups-overview-page/component/facts-panel/facts-panel.component.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
.facts-card { | ||
display: flex; | ||
justify-content: space-around; | ||
padding: 20px; | ||
background-color: #f3f8fb; | ||
border: 1px solid #dcdcdc; | ||
border-radius: 10px; | ||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); | ||
margin-bottom: 20px; | ||
text-align: center; | ||
} | ||
|
||
.facts-title { | ||
font-size: 1.2em; | ||
margin-bottom: 8px; | ||
color: #6c757d; | ||
} | ||
|
||
.facts-value { | ||
font-size: 2em; | ||
font-weight: bold; | ||
color: #343a40; | ||
} |
10 changes: 10 additions & 0 deletions
10
apps/frontend/src/app/backups-overview-page/component/facts-panel/facts-panel.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<div class="card facts-card"> | ||
<div class="facts-item"> | ||
<div class="facts-title">Total Size of All Backups</div> | ||
<div class="facts-value">{{ shortenBytes(((basicInformations$ | async)?.totalBackupSize ?? 0) * 1000000) }}</div> | ||
</div> | ||
<div class="facts-item"> | ||
<div class="facts-title">Number of Backups</div> | ||
<div class="facts-value">{{ (basicInformations$ | async)?.numberOfBackups }}</div> | ||
</div> | ||
</div> |
37 changes: 37 additions & 0 deletions
37
...rontend/src/app/backups-overview-page/component/facts-panel/facts-panel.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { beforeEach, describe, expect, it, Mock, vi } from 'vitest'; | ||
import { of } from 'rxjs'; | ||
import { FactsPanelComponent } from './facts-panel.component'; | ||
import { BasicInformation } from '../../../shared/types/basicInformation'; | ||
|
||
const mockInformations: BasicInformation = { | ||
numberOfBackups: 10, | ||
totalBackupSize: 100, | ||
}; | ||
describe('FactsPanel', () => { | ||
let component: FactsPanelComponent; | ||
let mockInformationService: { | ||
getBasicInformations: Mock; | ||
}; | ||
|
||
beforeEach(() => { | ||
mockInformationService = { | ||
getBasicInformations: vi.fn().mockReturnValue(of(mockInformations)), | ||
}; | ||
|
||
component = new FactsPanelComponent(mockInformationService as any); | ||
}); | ||
|
||
describe('basicInformations$', () => { | ||
it('should load basic informations correctly', (done) => { | ||
mockInformationService.getBasicInformations.mockReturnValue( | ||
of(mockInformations) | ||
); | ||
|
||
component.loadBasicInformations(); | ||
|
||
component.basicInformations$.subscribe((result) => { | ||
expect(result).toEqual(mockInformations); | ||
}); | ||
}); | ||
}); | ||
}); |
40 changes: 40 additions & 0 deletions
40
apps/frontend/src/app/backups-overview-page/component/facts-panel/facts-panel.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { Component, OnDestroy, OnInit } from '@angular/core'; | ||
import { Observable, of, shareReplay, Subject, takeUntil } from 'rxjs'; | ||
import { BasicInformation } from '../../../shared/types/basicInformation'; | ||
import { InformationServiceService } from '../../../shared/services/information-service/information-service.service'; | ||
import { shortenBytes } from '../../../shared/utils/shortenBytes'; | ||
|
||
@Component({ | ||
selector: 'app-facts-panel', | ||
templateUrl: './facts-panel.component.html', | ||
styleUrl: './facts-panel.component.css', | ||
}) | ||
export class FactsPanelComponent implements OnDestroy, OnInit { | ||
private readonly destroy$ = new Subject<void>(); | ||
basicInformations$: Observable<BasicInformation> = of(); | ||
|
||
constructor(private readonly informationService: InformationServiceService) {} | ||
|
||
ngOnInit() { | ||
this.loadBasicInformations(); | ||
this.informationService | ||
.getRefreshObservable() | ||
.pipe(takeUntil(this.destroy$)) | ||
.subscribe(() => { | ||
this.loadBasicInformations(); | ||
}); | ||
} | ||
|
||
ngOnDestroy(): void { | ||
this.destroy$.next(); | ||
this.destroy$.complete(); | ||
} | ||
|
||
loadBasicInformations(): void { | ||
this.basicInformations$ = this.informationService | ||
.getBasicInformations() | ||
.pipe(takeUntil(this.destroy$), shareReplay(1)); | ||
} | ||
|
||
protected readonly shortenBytes = shortenBytes; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.