- Shared types : ajout isCurrent sur ApiEntry et ApiEntryListItem - Backend entity : colonne is_current (boolean, default true) - Backend service : isCurrent calculé à la création, setCurrent() marque une version comme courante (siblings → false) - Backend controller : POST /api/apis/:id/set-current - Frontend ApiService : méthode setCurrent() - Browse/upload : affichage badge "Courante" via isCurrent - Seeder : données de démo mises à jour - Documentation : api-reference, architecture, local-setup, CLAUDE.md Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Happy <yesreply@happy.engineering>
88 lines
2.8 KiB
TypeScript
88 lines
2.8 KiB
TypeScript
import { Injectable, inject } from '@angular/core';
|
|
import { HttpClient } from '@angular/common/http';
|
|
import { Observable } from 'rxjs';
|
|
import { ApiEntry, ApiEntryListItem, ApiListResponse, ApiListQuery } from '@datacat/shared';
|
|
|
|
@Injectable({ providedIn: 'root' })
|
|
export class ApiService {
|
|
private http = inject(HttpClient);
|
|
private baseUrl = '/api/apis';
|
|
|
|
list(query?: ApiListQuery): Observable<ApiListResponse> {
|
|
const params: Record<string, string> = {};
|
|
if (query?.search) params['search'] = query.search;
|
|
if (query?.type) params['type'] = query.type;
|
|
if (query?.categoryId) params['categoryId'] = query.categoryId;
|
|
if (query?.page) params['page'] = String(query.page);
|
|
if (query?.limit) params['limit'] = String(query.limit);
|
|
return this.http.get<ApiListResponse>(this.baseUrl, { params });
|
|
}
|
|
|
|
get(id: string): Observable<ApiEntry> {
|
|
return this.http.get<ApiEntry>(`${this.baseUrl}/${id}`);
|
|
}
|
|
|
|
update(id: string, data: {
|
|
convention?: string;
|
|
name?: string;
|
|
provider?: string;
|
|
versionMajor?: number;
|
|
versionMinor?: number;
|
|
versionPatch?: number;
|
|
description?: string | null;
|
|
categoryId?: string | null;
|
|
contactFunctionalName?: string;
|
|
contactFunctionalEntity?: string;
|
|
contactFunctionalEmail?: string;
|
|
contactTechnicalName?: string;
|
|
contactTechnicalEntity?: string;
|
|
contactTechnicalEmail?: string;
|
|
}): Observable<ApiEntry> {
|
|
return this.http.patch<ApiEntry>(`${this.baseUrl}/${id}`, data);
|
|
}
|
|
|
|
delete(id: string): Observable<void> {
|
|
return this.http.delete<void>(`${this.baseUrl}/${id}`);
|
|
}
|
|
|
|
getVersions(id: string): Observable<ApiEntryListItem[]> {
|
|
return this.http.get<ApiEntryListItem[]>(`${this.baseUrl}/${id}/versions`);
|
|
}
|
|
|
|
setCurrent(id: string): Observable<ApiEntry> {
|
|
return this.http.post<ApiEntry>(`${this.baseUrl}/${id}/set-current`, {});
|
|
}
|
|
|
|
regenerate(id: string): Observable<ApiEntry> {
|
|
return this.http.post<ApiEntry>(`${this.baseUrl}/${id}/regenerate`, {});
|
|
}
|
|
|
|
upload(formData: FormData): Observable<ApiEntry> {
|
|
return this.http.post<ApiEntry>('/api/uploads', formData);
|
|
}
|
|
|
|
validate(formData: FormData): Observable<{
|
|
valid: boolean;
|
|
type: 'ASYNCAPI' | 'OPENAPI' | null;
|
|
mainFile: string | null;
|
|
name: string | null;
|
|
versionMajor: number | null;
|
|
versionMinor: number | null;
|
|
versionPatch: number | null;
|
|
description: string | null;
|
|
errors: Array<{ file: string; message: string }>;
|
|
}> {
|
|
return this.http.post<{
|
|
valid: boolean;
|
|
type: 'ASYNCAPI' | 'OPENAPI' | null;
|
|
mainFile: string | null;
|
|
name: string | null;
|
|
versionMajor: number | null;
|
|
versionMinor: number | null;
|
|
versionPatch: number | null;
|
|
description: string | null;
|
|
errors: Array<{ file: string; message: string }>;
|
|
}>('/api/uploads/validate', formData);
|
|
}
|
|
}
|