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..4b8d7af --- /dev/null +++ b/task-1/delete.sh @@ -0,0 +1 @@ +curl -X DELETE http://localhost:3000/users/11 \ No newline at end of file diff --git a/task-1/get.sh b/task-1/get.sh new file mode 100644 index 0000000..e46ff3f --- /dev/null +++ b/task-1/get.sh @@ -0,0 +1,2 @@ +curl -X GET http://localhost:3000/users/11 \ +-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..8909f80 --- /dev/null +++ b/task-1/patch.sh @@ -0,0 +1,4 @@ + +curl -X PATCH http://localhost:3000/users/11 \ +-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..211ff5e --- /dev/null +++ b/task-1/post.sh @@ -0,0 +1,5 @@ + +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..125d0d6 100644 --- a/task-2/services.js +++ b/task-2/services.js @@ -1,8 +1,8 @@ // Nobel Prize API Documentation: https://www.nobelprize.org/about/developer-zone-2/ -import { fetchData } from './fetcher.js'; +import { fetchData } from "./fetcher.js"; -const API_BASE_URL = 'https://api.nobelprize.org/2.1'; +const API_BASE_URL = "https://api.nobelprize.org/2.1"; /** * Fetch Nobel Prizes with optional filters @@ -11,11 +11,30 @@ const API_BASE_URL = 'https://api.nobelprize.org/2.1'; * @param {string} filters.category - Category code to filter by (optional) * @param {number} filters.offset - Pagination offset (default: 0) * @param {number} filters.limit - Number of results per page (default: 10) + * @param {string} filters.sort - The sort order (result is sorted by year) * @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; +export function fetchNobelPrizes( + { + category = "all", + year = "all", + offset = 0, + limit = 10, + sort = "desc", + } = {}, + onSuccess, + onError +) { + const params = new URLSearchParams(); + if (category !== "all") params.append("nobelPrizeCategory", category); + if (year !== "all") params.append("nobelPrizeYear", year); + + params.append("sort", sort); + params.append("offset", offset); + params.append("limit", limit); + + const url = `${API_BASE_URL}/nobelPrizes?${params.toString()}`; fetchData(url, onSuccess, onError); } diff --git a/task-2/ui.js b/task-2/ui.js index 1981a10..2551049 100644 --- a/task-2/ui.js +++ b/task-2/ui.js @@ -125,6 +125,7 @@ export default class UI { category: category, offset: offset, limit: this.state.itemsPerPage, + sort : 'desc', }, (data) => { // Update state with results