import { Injectable } from '@angular/core'; import {Observable} from 'rxjs'; import {Post} from '../models/post'; import {HttpClient, HttpHeaders} from '@angular/common/http'; @Injectable({ providedIn: 'root' }) export class PostService { url: string = 'http://localhost:8080/api/posts'; constructor(private httpClient: HttpClient) {} list(): Observable { return this.httpClient.get(this.url); } createPost(post: any, token: string | undefined): Observable { const httpOptions = { headers: new HttpHeaders({ 'Authorization': `Bearer ${token}` }) }; return this.httpClient.post(this.url, post, httpOptions); } changeIllustration(id: bigint, image: File | undefined, token: string): Observable { const httpOptions = { headers: new HttpHeaders({ 'Authorization': `Bearer ${token}` }) }; return this.httpClient.put(`${this.url}/${id}`, image, httpOptions); } }