import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { Post, Category } from '../../core/entities';

@Injectable()
export class ByCategoryService {

	constructor(private http: HttpClient) {}

	getCategoryById(categoryId: number): Observable<Category> {
		return this.http.get<Category>(`/api/categories/${categoryId}`);
	}

	getPostsByCategory(category: Category): Observable<Array<Post>> {
		return this.http.get<Array<Post>>(`/api/posts/byCategory/${category.id}`);
	}
}
