add project
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
import { GlobalConstants } from '../global-constants';
|
||||
import { webSocket, WebSocketSubject } from 'rxjs/webSocket';
|
||||
|
||||
// Унифицируем название интерфейса для списка контейнеров
|
||||
export interface DockerContainer {
|
||||
id: string;
|
||||
name: string;
|
||||
image: string;
|
||||
state: string; // running, exited, etc.
|
||||
status: string; // Up 2 hours, etc.
|
||||
}
|
||||
|
||||
// Интерфейс Project в соответствии с Project.java[cite: 3]
|
||||
export interface Project {
|
||||
id: string;
|
||||
name: string;
|
||||
user?: any; // Соответствует полю private User user в Java[cite: 3]
|
||||
status: string;
|
||||
localPath: string;
|
||||
createdAt: Date;
|
||||
containers?: DockerContainer[];
|
||||
}
|
||||
|
||||
export interface ProjectCreateRequest {
|
||||
name: string;
|
||||
rawComposeContent: string;
|
||||
}
|
||||
|
||||
export interface ProjectDetailResponse {
|
||||
project: Project;
|
||||
config: {
|
||||
projectId: string;
|
||||
rawComposeContent: string;
|
||||
envVariables: { [key: string]: string };
|
||||
};
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class ProjectService {
|
||||
// Используем baseUrl, как определено в начале класса
|
||||
private baseUrl = GlobalConstants.API_URL;
|
||||
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
// Создание нового проекта[cite: 4, 5]
|
||||
createProject(request: ProjectCreateRequest): Observable<Project> {
|
||||
return this.http.post<Project>(`${this.baseUrl}/user/projects`, request);
|
||||
}
|
||||
|
||||
// Методы для Dashboard[cite: 4, 5]
|
||||
getUserProjects(): Observable<Project[]> {
|
||||
return this.http.get<Project[]>(`${this.baseUrl}/user/projects`);
|
||||
}
|
||||
|
||||
getProjectDetails(id: string): Observable<ProjectDetailResponse> {
|
||||
return this.http.get<ProjectDetailResponse>(`${this.baseUrl}/user/projects/${id}/details`);
|
||||
}
|
||||
|
||||
// Управление жизненным циклом (Docker Compose)[cite: 3, 4]
|
||||
deployProject(id: string): Observable<string> {
|
||||
return this.http.post(`${this.baseUrl}/user/projects/${id}/deploy`, {}, { responseType: 'text' });
|
||||
}
|
||||
|
||||
stopProject(id: string): Observable<string> {
|
||||
return this.http.post(`${this.baseUrl}/user/projects/${id}/stop`, {}, { responseType: 'text' });
|
||||
}
|
||||
|
||||
deleteProject(id: string): Observable<any> {
|
||||
return this.http.delete(`${this.baseUrl}/user/projects/${id}`);
|
||||
}
|
||||
|
||||
// Администрирование[cite: 4]
|
||||
getAllProjectsAdmin(): Observable<Project[]> {
|
||||
return this.http.get<Project[]>(`${this.baseUrl}/admin/projects/all`);
|
||||
}
|
||||
|
||||
// WebSocket для трансляции логов в реальном времени[cite: 3, 5]
|
||||
public connectToDockerLogs(projectId: string): WebSocketSubject<any> {
|
||||
const socketUrl = this.baseUrl.replace('http', 'ws') + '/ws-jambotron/' + projectId;
|
||||
return webSocket({
|
||||
url: socketUrl,
|
||||
deserializer: (msg) => msg.data
|
||||
});
|
||||
}
|
||||
|
||||
// ИСПРАВЛЕНО: возвращаем DockerContainer и используем правильный baseUrl[cite: 5]
|
||||
getProjectContainers(projectId: string): Observable<DockerContainer[]> {
|
||||
return this.http.get<DockerContainer[]>(`${this.baseUrl}/user/projects/${projectId}/containers`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user