Skip to content

Commit

Permalink
Merge pull request #93 from Blueprint-Boulder/frontendServicesFix
Browse files Browse the repository at this point in the history
Fixes to Services so that content actually loads from backend.
  • Loading branch information
nh602 authored Feb 28, 2024
2 parents 7eaf3b4 + 2ce9b4c commit 59129bb
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
9 changes: 7 additions & 2 deletions frontend/src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import VendorsService from './services/Vendors/VendorsService.js';
import {handleLoginVendor} from './services/handleLogin.js';
import {handleRegister} from './services/handleRegister.js';

import HttpClient from './services/HttpClient.js';

// Import configuration variables
import config from './config.js';

Expand All @@ -47,9 +49,12 @@ if (config.environment == 'dev') {
// Load base url for the backend
const baseUrl = config.baseUrl;

// Create HttpClient
const httpClient = new HttpClient(baseUrl);

// Initilize Services
const eventsService = new EventsService(baseUrl);
const vendorsService = new VendorsService(baseUrl);
const eventsService = new EventsService(httpClient);
const vendorsService = new VendorsService(httpClient);

eventService = eventsService;
vendorService = vendorsService;
Expand Down
1 change: 0 additions & 1 deletion frontend/src/services/HttpClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ class HttpClient {
constructor(baseURL) {
this.axiosInstance = axios.create({
baseURL: baseURL,
withCredentials: true,
});
this.cookie = '';
}
Expand Down
16 changes: 9 additions & 7 deletions frontend/src/services/Vendors/VendorsRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ export default class VendorsRepository {
const response = await this.httpClient.axiosInstance.get('/vendors');
return response.data;
} catch (error) {
console.error('Error fetching vendors:');
throw error;
console.error('Error fetching vendors');
return undefined;
}
}

Expand All @@ -19,6 +19,7 @@ export default class VendorsRepository {
return response.data;
} catch (error) {
console.error(`Error fetching vendor with ID ${vendorId}:`);
return undefined;
}
}

Expand All @@ -29,6 +30,7 @@ export default class VendorsRepository {
return response;
} catch (error) {
console.error('Error logging in vendor:');
return undefined;
}
}

Expand All @@ -38,7 +40,7 @@ export default class VendorsRepository {
return response.data;
} catch (error) {
console.error('Error creating vendor:');
throw error;
return undefined;
}
}

Expand All @@ -48,7 +50,7 @@ export default class VendorsRepository {
return response.data;
} catch (error) {
console.error('Error updating vendor:');
throw error;
return undefined;
}
}

Expand All @@ -58,7 +60,7 @@ export default class VendorsRepository {
return response.data;
} catch (error) {
console.error(`Error updating vendor with ID ${vendorId}:`);
throw error;
return undefined;
}
}

Expand All @@ -68,7 +70,7 @@ export default class VendorsRepository {
return response.data;
} catch (error) {
console.error(`Error deleting vendor with ID ${vendorId}:`);
throw error;
return undefined;
}
}

Expand All @@ -78,7 +80,7 @@ export default class VendorsRepository {
return response.data;
} catch (error) {
console.error('Error logging out:');
throw error;
return undefined;
}
}
}
4 changes: 4 additions & 0 deletions frontend/src/services/Vendors/VendorsService.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ export default class VendorsService {

async getVendors() {
const vendorsData = await this.vendorsRepository.getAllVendors();
if (vendorsData == undefined) {
return undefined;
}

return vendorsData.map((data) => new Vendor(
data.vendor_id,
data.name,
Expand Down

0 comments on commit 59129bb

Please sign in to comment.