diff --git a/res/static/res/script/listmaker.js b/res/static/res/script/listmaker.js index c7f53ff..6a08a59 100644 --- a/res/static/res/script/listmaker.js +++ b/res/static/res/script/listmaker.js @@ -1,6 +1,10 @@ var listItems = new Array(); +$("#btnCreateList").click(function (evt) { + createList(); +}); + function addToList(id, desc){ var listEntry = {id: id, desc: desc}; @@ -8,7 +12,7 @@ function addToList(id, desc){ } function createList(){ - var url = "/api/createlist/"; + var url = "/api/list"; var postData = {}; @@ -20,17 +24,29 @@ function createList(){ if(title === null){ return; } - - postData["title" ] = title; + + var postData = { + "title": title, + "description": "yo", + "files": new Array() + }; var arrayLength = listItems.length; for (var i = 0; i < arrayLength; i++) { - postData["id" + i] = listItems[i]["id"]; - postData["desc" + i] = listItems[i]["desc"]; + postData.files[i] = { + "id": listItems[i]["id"], + "description": listItems[i]["desc"] + }; } - $.post(url, postData, function(response){ - listCreated(response); + $.ajax({ + url: url, + contentType: "application/json", + method: "POST", + data: JSON.stringify(postData), + dataType: "json", + success: listCreated, + error: listCreated }); } @@ -38,7 +54,7 @@ function listCreated(response){ if(response.status === "success"){ resultString = "
Param | -Required | -Location | -Description | -
id | -true | -URL | -ID of the file to delete | -
+ POST body should be a JSON object, example below. A list can contain + maximally 5000 files. If you try to add more the request will fail. +
++{ + "title": "My beautiful photos", + "description": "An album of photos from my vacation in Austria", + "files": [ // Ordered array of files to add to the list + { + "id": "abc123", + "description": "First photo of the week, such a beautiful valley" + }, + { + "id": "123abc", + "description": "The week went by so quickly, here's a photo from the plane back" + } + ] +} +
HTTP 200: OK { "success": true, - "value": "file_deleted", - "message": "The file has been deleted." -}-
HTTP 404: Not Found + "id": "yay137" // ID of the newly created list +} ++
HTTP 422: Unprocessable Entity { "success": false, "value": "file_not_found", - "message": "File ID was not found in the database." -}-
HTTP 401: Unauthorized + "id": "Oh42No", // The file you tried to add with this ID does not exist + "message": "File Oh42No was not found in the database." +} ++
HTTP 413: Payload too large { "success": false, - "value": "unauthorized", - "message": "You are not logged in." -}-
HTTP 403: Forbidden + "value": "too_many_files", + "message": "This list contains too many files, max 5000 allowed." +} ++
HTTP 422: Unprocessable Entity { "success": false, - "value": "forbidden", - "message": "This is not your file." -}+ "value": "json_parse_failed", + "message": "The JSON object in the request body could not be read." +} + +
HTTP 413: Payload too large +{ + "success": false, + "value": "title_too_long", + "message": "The title of this list is too long, max 300 characters allowed." +} ++
HTTP 413: Payload too large +{ + "success": false, + "value": "description_too_long", + "message": "The description of this list or one of the files in the list is too long, max 3000 characters allowed." +} +