GNXSOFT.COM
This commit is contained in:
334
gnx-react/lib/api/aboutService.ts
Normal file
334
gnx-react/lib/api/aboutService.ts
Normal file
@@ -0,0 +1,334 @@
|
||||
import { API_BASE_URL } from '../config/api';
|
||||
|
||||
// Types for About Us data
|
||||
export interface AboutStat {
|
||||
number: string;
|
||||
label: string;
|
||||
order: number;
|
||||
}
|
||||
|
||||
export interface AboutSocialLink {
|
||||
platform: string;
|
||||
url: string;
|
||||
icon: string;
|
||||
aria_label: string;
|
||||
order: number;
|
||||
}
|
||||
|
||||
export interface AboutBanner {
|
||||
id: number;
|
||||
title: string;
|
||||
subtitle: string;
|
||||
description: string;
|
||||
badge_text: string;
|
||||
badge_icon: string;
|
||||
cta_text: string;
|
||||
cta_link: string;
|
||||
cta_icon: string;
|
||||
image_url: string | null;
|
||||
is_active: boolean;
|
||||
stats: AboutStat[];
|
||||
social_links: AboutSocialLink[];
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
}
|
||||
|
||||
export interface AboutFeature {
|
||||
title: string;
|
||||
description: string;
|
||||
icon: string;
|
||||
order: number;
|
||||
}
|
||||
|
||||
export interface AboutService {
|
||||
id: number;
|
||||
title: string;
|
||||
subtitle: string;
|
||||
description: string;
|
||||
badge_text: string;
|
||||
badge_icon: string;
|
||||
image_url: string | null;
|
||||
cta_text: string;
|
||||
cta_link: string;
|
||||
is_active: boolean;
|
||||
features: AboutFeature[];
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
}
|
||||
|
||||
export interface AboutProcessStep {
|
||||
step_number: string;
|
||||
title: string;
|
||||
description: string;
|
||||
order: number;
|
||||
}
|
||||
|
||||
export interface AboutProcess {
|
||||
id: number;
|
||||
title: string;
|
||||
subtitle: string;
|
||||
description: string;
|
||||
badge_text: string;
|
||||
badge_icon: string;
|
||||
image_url: string | null;
|
||||
cta_text: string;
|
||||
cta_link: string;
|
||||
is_active: boolean;
|
||||
steps: AboutProcessStep[];
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
}
|
||||
|
||||
export interface AboutMilestone {
|
||||
year: string;
|
||||
title: string;
|
||||
description: string;
|
||||
order: number;
|
||||
}
|
||||
|
||||
export interface AboutJourney {
|
||||
id: number;
|
||||
title: string;
|
||||
subtitle: string;
|
||||
description: string;
|
||||
badge_text: string;
|
||||
badge_icon: string;
|
||||
image_url: string | null;
|
||||
cta_text: string;
|
||||
cta_link: string;
|
||||
is_active: boolean;
|
||||
milestones: AboutMilestone[];
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
}
|
||||
|
||||
export interface AboutPageData {
|
||||
banner: AboutBanner;
|
||||
service: AboutService;
|
||||
process: AboutProcess;
|
||||
journey: AboutJourney;
|
||||
}
|
||||
|
||||
class AboutService {
|
||||
private baseUrl = `${API_BASE_URL}/api/about`;
|
||||
|
||||
/**
|
||||
* Get all about page data in one request
|
||||
*/
|
||||
async getAboutPageData(): Promise<AboutPageData> {
|
||||
try {
|
||||
const response = await fetch(`${this.baseUrl}/page/`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
return data;
|
||||
} catch (error) {
|
||||
console.error('Error fetching about page data:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all about banners
|
||||
*/
|
||||
async getBanners(): Promise<AboutBanner[]> {
|
||||
try {
|
||||
const response = await fetch(`${this.baseUrl}/banner/`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
return data.results || data;
|
||||
} catch (error) {
|
||||
console.error('Error fetching about banners:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a specific about banner by ID
|
||||
*/
|
||||
async getBanner(id: number): Promise<AboutBanner> {
|
||||
try {
|
||||
const response = await fetch(`${this.baseUrl}/banner/${id}/`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
return data;
|
||||
} catch (error) {
|
||||
console.error(`Error fetching about banner ${id}:`, error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all about services
|
||||
*/
|
||||
async getServices(): Promise<AboutService[]> {
|
||||
try {
|
||||
const response = await fetch(`${this.baseUrl}/service/`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
return data.results || data;
|
||||
} catch (error) {
|
||||
console.error('Error fetching about services:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a specific about service by ID
|
||||
*/
|
||||
async getService(id: number): Promise<AboutService> {
|
||||
try {
|
||||
const response = await fetch(`${this.baseUrl}/service/${id}/`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
return data;
|
||||
} catch (error) {
|
||||
console.error(`Error fetching about service ${id}:`, error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all about processes
|
||||
*/
|
||||
async getProcesses(): Promise<AboutProcess[]> {
|
||||
try {
|
||||
const response = await fetch(`${this.baseUrl}/process/`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
return data.results || data;
|
||||
} catch (error) {
|
||||
console.error('Error fetching about processes:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a specific about process by ID
|
||||
*/
|
||||
async getProcess(id: number): Promise<AboutProcess> {
|
||||
try {
|
||||
const response = await fetch(`${this.baseUrl}/process/${id}/`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
return data;
|
||||
} catch (error) {
|
||||
console.error(`Error fetching about process ${id}:`, error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all about journeys
|
||||
*/
|
||||
async getJourneys(): Promise<AboutJourney[]> {
|
||||
try {
|
||||
const response = await fetch(`${this.baseUrl}/journey/`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
return data.results || data;
|
||||
} catch (error) {
|
||||
console.error('Error fetching about journeys:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a specific about journey by ID
|
||||
*/
|
||||
async getJourney(id: number): Promise<AboutJourney> {
|
||||
try {
|
||||
const response = await fetch(`${this.baseUrl}/journey/${id}/`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
return data;
|
||||
} catch (error) {
|
||||
console.error(`Error fetching about journey ${id}:`, error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Export a singleton instance
|
||||
export const aboutService = new AboutService();
|
||||
export default aboutService;
|
||||
Reference in New Issue
Block a user