import { Injectable } from '@angular/core' ; import { HttpClient } from '@angular/common/http' ; import { Tag } from '../../shared/models/tag.model' ; import { Post } from '../../shared/models/post.model' ; import { Observable } from 'rxjs/internal/Observable' ; @ Injectable ( ) export class TagService { constructor ( private http ) { } getTags ( term = null ) { return this . http . get < Tag [ ] > ( `/api/tags?q=${ term == null ? '' : term }` ) ; } getTagById ( _id ) { return this . http . get < Tag > ( `/api/tag/${ _id }` ) ; } countTags ( ) { return this . http . get < number > ( '/api/tags/count' ) ; } addTag ( tag ) { return this . http . post < Tag > ( '/api/tag' , tag ) ; } getTag ( tag ) { return this . http . get < Tag > ( `/api/tag/${ tag . _id }` ) ; } editTag ( tag ) { return this . http . put ( `/api/tag/${ tag . _id }` , tag , { responseType : 'text' , } ) ; } deleteTag ( tag ) { return this . http . delete ( `/api/tag/${ tag . _id }` , { responseType : 'text' , } ) ; } getTagPosts ( _id , page ) { return this . http . get < Post > ( `/api/tag/${ _id }/posts?page=${ page == null ? 1 : page }` ) ; } }