// post.model.ts
export interface Blog {
  id?: number;
  title: string;
  content: string;
  professors: { id: number, name: string }[];  // Adjust this as per your entity structure
  tags: string[];
  isPosted: boolean;
}


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


@Injectable({
  providedIn: 'root'
})
export class BlogService {
  private apiUrl = environment.apiUrl+'/api/posts'; // Updated to match the Spring Boot controller

  constructor(private http: HttpClient) {}

  // Get all blogs
  getBlogs(): Observable<Blog[]> {
    return this.http.get<Blog[]>(this.apiUrl);
  }

  // Get a single blog by ID
  getBlog(id: number): Observable<Blog> {
    return this.http.get<Blog>(`${this.apiUrl}/${id}`);
  }

  // Create a new blog
  createBlog(blog: Blog): Observable<Blog> {
    return this.http.post<Blog>(this.apiUrl, blog);
  }

  // Update an existing blog
  updateBlog(id: number, blog: Blog): Observable<Blog> {
    return this.http.put<Blog>(`${this.apiUrl}/${id}`, blog);
  }

  // Delete a blog
  deleteBlog(id: number): Observable<void> {
    return this.http.delete<void>(`${this.apiUrl}/${id}`);
  }
}
