import { Injectable } from '@angular/core'; import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http'; import { environment } from 'src/environments/environment'; import { AuthService } from '../services/auth.service'; import { User } from '../models/user.model'; import { Observable } from 'rxjs'; @Injectable({ providedIn: 'root' }) export class PublicationsService { authheader = {}; loggeduser: User; headers: HttpHeaders; constructor(private http: HttpClient, user: AuthService) { this.loggeduser = user.ValidatedUser; this.headers = new HttpHeaders(); this.headers = this.headers.set('Authorization', this.loggeduser.BasicAuthKey); } GetPublicationFolderList(){ const geturl = environment.apiURL + 'presidentialActions'; let options = { headers: this.headers, }; return this.http.get(`${geturl}`, options); } GetPublicationFolderById(id:any){ const geturl = environment.apiURL + 'presidentialActions/'+id; let options = { headers: this.headers, }; return this.http.get(`${geturl}`, options); } CreatePublicationFolder(body:any){ const geturl = environment.apiURL + 'presidentialActions'; let options = { headers: this.headers, }; return this.http.post(`${geturl}`, body, options).toPromise().then(res =>{ console.log(res); }); } UpdatePublicationFolder(body:any){ const geturl = environment.apiURL + 'presidentialActions'; let options = { headers: this.headers, }; return this.http.put(`${geturl}`, body, options).toPromise().then(res =>{ console.log(res); }); } DeletePublicationFolderById(id:any){ const geturl = environment.apiURL + 'presidentialActions'; let params = new HttpParams(); params = params.set("id", id); let options = { headers: this.headers, params: params }; return this.http.delete(`${geturl}`, options); } GetPublications(id:any){ const geturl = environment.apiURL + 'presidentialActions/'+ id +'/posts'; let params = new HttpParams(); params = params.set("folderId", id); let options = { headers: this.headers, params: params }; return this.http.get(`${geturl}`, options); } GetPublicationById( publicationId:any){ const geturl = environment.apiURL + 'presidentialActions/posts/'+ publicationId; let params = new HttpParams(); /* params = params.set("id", publicationId); */ console.log(params); let options = { headers: this.headers, /* params: params */ }; return this.http.get(`${geturl}`, options); } CreatePublication(folderId:any,body:any){ const geturl = environment.apiURL + 'presidentialActions/'+folderId+'/posts'; let params = new HttpParams(); params = params.set("folderId", folderId); let options = { headers: this.headers, /* params: params */ }; return this.http.post(`${geturl}`, body, options).toPromise().then(res =>{ console.log(res); }); } UpdatePublication(folderId:any,body:any){ const geturl = environment.apiURL + 'presidentialActions/'+folderId+'/posts'; let params = new HttpParams(); params = params.set("folderId", folderId); let options = { headers: this.headers, /* params: params */ }; return this.http.put(`${geturl}`, body, options).toPromise().then(res =>{ console.log(res); }); } DeletePublication(folderId:any,publicationId:any){ const geturl = environment.apiURL + 'presidentialActions/'+folderId+'/posts/'+publicationId; let params = new HttpParams(); params = params.set("folderId", folderId); params = params.set("id", publicationId); let options = { headers: this.headers, /* params: params */ }; return this.http.delete(`${geturl}`, options).toPromise(); } }