import { Injectable } from '@angular/core'; import {Auth} from "../Interfaces/auth.interface"; import {HttpClient, HttpHeaders} from "@angular/common/http"; import {BehaviorSubject, Observable, Subject} from "rxjs"; import {Task} from "../Interfaces/task.interface"; const httpOptionAuth: {headers: HttpHeaders} = { headers: new HttpHeaders({ Accept: "application/vnd.api+json", "Content-Type": "application/vnd.api+json" }), }; const httpOptionBearer: {headers: HttpHeaders} = { headers: new HttpHeaders({ Authorization: `Bearer ${localStorage.getItem("token")}`, Accept: "application/vnd.api+json", "Content-Type": "application/vnd.api+json" }), }; @Injectable({ providedIn: 'root' }) export class ApiService { hasLoggedInSub: BehaviorSubject = new BehaviorSubject(false) constructor(private http: HttpClient) { } adminLogin(creds: Auth): Observable{ return this.http.post("https://lucky-tasks.vercel.app/api/v1/login", creds, httpOptionAuth) } setLoggedInSubj(value: boolean): void{ this.hasLoggedInSub.next(value) } getAllCards(): Observable{ return this.http.get("https://lucky-tasks.vercel.app/api/v1/cards", { headers: new HttpHeaders({ Authorization: `Bearer ${localStorage.getItem("token")}`, Accept: "application/vnd.api+json", "Content-Type": "application/vnd.api+json" }), }) } storeCard(data: Task): Observable{ return this.http.post("https://lucky-tasks.vercel.app/api/v1/cards", data, httpOptionBearer) } deleteCard(index: number): Observable{ return this.http.delete(`https://lucky-tasks.vercel.app/api/v1/cards/${index}`, httpOptionBearer) } getOneCard(index: number): Observable{ return this.http.get(`https://lucky-tasks.vercel.app/api/v1/cards/${index}`, httpOptionBearer) } editCard(index: number, card: Task): Observable{ return this.http.patch(`https://lucky-tasks.vercel.app/api/v1/cards/${index}`, card, httpOptionBearer) } getTodaysTasks(): Observable{ return this.http.get(`https://lucky-tasks.vercel.app/api/v1/cards/today`, httpOptionAuth) } }