Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions projects/core/src/lib/services/api/api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ export class ApiService {
.pipe(retry(exponentialBackoff(this.RETRY_COUNT)), first()) as Observable<Blob>;
}

postFile(path: string, body: object): Observable<Blob> {
return this.http.post(this.apiUrl + path, body, { responseType: "blob" }).pipe(first());
}

/**
* Выполняет PUT запрос к API (полное обновление ресурса)
* @param path - Относительный путь к ресурсу
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/** @format */
import { Injectable } from "@angular/core";

/** Короткоживущий переход между таблицей проектов и существующим редактором назначений. */
@Injectable({ providedIn: "root" })
export class ProgramProjectAssignmentSelection {
private value: { programId: number; projectIds: number[] } | null = null;
set(programId: number, projectIds: number[]): void {
this.value = { programId, projectIds };
}
take(programId: number): number[] | null {
const value = this.value;
this.value = null;
return value?.programId === programId ? value.projectIds : null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { inject, Injectable } from "@angular/core";
import { EvaluationRepositoryPort } from "@domain/program/ports/evaluation.repository.port";
import { EventBus } from "@domain/shared/event-bus";
import { ProgramUpdated } from "@domain/program/program-updated.event";
import { ExpertRegistration } from "@domain/program/evaluation-workspace.model";
import { ExpertRegistration, ExpertsBulkWrite } from "@domain/program/evaluation-workspace.model";
import { tap } from "rxjs";
@Injectable({ providedIn: "root" })
export class EvaluationUseCase {
Expand All @@ -18,6 +18,9 @@ export class EvaluationUseCase {
}
readonly programs = this.repository.programs.bind(this.repository);
readonly workspace = this.repository.workspace.bind(this.repository);
bulkExperts(id: number, data: ExpertsBulkWrite) {
return this.repository.bulkExperts(id, data);
}
readonly saveCaseScope = this.repository.saveCaseScope.bind(this.repository);
readonly saveInvitationCaseScope = this.repository.saveInvitationCaseScope.bind(this.repository);
readonly saveProjectExperts = this.repository.saveProjectExperts.bind(this.repository);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ export class ProgramManagementUseCase {
exportParticipants(id: number, q: ManagementQuery) {
return this.repository.exportParticipants(id, q);
}
selection(id: number, kind: "participants" | "projects", q: ManagementQuery) {
return this.repository.selection(id, kind, q);
}
exportSelectedParticipants(id: number, ids: number[]) {
return this.repository.exportSelectedParticipants(id, ids);
}
previewParticipantRemoval(id: number, ids: number[]) {
return this.repository.previewParticipantRemoval(id, ids);
}
removeParticipants(id: number, ids: number[], previewToken: string) {
return this.repository.removeParticipants(id, ids, previewToken);
}
projects(id: number, q: ManagementQuery) {
return this.repository.projects(id, q);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ export interface ExpertCaseScopeWrite {
allCases: boolean;
caseNames: (string | null)[];
}
export interface ExpertsBulkWrite extends ExpertCaseScopeWrite {
action: "cases" | "resend" | "revoke";
expertIds: number[];
invitationIds: number[];
}
export interface ProjectExpertsWrite {
revision: string;
projectIds: number[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ import {
ExpertRegistered,
ExpertCaseScopeWrite,
ProjectExpertsWrite,
ExpertsBulkWrite,
} from "@domain/program/evaluation-workspace.model";
export abstract class EvaluationRepositoryPort {
abstract programs(): Observable<EvaluationPrograms>;
abstract workspace(id: number): Observable<ExpertWorkspace>;
abstract bulkExperts(id: number, data: ExpertsBulkWrite): Observable<ExpertWorkspace>;
abstract saveCaseScope(
id: number,
expertId: number,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
ManagementSettingsWrite,
ManagementTeam,
ProgramManagement,
ManagementSelection,
ParticipantRemovalPreview,
} from "../program-management.model";

export abstract class ProgramManagementRepositoryPort {
Expand All @@ -35,6 +37,21 @@ export abstract class ProgramManagementRepositoryPort {
query: ManagementQuery,
): Observable<ManagementParticipantsPage>;
abstract exportParticipants(programId: number, query: ManagementQuery): Observable<Blob>;
abstract selection(
programId: number,
kind: "participants" | "projects",
query: ManagementQuery,
): Observable<ManagementSelection>;
abstract exportSelectedParticipants(programId: number, ids: number[]): Observable<Blob>;
abstract previewParticipantRemoval(
programId: number,
ids: number[],
): Observable<ParticipantRemovalPreview>;
abstract removeParticipants(
programId: number,
ids: number[],
previewToken: string,
): Observable<{ removed: number }>;
abstract projects(programId: number, query: ManagementQuery): Observable<ManagementProjectsPage>;
abstract team(programId: number, linkId: number): Observable<ManagementTeam>;
abstract evaluation(programId: number, linkId: number): Observable<ManagementEvaluation>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export interface ManagementProject {
name: string;
leader: { id: number; name: string };
submitted: boolean;
draft?: boolean;
evaluationStatus: ManagementEvaluationStatus;
assignmentsTotal: number | null;
assignmentsCompleted: number | null;
Expand Down Expand Up @@ -126,6 +127,7 @@ export interface ManagementQuery {
offset: number;
limit: number;
submission: "all" | "submitted" | "not_submitted";
evaluation?: "all" | "evaluated" | "not_evaluated";
caseScope: "all" | "selected" | "without_case";
caseName?: string;
regionScope?: "all" | "selected" | "without_region";
Expand All @@ -134,6 +136,23 @@ export interface ManagementQuery {
activityFrom?: string;
activityTo?: string;
}
export interface ManagementSelectionProject {
id: number;
projectId: number;
submitted: boolean;
caseName: string | null;
draft: boolean;
}
export interface ManagementSelection {
ids: number[];
projects?: ManagementSelectionProject[];
}
export interface ParticipantRemovalPreview {
previewToken: string;
participantCount: number;
applications: { id: number; projectId: number; name: string; submitted: boolean }[];
assignmentsCount: number;
}
export interface ManagementSettingsWrite {
expectedUpdatedAt: string;
confirmReopen?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
ExpertRegistered,
ExpertCaseScopeWrite,
ProjectExpertsWrite,
ExpertsBulkWrite,
} from "@domain/program/evaluation-workspace.model";
import { EvaluationRepositoryPort } from "@domain/program/ports/evaluation.repository.port";
@Injectable({ providedIn: "root" })
Expand All @@ -29,6 +30,9 @@ export class EvaluationHttpAdapter implements EvaluationRepositoryPort {
workspace(id: number): Observable<ExpertWorkspace> {
return this.api.get(`${this.root(id)}/experts/`);
}
bulkExperts(id: number, data: ExpertsBulkWrite): Observable<ExpertWorkspace> {
return this.api.post(`${this.root(id)}/experts/bulk/`, data);
}
saveCaseScope(
id: number,
expertId: number,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ describe("Контракт HTTP панели организатора", () => {
adapter
.projects(4, {
search: "Город",
offset: 25,
limit: 25,
offset: 20,
limit: 20,
evaluation: "not_evaluated",
submission: "submitted",
caseScope: "selected",
caseName: "Экология",
Expand All @@ -44,7 +45,8 @@ describe("Контракт HTTP панели организатора", () => {
const request = http.expectOne(r => r.url.endsWith("/programs/4/management/projects/"));
expect(request.request.params.get("case_scope")).toBe("selected");
expect(request.request.params.get("case_name")).toBe("Экология");
expect(request.request.params.get("offset")).toBe("25");
expect(request.request.params.get("offset")).toBe("20");
expect(request.request.params.get("evaluation")).toBe("not_evaluated");
request.flush({ count: 0, results: [], case_options: ["Экология"], is_competitive: true });
});
it("выгрузка участников передаёт те же фильтры региона и периода, что и список", () => {
Expand Down Expand Up @@ -89,6 +91,43 @@ describe("Контракт HTTP панели организатора", () => {
});
request.flush({ updated_at: version });
});
it("выбор всех проектов использует те же фильтры и сохраняет оба вида ID", () => {
adapter
.selection(4, "projects", {
search: "Город",
offset: 20,
limit: 20,
submission: "submitted",
caseScope: "selected",
caseName: "Экология",
evaluation: "not_evaluated",
})
.subscribe(result => expect(result.projects?.[0].projectId).toBe(91));
const request = http.expectOne(r => r.url.endsWith("/projects/selection/"));
expect(request.request.params.get("evaluation")).toBe("not_evaluated");
expect(request.request.params.get("case_name")).toBe("Экология");
request.flush({ ids: [11], projects: [{ id: 11, project_id: 91 }] });
});
it("выбранная выгрузка использует POST Blob, удаление передает подписанное подтверждение без retry", () => {
adapter.exportSelectedParticipants(4, [1, 21]).subscribe();
const file = http.expectOne(r => r.url.endsWith("/participants/export/"));
expect(file.request.method).toBe("POST");
expect(file.request.body).toEqual({ ids: [1, 21] });
expect(file.request.responseType).toBe("blob");
file.flush(new Blob(["xlsx"]));
adapter
.previewParticipantRemoval(4, [1, 21])
.subscribe(result => expect(result.previewToken).toBe("proof"));
const preview = http.expectOne(r => r.url.endsWith("/remove-preview/"));
preview.flush({ preview_token: "proof", participant_count: 2, applications: [] });
const failed = vi.fn();
adapter.removeParticipants(4, [1, 21], "proof").subscribe({ error: failed });
const removal = http.expectOne(r => r.url.endsWith("/participants/remove/"));
expect(removal.request.body).toEqual({ ids: [1, 21], preview_token: "proof" });
removal.flush({ detail: "Изменено" }, { status: 409, statusText: "Conflict" });
expect(failed).toHaveBeenCalledOnce();
http.expectNone(r => r.url.endsWith("/participants/remove/"));
});
it("удаление материала передаёт версию в query и не вызывает удаление UserFile", () => {
adapter
.deleteMaterial(4, { id: 9, updatedAt: "2026-10-17T15:00:00+03:00" } as ManagementMaterial)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import {
ManagementSettingsWrite,
ManagementTeam,
ProgramManagement,
ManagementSelection,
ParticipantRemovalPreview,
} from "@domain/program/program-management.model";

@Injectable()
Expand Down Expand Up @@ -67,6 +69,27 @@ export class ProgramManagementHttpAdapter implements ProgramManagementRepository
exportParticipants(id: number, q: ManagementQuery) {
return this.api.getFile(`${this.root(id)}/participants/export/`, this.participantParams(q));
}
selection(id: number, kind: "participants" | "projects", q: ManagementQuery) {
return this.api.get<ManagementSelection>(
`${this.root(id)}/${kind}/selection/`,
kind === "participants" ? this.participantParams(q) : this.projectParams(q),
);
}
exportSelectedParticipants(id: number, ids: number[]) {
return this.api.postFile(`${this.root(id)}/participants/export/`, { ids });
}
previewParticipantRemoval(id: number, ids: number[]) {
return this.api.post<ParticipantRemovalPreview>(
`${this.root(id)}/participants/remove-preview/`,
{ ids },
);
}
removeParticipants(id: number, ids: number[], previewToken: string) {
return this.api.post<{ removed: number }>(`${this.root(id)}/participants/remove/`, {
ids,
previewToken,
});
}
private participantParams(q: ManagementQuery): HttpParams {
let params = this.params(q)
.set("region_scope", q.regionScope ?? "all")
Expand All @@ -79,9 +102,18 @@ export class ProgramManagementHttpAdapter implements ProgramManagementRepository
return params;
}
projects(id: number, q: ManagementQuery) {
let params = this.params(q).set("submission", q.submission).set("case_scope", q.caseScope);
return this.api.get<ManagementProjectsPage>(
`${this.root(id)}/projects/`,
this.projectParams(q),
);
}
private projectParams(q: ManagementQuery): HttpParams {
let params = this.params(q)
.set("submission", q.submission)
.set("case_scope", q.caseScope)
.set("evaluation", q.evaluation ?? "all");
if (q.caseScope === "selected" && q.caseName) params = params.set("case_name", q.caseName);
return this.api.get<ManagementProjectsPage>(`${this.root(id)}/projects/`, params);
return params;
}
team(id: number, linkId: number) {
return this.api.get<ManagementTeam>(`${this.root(id)}/projects/${linkId}/team/`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
import { inject, Injectable } from "@angular/core";
import { EvaluationHttpAdapter } from "../../adapters/program/evaluation-http.adapter";
import { EvaluationRepositoryPort } from "@domain/program/ports/evaluation.repository.port";
import { ExpertsBulkWrite } from "@domain/program/evaluation-workspace.model";
@Injectable({ providedIn: "root" })
export class EvaluationRepository implements EvaluationRepositoryPort {
private readonly adapter = inject(EvaluationHttpAdapter);
readonly programs = this.adapter.programs.bind(this.adapter);
readonly workspace = this.adapter.workspace.bind(this.adapter);
bulkExperts(id: number, data: ExpertsBulkWrite) {
return this.adapter.bulkExperts(id, data);
}
readonly saveCaseScope = this.adapter.saveCaseScope.bind(this.adapter);
readonly saveInvitationCaseScope = this.adapter.saveInvitationCaseScope.bind(this.adapter);
readonly saveProjectExperts = this.adapter.saveProjectExperts.bind(this.adapter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@ export class ProgramManagementRepository implements ProgramManagementRepositoryP
exportParticipants(id: number, q: ManagementQuery) {
return this.adapter.exportParticipants(id, q);
}
selection(id: number, kind: "participants" | "projects", q: ManagementQuery) {
return this.adapter.selection(id, kind, q);
}
exportSelectedParticipants(id: number, ids: number[]) {
return this.adapter.exportSelectedParticipants(id, ids);
}
previewParticipantRemoval(id: number, ids: number[]) {
return this.adapter.previewParticipantRemoval(id, ids);
}
removeParticipants(id: number, ids: number[], previewToken: string) {
return this.adapter.removeParticipants(id, ids, previewToken).pipe(tap(() => this.changed(id)));
}
projects(id: number, q: ManagementQuery) {
return this.adapter.projects(id, q);
}
Expand Down
Loading