From 35c157a74d1d9fb5d6bf69368fc96a5ef27a95d8 Mon Sep 17 00:00:00 2001 From: Muna Nasher Date: Wed, 11 Mar 2026 20:24:43 +0100 Subject: [PATCH] MunaNsher --- package-lock.json | 4 ++-- task-1/delete.sh | 5 +++++ task-1/get.sh | 5 +++++ task-1/patch.sh | 10 ++++++++++ task-1/post.sh | 12 ++++++++++++ task-2/services.js | 18 +++++++++++++++--- task-2/testServices.js | 13 +++++++++++++ task-2/ui.js | 8 +++++--- 8 files changed, 67 insertions(+), 8 deletions(-) create mode 100644 task-1/delete.sh create mode 100644 task-1/get.sh create mode 100644 task-1/patch.sh create mode 100644 task-1/post.sh create mode 100644 task-2/testServices.js diff --git a/package-lock.json b/package-lock.json index 020596f..837218f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { - "name": "core-assignment-week-10", + "name": "core-assignment-week-9", "version": "1.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "core-assignment-week-10", + "name": "core-assignment-week-9", "version": "1.0.0", "license": "ISC", "dependencies": { diff --git a/task-1/delete.sh b/task-1/delete.sh new file mode 100644 index 0000000..b3f9827 --- /dev/null +++ b/task-1/delete.sh @@ -0,0 +1,5 @@ + +USER_ID=11 + +curl -X DELETE http://localhost:3000/users/$USER_ID \ +-H "Content-Type: application/json" \ No newline at end of file diff --git a/task-1/get.sh b/task-1/get.sh new file mode 100644 index 0000000..e01bdaa --- /dev/null +++ b/task-1/get.sh @@ -0,0 +1,5 @@ + +USER_ID=11 + +curl -X GET http://localhost:3000/users/$USER_ID \ +-H "Content-Type: application/json" \ No newline at end of file diff --git a/task-1/patch.sh b/task-1/patch.sh new file mode 100644 index 0000000..cbaaea4 --- /dev/null +++ b/task-1/patch.sh @@ -0,0 +1,10 @@ + + + +USER_ID=11 + +curl -X PATCH http://localhost:3000/users/$USER_ID \ +-H "Content-Type: application/json" \ +-d '{ + "email": "johndoe@example.com" +}' \ No newline at end of file diff --git a/task-1/post.sh b/task-1/post.sh new file mode 100644 index 0000000..15960ee --- /dev/null +++ b/task-1/post.sh @@ -0,0 +1,12 @@ + +# add new user +curl -X POST http://localhost:3000/users \ +-H "Content-Type: application/json" \ +-d '{ + "name": "John Doe", + "email": "john.doe@example.com", + "password": "secret123", + "role": "user", + "active": true, + "department": "Engineering" +}' \ No newline at end of file diff --git a/task-2/services.js b/task-2/services.js index 2126969..fe19a24 100644 --- a/task-2/services.js +++ b/task-2/services.js @@ -1,5 +1,4 @@ // Nobel Prize API Documentation: https://www.nobelprize.org/about/developer-zone-2/ - import { fetchData } from './fetcher.js'; const API_BASE_URL = 'https://api.nobelprize.org/2.1'; @@ -13,9 +12,22 @@ const API_BASE_URL = 'https://api.nobelprize.org/2.1'; * @param {number} filters.limit - Number of results per page (default: 10) * @param {Function} onSuccess - Callback for successful fetch * @param {Function} onError - Callback for fetch errors + * */ export function fetchNobelPrizes(filters = {}, onSuccess, onError) { - let url = ''; // TODO Construct the full URL with query parameters; + const { year, category, offset = 0, limit = 10 } = filters; + + let url = `${API_BASE_URL}/nobelPrizes?offset=${offset}&limit=${limit}`; + + // only add year if it is not "all" + if (year && year !== 'all') { + url += `&year=${year}`; + } + + // only add category if it is not "all" + if (category && category !== 'all') { + url += `&nobelPrizeCategory=${category}`; + } fetchData(url, onSuccess, onError); -} +} \ No newline at end of file diff --git a/task-2/testServices.js b/task-2/testServices.js new file mode 100644 index 0000000..3fe0187 --- /dev/null +++ b/task-2/testServices.js @@ -0,0 +1,13 @@ +import { fetchNobelPrizes } from './services.js'; + +// اختبار الدالة بدون أي فلاتر +fetchNobelPrizes({}, + data => console.log('All Prizes:', data), + error => console.error('Error:', error) +); + +// اختبار الدالة مع سنة وفئة معينة +fetchNobelPrizes({ year: '2020', category: 'phy' }, + data => console.log('Physics Prizes 2020:', data), + error => console.error('Error:', error) +); \ No newline at end of file diff --git a/task-2/ui.js b/task-2/ui.js index 1981a10..926ae9f 100644 --- a/task-2/ui.js +++ b/task-2/ui.js @@ -70,8 +70,9 @@ export default class UI { * Populate year select dropdown with years from 1901 to current year */ populateYearSelect() { - const currentYear = new Date().getFullYear(); - const startYear = 1901; + + const currentYear = new Date().getFullYear(); + const startYear = 1901; // Add 'All' option first const allOption = document.createElement('option'); @@ -108,7 +109,8 @@ export default class UI { // Get filter values const category = this.dom.categorySelect.value; - const year = this.dom.yearSelect.value; + const year = this.dom.yearSelect.value; + // Update state this.state.filters.category = category;