import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { HttpClient } from '@angular/common/http';

import { environment } from '../../environments/environment';
import { Post } from '../core/entities';

const POSTS_URL = environment.apiUrl + '/api/posts';

@Injectable()
export class PostService {

	constructor(private http: HttpClient) {}

	getPost(postKey: string): Observable<Post> {
		return this.http.get<Post>(`${POSTS_URL}/${postKey}`);
	}

	deletePost(postToDelete: Post): Observable<any> {
		return this.http.delete(`${POSTS_URL}/${postToDelete.key}`);
	}
}
