Create mobile-shopping app
This commit is contained in:
51
mobile-shopping/src/services/ShoppingService.js
Normal file
51
mobile-shopping/src/services/ShoppingService.js
Normal file
@@ -0,0 +1,51 @@
|
||||
import requestUtil from '../utils/RequestUtil';
|
||||
|
||||
class ShoppingService {
|
||||
constructor() {
|
||||
this.endpoint = '/api/shopping';
|
||||
}
|
||||
|
||||
// Get all shopping items
|
||||
async getItems() {
|
||||
return requestUtil.get(this.endpoint);
|
||||
}
|
||||
|
||||
// Get a specific shopping item
|
||||
async getItem(id) {
|
||||
return requestUtil.get(`${this.endpoint}/${id}`);
|
||||
}
|
||||
|
||||
// Create a new shopping item
|
||||
async createItem(item) {
|
||||
return requestUtil.post(this.endpoint, item);
|
||||
}
|
||||
|
||||
// Update a shopping item
|
||||
async updateItem(id, item) {
|
||||
return requestUtil.put(`${this.endpoint}/${id}`, item);
|
||||
}
|
||||
|
||||
// Toggle checked status of an item
|
||||
async toggleItem(id) {
|
||||
return requestUtil.patch(`${this.endpoint}/${id}/toggle`);
|
||||
}
|
||||
|
||||
// Delete a shopping item
|
||||
async deleteItem(id) {
|
||||
return requestUtil.delete(`${this.endpoint}/${id}`);
|
||||
}
|
||||
|
||||
// Delete all checked items
|
||||
async deleteCheckedItems() {
|
||||
return requestUtil.delete(`${this.endpoint}/checked/all`);
|
||||
}
|
||||
|
||||
// Health check
|
||||
async healthCheck() {
|
||||
return requestUtil.get('/api/health');
|
||||
}
|
||||
}
|
||||
|
||||
// Create and export a singleton instance
|
||||
const shoppingService = new ShoppingService();
|
||||
export default shoppingService;
|
Reference in New Issue
Block a user