// 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;
  posted: boolean;
  professors : Professor[];
}


export interface Professor {
  id: number;
  professorId: string;
  firstName: string;
  lastName: string;
  email: string;
  department: string;
  position: string;
  officeLocation: string;
  joinDate: Date | null;
  profileImageUrl: string;
  status: 'ACTIVE' | 'INACTIVE'; // assuming status has fixed values like 'ACTIVE' or 'INACTIVE'
}



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 all blogs
  getPostedBlogs(): Observable<Blog[]> {
    return this.http.get<Blog[]>(this.apiUrl+"/posted");
  }

  // 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}`);
  }
}
