36 lines
988 B
TypeScript
36 lines
988 B
TypeScript
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<Post[]> {
|
|
return this.httpClient.get<Post[]>(this.url);
|
|
}
|
|
|
|
createPost(post: any, token: string | undefined): Observable<Post> {
|
|
const httpOptions = {
|
|
headers: new HttpHeaders({
|
|
'Authorization': `Bearer ${token}`
|
|
})
|
|
};
|
|
return this.httpClient.post<Post>(this.url, post, httpOptions);
|
|
}
|
|
|
|
changeIllustration(id: bigint, image: File | undefined, token: string): Observable<Post> {
|
|
const httpOptions = {
|
|
headers: new HttpHeaders({
|
|
'Authorization': `Bearer ${token}`
|
|
})
|
|
};
|
|
return this.httpClient.put<Post>(`${this.url}/${id}`, image, httpOptions);
|
|
}
|
|
|
|
}
|