Skip to content
Snippets Groups Projects
Commit 601a9ea8 authored by Lukáš Majdan's avatar Lukáš Majdan
Browse files

Merge branch 'develop' into 'master'

Added cheating detection api archive method.

See merge request muni-kypo-crp/frontend-angular/apis/kypo-training-api!76
parents 7017710d a99ef8c5
No related branches found
No related tags found
No related merge requests found
14.2.2 Added cheating detection archive api method.
14.2.1 Updated and enhanced apis, DTOs and mappers for experimental version of cheating detection. 14.2.1 Updated and enhanced apis, DTOs and mappers for experimental version of cheating detection.
14.2.0 Replaced sandbox id with sandbox uuid. 14.2.0 Replaced sandbox id with sandbox uuid.
14.1.0 Add apis, DTOs and mappers for experimental version of cheating detection. 14.1.0 Add apis, DTOs and mappers for experimental version of cheating detection.
......
...@@ -34,9 +34,8 @@ export abstract class CheatingDetectionApi { ...@@ -34,9 +34,8 @@ export abstract class CheatingDetectionApi {
abstract delete(cheatingDetectionId: number, trainingInstanceId: number): Observable<any>; abstract delete(cheatingDetectionId: number, trainingInstanceId: number): Observable<any>;
/** /**
* Sends http request to delete all cheating detections and its associated detection events * Sends http request to export (download) cheating detection
* by training instance id * @param cheatingDetectionId id of cheating detection which should be archived
* @param trainingInstanceId id of training instance
*/ */
abstract deleteAllByTrainingInstance(trainingInstanceId: number): Observable<any>; abstract archive(cheatingDetectionId: number): Observable<any>;
} }
import { HttpClient, HttpParams } from '@angular/common/http'; import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { PaginatedResource, OffsetPaginationEvent } from '@sentinel/common'; import { PaginatedResource, OffsetPaginationEvent, ResponseHeaderContentDispositionReader } from '@sentinel/common';
import { CheatingDetection } from '@muni-kypo-crp/training-model'; import { CheatingDetection } from '@muni-kypo-crp/training-model';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { map } from 'rxjs/operators'; import { catchError, map } from 'rxjs/operators';
import { KypoTrainingApiContext } from '../../other/kypo-training-api-context'; import { KypoTrainingApiContext } from '../../other/kypo-training-api-context';
import { CheatingDetectionApi } from './cheating-detection-api.service'; import { CheatingDetectionApi } from './cheating-detection-api.service';
import { PaginationParams } from '../../http/params/pagination-params'; import { PaginationParams } from '../../http/params/pagination-params';
...@@ -11,6 +11,8 @@ import { PaginationMapper } from '../../mappers/pagination-mapper'; ...@@ -11,6 +11,8 @@ import { PaginationMapper } from '../../mappers/pagination-mapper';
import { CheatingDetectionDTO } from '../../dto/cheating-detection/cheating-detection-dto'; import { CheatingDetectionDTO } from '../../dto/cheating-detection/cheating-detection-dto';
import { CheatingDetectionMapper } from '../../mappers/cheating-detection/cheating-detection-mapper'; import { CheatingDetectionMapper } from '../../mappers/cheating-detection/cheating-detection-mapper';
import { CheatingDetectionRestResource } from '../../dto/cheating-detection/cheating-detection-rest-resource'; import { CheatingDetectionRestResource } from '../../dto/cheating-detection/cheating-detection-rest-resource';
import { JSONErrorConverter } from '../../http/json-error-converter';
import { FileSaver } from '../../http/response-headers/file-saver';
/** /**
* Default implementation of service abstracting http communication with training event endpoints. * Default implementation of service abstracting http communication with training event endpoints.
...@@ -89,11 +91,25 @@ export class CheatingDetectionDefaultApi extends CheatingDetectionApi { ...@@ -89,11 +91,25 @@ export class CheatingDetectionDefaultApi extends CheatingDetectionApi {
} }
/** /**
* Sends http request to delete all cheating detections and its associated detection events * Sends http request to archive (download) cheating detection
* by training instance id * @param cheatingDetectionId id of cheating detection which should be archived
* @param trainingInstanceId id of training instance
*/ */
deleteAllByTrainingInstance(trainingInstanceId: number): Observable<any> { archive(cheatingDetectionId: number): Observable<any> {
return this.http.delete<any>(`${this.cheatingDetectionsEndpointUri}/${trainingInstanceId}/deleteAll`, {}); const filename = `cheating-detection-${cheatingDetectionId}.zip`;
const headers = new HttpHeaders();
headers.set('Accept', ['application/octet-stream']);
return this.http
.get(`${this.cheatingDetectionsEndpointUri}/exports/${cheatingDetectionId}`, {
responseType: 'blob',
observe: 'response',
headers,
})
.pipe(
catchError((err) => JSONErrorConverter.fromBlob(err)),
map((resp) => {
FileSaver.fromBlob(resp.body, ResponseHeaderContentDispositionReader.getFilenameFromResponse(resp, filename));
return true;
})
);
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment