You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

82 line
2.4 KiB

  1. import { Injectable } from '@angular/core';
  2. import { HttpClient, HttpHeaders } from '@angular/common/http';
  3. @Injectable({
  4. providedIn: 'root'
  5. })
  6. export class UserService {
  7. BASE_URL: string = 'https://fan-engagement.techmahindra.com';
  8. // /like-article/:id
  9. // /bookmark-article/:id
  10. constructor(
  11. private http: HttpClient
  12. ) { }
  13. likePost(postId: string) {
  14. const httpOptions = {
  15. headers: new HttpHeaders({
  16. 'Access-Control-Allow-Origin': '*',
  17. 'Content-Type': 'application/json',
  18. 'Authorization': 'Bearer ' + JSON.parse(localStorage.getItem('FBToken')).token
  19. })
  20. };
  21. return this.http.get(this.BASE_URL + '/like-article/' + postId, httpOptions).toPromise();
  22. }
  23. dislikePost(postId: string) {
  24. const httpOptions = {
  25. headers: new HttpHeaders({
  26. 'Access-Control-Allow-Origin': '*',
  27. 'Content-Type': 'application/json',
  28. 'Authorization': 'Bearer ' + JSON.parse(localStorage.getItem('FBToken')).token
  29. })
  30. };
  31. return this.http.get(this.BASE_URL + '/unlike-article/' + postId, httpOptions).toPromise();
  32. }
  33. BookmarkPost(postId: string) {
  34. const httpOptions = {
  35. headers: new HttpHeaders({
  36. 'Access-Control-Allow-Origin': '*',
  37. 'Content-Type': 'application/json',
  38. 'Authorization': 'Bearer ' + JSON.parse(localStorage.getItem('FBToken')).token
  39. })
  40. };
  41. return this.http.get(this.BASE_URL + '/bookmark-article/' + postId, httpOptions).toPromise();
  42. }
  43. UnBookmarkPost(postId: string) {
  44. const httpOptions = {
  45. headers: new HttpHeaders({
  46. 'Access-Control-Allow-Origin': '*',
  47. 'Content-Type': 'application/json',
  48. 'Authorization': 'Bearer ' + JSON.parse(localStorage.getItem('FBToken')).token
  49. })
  50. };
  51. return this.http.get(this.BASE_URL + '/unbookmark-article/' + postId, httpOptions).toPromise();
  52. }
  53. getUserProfile() {
  54. if (localStorage.getItem('FBToken')) {
  55. const httpOptions = {
  56. headers: new HttpHeaders({
  57. 'Access-Control-Allow-Origin': '*',
  58. 'Content-Type': 'application/json',
  59. 'Authorization': 'Bearer ' + JSON.parse(localStorage.getItem('FBToken')).token
  60. })
  61. };
  62. return this.http.get(this.BASE_URL + '/user-details/', httpOptions).toPromise();
  63. } else {
  64. return Promise.reject(null);
  65. }
  66. }
  67. }