import { Injectable } from '@angular/core'; import { Work } from '../models/work.model'; import { HttpClient } from '@angular/common/http'; import { Observable } from 'rxjs'; import { NgForm } from '@angular/forms'; @Injectable({ providedIn: 'root', }) export class WorkService { API_URL = 'http://127.0.0.1:3000'; private works: Work[] = []; constructor(private http: HttpClient) {} getWorks(): Observable { return this.http.get(`${this.API_URL}/works`); } getWorkByLink(link: string): Observable { return this.http.get(`${this.API_URL}/works/${link}`); } saveWork(form: NgForm): void { const code = form.value.content; this.http.post(`${this.API_URL}/works/save`, code).subscribe(); } postWork(code: string, language: string, id_user: number): string { let body = { id_user: id_user, // tant que ça pas résolu -> je peux pas faire le share link: crypto.randomUUID(), language: language, title: `Basic ${language}`, code: code, }; this.http.post(`${this.API_URL}/works`, body).subscribe(); return body.link; } updateWork(id: string, code: string, language: string): void { let body = { newContent: code, language: language, }; this.http.put(`${this.API_URL}/works/${id}/content`, body).subscribe(); } }