程序代写代做代考 database Hive javascript Java ECLT 5830

ECLT 5830

ECLT 5830
Assignment #4 Specification
(Due: 7 Apr 2019)

Specification
Objective: In this assignment, you will need to
Retrieve/add data from/to a MySQL Database using JavaScript
Modify code from assignment #3 to retrieve item data from the database (instead of using the mock data)
Send HTTP request from a Node.js app

You can find the requirements for each page in the following slides.

MySQL Database
You need to have a MySQL DBMS running on the local machine.
Using XAMPP is preferred (as it is easier to install and it comes with phpMyAdmin – a Web interface to interact with MySQL DBMS)
The DBMS should be listening to the default port 3306.

The password for the “root” user is assumed to be an empty string (i.e., the default setting in XAMPP).

The database name is “eclt5830”

Note: If you can run “node init” in folder “init” without any problem, then your DBMS setting is as expected. If the database setting on your machine is different, please change back the database configuration in your code right before you submit your solution.

Item Data
These are the same data used in the previous assignments. However, the data should only reside in the database on the server side.

After installing the necessary npm modules (by running “npm install”), in folder “init”, run “node init” to initialize and populate the database.

Task #1: Retrieving Data from Database and Serving the selected data in JSON format
Create a Node.js app so that when the server receives a GET request for
/getItems?size=SIZE
If SIZE is one of “XS”, “S” ,”M”, “L”, “XL”, “2XL”, “3XL” (without the double quotes), the server should return all items of the specified SIZE in the response.

For all other cases, the server should return all items regardless of size.

The item data in the response should be encoded in JSON format.

Note: This is similar to task #2 in assignment #3. The only difference is that you need to retrieve the data from the database in this assignment.
You do not need to integrate assignment #3 solution into this assignment; you can just enter the URL in the browser location bar directly.

Task #2 – Recording “User X Likes Item Y” in database
When the server receives a GET request for
/likeItems?user_id=USER_ID&item_id=ITEM_ID

The server should perform the following tasks:
If
USER_ID exists in the “users” table, and
ITEM_ID exists in the “items” table, and
the “likes” table does not contain the pair (USER_ID, ITEM_ID)
then
Insert the pair (USER_ID, ITEM_ID) into the “likes” table
In the response, send the total number of users who have liked the item identified by ITEM_ID. (SQL: SELECT count(user_id) FROM likes WHERE …)
else
Send -1 in the response.

Task #3: Sending HTTP Request from a Node.js script
Modify the function likeItems(user_id, item_id) in “task3.js” so that the function will carry out the following tasks:

Send a HTTP GET request to
http://localhost:8080/likeItems?user_id=user_id&item_id=item_id
and output the value in the response.

You can run “task3.js” directly as “node task3” (while the server in task #2 and MySQL DBMS are running.)

Assessment Weight
Task 1 (40% of assignment #2)
Task 2 (40% of assignment #2)
Task 3 (20% of assignment #2)

Submission
To submit your solution, please archive the “npm project folder” of your app into a ZIP file, and upload the ZIP file to Blackboard.
Please remove the subfolder “node_modules” from your project folder before you ZIP the folder.

/docProps/thumbnail.jpeg