-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b53b921
commit afee238
Showing
5 changed files
with
178 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import axios from 'axios'; | ||
|
||
export default class VendorsRepository { | ||
constructor(baseUrl) { | ||
this.baseUrl = baseUrl; | ||
} | ||
|
||
async getAllVendors() { | ||
try { | ||
const response = await axios.get(`${this.baseUrl}/vendors`); | ||
return response.data; | ||
} catch (error) { | ||
console.error('Error fetching vendors:', error); | ||
throw error; | ||
} | ||
} | ||
|
||
async getVendorById(vendorId) { | ||
try { | ||
const response = await axios.get(`${this.baseUrl}/vendors/${vendorId}`); | ||
return response.data; | ||
} catch (error) { | ||
console.error(`Error fetching vendor with ID ${vendorId}:`, error); | ||
throw error; | ||
} | ||
} | ||
|
||
async authenticateVendor(vendorData) { | ||
try { | ||
const response = await axios.post(`${this.baseUrl}/vendors/login`, vendorData); | ||
return response.data; | ||
} catch (error) { | ||
console.error('Error logging in vendor:', error); | ||
throw error; | ||
} | ||
} | ||
|
||
async createVendor(vendorData) { | ||
try { | ||
const response = await axios.post(`${this.baseUrl}/vendors`, vendorData); | ||
return response.data; | ||
} catch (error) { | ||
console.error('Error creating vendor:', error); | ||
throw error; | ||
} | ||
} | ||
|
||
async updateVendor(vendorId, vendorData) { | ||
try { | ||
const response = await axios.put(`${this.baseUrl}/vendors/${vendorId}`, vendorData); | ||
return response.data; | ||
} catch (error) { | ||
console.error(`Error updating vendor with ID ${vendorId}:`, error); | ||
throw error; | ||
} | ||
} | ||
|
||
async deleteVendor(vendorId) { | ||
try { | ||
const response = await axios.delete(`${this.baseUrl}/vendors/${vendorId}`); | ||
return response.data; | ||
} catch (error) { | ||
console.error(`Error deleting vendor with ID ${vendorId}:`, error); | ||
throw error; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import VendorsRepository from './VendorsRepository'; | ||
import Vendor from '../../objects/Vendor'; | ||
|
||
export default class VendorsService { | ||
constructor(baseUrl) { | ||
this.vendorsRepository = new VendorsRepository(baseUrl); | ||
} | ||
|
||
async getVendors() { | ||
const vendorsData = await this.vendorsRepository.getAllVendors(); | ||
return vendorsData.map((data) => new Vendor( | ||
data.vendorId, | ||
data.name, | ||
data.email, | ||
data.website, | ||
data.phoneNumber, | ||
data.image, | ||
)); | ||
} | ||
|
||
async getVendorById(vendorId) { | ||
const vendorData = await this.vendorsRepository.getVendorById(vendorId); | ||
return new Vendor( | ||
vendorData.vendorId, | ||
vendorData.name, | ||
vendorData.email, | ||
vendorData.website, | ||
vendorData.phoneNumber, | ||
vendorData.image, | ||
); | ||
} | ||
|
||
async authenticateVendor(vendor) { | ||
const vendorData = { | ||
email: vendor.email, | ||
password: vendor.password, | ||
}; | ||
return await this.vendorsRepository.authenticateVendor(vendorData); | ||
} | ||
|
||
async createVendor(vendor) { | ||
const vendorData = { | ||
name: vendor.name, | ||
email: vendor.email, | ||
password: vendor.password, | ||
website: vendor.website, | ||
phoneNumber: vendor.phoneNumber, | ||
image: vendor.image, | ||
}; | ||
return await this.vendorsRepository.createVendor(vendorData); | ||
} | ||
|
||
async updateVendor(vendor) { | ||
const vendorData = { | ||
name: vendor.name, | ||
email: vendor.email, | ||
website: vendor.website, | ||
phoneNumber: vendor.phoneNumber, | ||
image: vendor.image, | ||
}; | ||
return await this.vendorsRepository.updateVendor(vendor.vendorId, vendorData); | ||
} | ||
|
||
async deleteVendor(vendorId) { | ||
return await this.vendorsRepository.deleteVendor(vendorId); | ||
} | ||
} |