import { Injectable } from '@angular/core' ; import { HttpClient } from '@angular/common/http' ; import { Post } from '../../shared/models/post.model' ; import { Observable } from 'rxjs/internal/Observable' ; @ Injectable ( ) export class PostService { constructor ( private http ) { } getPosts ( page = null ) { return this . http . get < Post [ ] > ( `/api/posts?page=${ page == null ? 1 : page }` ) ; } getPostById ( _id ) { return this . http . get < Post > ( `/api/post/${ _id }` ) ; } countPosts ( ) { return this . http . get < number > ( '/api/posts/count' ) ; } addPost ( post ) { return this . http . post < Post > ( '/api/post' , post ) ; } getPost ( post ) { return this . http . get < Post > ( `/api/post/${ post . _id }` ) ; } editPost ( post ) { return this . http . put ( `/api/post/${ post . _id }` , post , { responseType : 'text' } ) ; } deletePost ( post ) { return this . http . delete ( `/api/post/${ post . _id }` , { responseType : 'text' } ) ; } }