|
| 1 | +import axios from 'axios'; |
| 2 | +import { ENDPOINTS } from '~/utils/URL'; |
| 3 | + |
| 4 | +/** |
| 5 | + * Fetch events with optional filtering |
| 6 | + * @param {Object} params - Query parameters |
| 7 | + * @param {string} params.type - Filter by event type |
| 8 | + * @param {string} params.location - Filter by location |
| 9 | + * @param {number} params.page - Page number |
| 10 | + * @param {number} params.limit - Items per page |
| 11 | + * @param {string} params.sortBy - Sort field |
| 12 | + * @returns {Promise} API response |
| 13 | + */ |
| 14 | +export async function getEvents(params = {}) { |
| 15 | + try { |
| 16 | + const { type = '', location = '', page = 1, limit = 9, sortBy = 'date' } = params; |
| 17 | + const queryParams = new URLSearchParams(); |
| 18 | + if (type) queryParams.append('type', type); |
| 19 | + if (location) queryParams.append('location', location); |
| 20 | + queryParams.append('page', page); |
| 21 | + queryParams.append('limit', limit); |
| 22 | + queryParams.append('sortBy', sortBy); |
| 23 | + |
| 24 | + const url = `${ENDPOINTS.EVENTS}?${queryParams.toString()}`; |
| 25 | + const response = await axios.get(url); |
| 26 | + return Promise.resolve(response); |
| 27 | + } catch (error) { |
| 28 | + return { |
| 29 | + message: error.response?.data?.error || error.message, |
| 30 | + errorCode: error.response?.status, |
| 31 | + status: error.response?.status || 500, |
| 32 | + }; |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +/** |
| 37 | + * Fetch available event types |
| 38 | + * @returns {Promise} API response |
| 39 | + */ |
| 40 | +export async function getEventTypes() { |
| 41 | + try { |
| 42 | + const url = ENDPOINTS.EVENT_TYPES; |
| 43 | + const response = await axios.get(url); |
| 44 | + return Promise.resolve(response); |
| 45 | + } catch (error) { |
| 46 | + return { |
| 47 | + message: error.response?.data?.error || error.message, |
| 48 | + errorCode: error.response?.status, |
| 49 | + status: error.response?.status || 500, |
| 50 | + }; |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +/** |
| 55 | + * Fetch available event locations |
| 56 | + * @returns {Promise} API response |
| 57 | + */ |
| 58 | +export async function getEventLocations() { |
| 59 | + try { |
| 60 | + const url = ENDPOINTS.EVENT_LOCATIONS; |
| 61 | + const response = await axios.get(url); |
| 62 | + return Promise.resolve(response); |
| 63 | + } catch (error) { |
| 64 | + return { |
| 65 | + message: error.response?.data?.error || error.message, |
| 66 | + errorCode: error.response?.status, |
| 67 | + status: error.response?.status || 500, |
| 68 | + }; |
| 69 | + } |
| 70 | +} |
0 commit comments