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

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

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

@Injectable()
export class SearchService {

	constructor(private http: HttpClient) {}

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