# All files / app/common/services api.service.ts

100% Statements 11/11
100% Branches 0/0
100% Functions 4/4
100% Lines 10/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    1073x
    3x

    3x

    3x

    4x

    4x

    4x

    1x

    1x

    1x

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

    // API Response Interfaces
    export interface CardData {
      button_label: string;
      button_url: string;
      is_most_popular: boolean;
      card_fee_label: string;
      card_fee_amount: string;
      credit_limit_label: string;
      limit_text: string;
    }

    export interface CardPost {
      id: number;
      title: string;
      description: string;
      excerpt: string;
      tags: string[];
      categories: string[];
      featured_image: string;
      card_features: string;
      card_data: CardData;
    }

    export interface CardsApiResponse {
      category_id: number;
      category_name: string;
      category_slug: string;
      posts: CardPost[];
    }

    // Slider/Banner API Response Interfaces (reuses CardData and similar structure)
    export interface SliderPost {
      id: number;
      title: string;
      description: string;
      excerpt: string;
      tags: string[];
      categories: string[];
      featured_image: string;
      featured_image2: string; // New field
      card_features: string;
      banner_label1_text_box: string; // New field
      banner_label2_text_box: string; // New field
      card_data: CardData;
    }

    export interface SliderApiResponse {
      category_id: number;
      category_name: string;
      category_slug: string;
      posts: SliderPost[];
    }

    // Offer Text API Response Interfaces (reuses CardData structure)
    export interface OfferTextPost {
      id: number;
      title: string;
      description: string;
      excerpt: string;
      tags: string[];
      categories: string[];
      featured_image: string | false;
      card_features: string;
      card_data: CardData;
    }

    export interface OfferTextApiResponse {
      category_id: number;
      category_name: string;
      category_slug: string;
      posts: OfferTextPost[];
    }

    @Injectable({
      providedIn: 'root'
    })
    export class ApiService {

      private readonly baseUrl = environment.apiUrl;

      private readonly headers = new HttpHeaders({
        'x-api-key': environment.apiKey
      });

      constructor(private http: HttpClient) { }

      // ✅ Slider API
      getSlider(): Observable<SliderApiResponse[]> {
        return this.http.post<SliderApiResponse[]>(`${this.baseUrl}/slider`, {}, { headers: this.headers });
      }

      // ✅ Offer Text API
      getOfferText(): Observable<OfferTextApiResponse[]> {
        return this.http.post<OfferTextApiResponse[]>(`${this.baseUrl}/offer-text`, {}, { headers: this.headers });
      }

      // ✅ Cards API
      getCards(): Observable<CardsApiResponse[]> {
        return this.http.post<CardsApiResponse[]>(`${this.baseUrl}/cards`, {}, { headers: this.headers });
      }
    }