代写Assignment Three: Database帮做Java编程

Assignment Three: Database

Released: 20th November 2024

Due: 23:59, 18th December 2024

Synopsis:

You are going to store and manipulate some data in aMongoDB database. The data are related to events and locations, similar to the suggested dataset in our project.

Problem 7E and Problem 8E are compulsory questions for ESTR students. For CSCI students, you may also attempt these questions. However, we will only give you feedback without any extra scores.

Environment setup:

Please follow lab08 to setup a basic web server using Node.js and Express. Also, please follow lab09 to setup aMongoDB database and access it using Mongoose in Node.js.

Problem 1: Database Schema (20%)

Schema and Model in Mongoose help to confine the types of data to be stored. Your task is to setup two Schemas:

1.   Event:

a.   eventId: number, required, unique

b.   name: string, required

c.   loc: ObjectID -> location documents*

d.   quota: number

2.   Location:

a.   locId: nmuber, required, unique

b.   name: string, required

c.   quota: number

*Remarks: Try to accommodate the reference to documents in the location collection. Check Lecture 17 MongoDB from the Blackboard.

Problem 2: GET (15%)

Your Express server should respond to this request: GEThttp://server-address/ev/eventID

When the server receives this request, look up the event with the given event ID from the database. Then print the event name, location ID, location name, event quota on separate lines, as shown in the illustration below. The location quota is not necessary. All field names and string  values  should  be  quoted  with  double  quotes.  Extra  spacing  is  allowed,  and brackets/commas do not need to be in separate lines.

If the given event ID is not found, output an understandable message in the response body with status  code  404. All the response  should  be  sent  as  HTTP responses  with  content  type text/plain.

 

Problem 3: POST (15%)

Your Express server should respond to this request: POSThttp://server-address/ev

When the server receives this request, it should use the parameters submitted in the HTTP request body to create a new event in the database. A simple HTML form. like lab8_task2.html in Blackboard can be used.

However, instead of letting the user decide the event ID, your code should assign a new maximum event ID by looking into the database. For example, if 123 is the current maximum event ID, the new event ID would be 124.

Modify the form so that it asks the user for the location ID. A lookup should be done to check if the location quota is larger than or equal to the new event quota. If not, the event should not be created, and an error message should be responded to the user with status code 406. (Note: There is no need to check other event at the same location.)

If the event is created successfully, respond to the user with the URL of the created event. Use HTTP status code 201.

Problem 4: DELETE (10%)

We allow users to delete an event using this request: DELETE http://server-address/ev/eventID

If the event ID is found, the event should be removed from the database. Send a response with status code 204, and nothing in the body. If not found, show a simple error message in the body with status code 404.

Problem 5: Some more queries (20%)

The following four requests need to be handled: Q1: GEThttp://server-address/ev

List all the events available, with details formatted similar to the illustration below.

Q2: GEThttp://server-address/lo/locatoinID

Show the details for this location ID, with details formatted similar to the illustration below. Respond with an error message if the location ID is not found with the status code 404.

 

Q3: GEThttp://server-address/lo

List all location available. Show details similarly to the illustration in Q1.

Q4: GEThttp://server-address/ev?q=number

List all the events with enough quota, with a similar format in Q1. Respond with an empty array if there is none.

Problem 6: Updating with PUT (20%)

Implement a simple HTML user interface for updating event information. Assume that the user always types in an existing event ID to load the event information. The current data from the database should be shown to the user, so that they can decide what to edit, in an HTML form. Then, update the database with the user data on submission, using this request:

PUThttp://server-address/ev/eventID

The event should always be updated successfully. Respond to the user with the updated event  details as in Problem 1. You may combine this HTML form. with the POST form in Problem 3 or create a new HTML file. Checking of event and location quota is not necessary here.

Problem 7E: Counting GET (15%)

In every GET queries in this assignment, add an extra field “query_no”, which indicates the total count of GET queries for this user on this browser including requests giving errors.

Show it only in the response when there is no error. The count should be reset if there is no further query in 5 minutes.

Q1: Perform GET http://server-address/ev/1 (or any other GET operations) for several times   and show the details for this response with “query_no” larger than 1 similar to the illustration below.

 

Q2: GEThttp://server-address/ev/1 (or any other GET operations) after 5 minutes and show the details for this response with “query_no” equal to 1 similar to the illustration below.

 

Problem 8E: GraphQL GET (20%)

You are required to transform. all GET operations in this assignment into a GraphQL API using Apollo Server while maintaining the same underlying data model and business logic. After starting     the      server      with     node      server_graphql.js      command,      navigate     to http://localhost:3000/graphql in your browser.

You can query all locations and events, and your response should be similar to the examples below:

 

Formats and assumptions:

Please pay attention for the followings:

1.   In this assignment, since the response body do not always confirm to standard JSON formats, e.g., for error messages, please always use text/plain as the Content- Type.

2.   The  JSON-like  objects  and  arrays   should  be  readable  by  standard  JavaScript JSON.parse() if all newline characters are removed.

3.   Use the CORS middleware for express to enable submission from local HTML forms (more details in lab08).

4.   Unless otherwise specified, the HTTP status code should be 200 OK by default. 201 Created is used for responding to successful POST requests, and 204 No Content is used for responding to successful DELETE requests.

5.   For development, you may feel free to populate your database with testing data (i.e., create your own fake data for testing). Please create a folder named database_setup. You can create database whose name is assignment3 and create two collections which are locations and events. In the locations collection, please import from JSON file database_setup/assignment3.locations.json. In the events collection, please import from JSON database_setup/assignment3.events.json.

6.   For grading, graders will use another set of data in their database. Hence, you code should be adaptive to different data. Assume that there is always at least one location and one event in the database when grading (i.e., it will not be an empty database). All locations linked from events are valid in the database.

7.   Assume that the input data type is always correct, i.e., only numbers will be input for number fields. All numbers are positive numbers. When grading, no fields are blank.

8.   Assume that user always enters a valid and existing location ID when creating or updating events.

9.   Unless otherwise specified, events or locations with missing quota will not be tested.

10. The  Node  server  should  start  at  port  3000.  Assume  the  access  URL  starts  with http://localhost:3000.

11. There are no cosmetic requirements for this assignment. You are welcome to implement extra styles and features at your own ability.

12. Your submission should contain only one JavaScript file (one more JavaScript file for Problem 8E).



热门主题

课程名

mktg2509 csci 2600 38170 lng302 csse3010 phas3226 77938 arch1162 engn4536/engn6536 acx5903 comp151101 phl245 cse12 comp9312 stat3016/6016 phas0038 comp2140 6qqmb312 xjco3011 rest0005 ematm0051 5qqmn219 lubs5062m eee8155 cege0100 eap033 artd1109 mat246 etc3430 ecmm462 mis102 inft6800 ddes9903 comp6521 comp9517 comp3331/9331 comp4337 comp6008 comp9414 bu.231.790.81 man00150m csb352h math1041 eengm4100 isys1002 08 6057cem mktg3504 mthm036 mtrx1701 mth3241 eeee3086 cmp-7038b cmp-7000a ints4010 econ2151 infs5710 fins5516 fin3309 fins5510 gsoe9340 math2007 math2036 soee5010 mark3088 infs3605 elec9714 comp2271 ma214 comp2211 infs3604 600426 sit254 acct3091 bbt405 msin0116 com107/com113 mark5826 sit120 comp9021 eco2101 eeen40700 cs253 ece3114 ecmm447 chns3000 math377 itd102 comp9444 comp(2041|9044) econ0060 econ7230 mgt001371 ecs-323 cs6250 mgdi60012 mdia2012 comm221001 comm5000 ma1008 engl642 econ241 com333 math367 mis201 nbs-7041x meek16104 econ2003 comm1190 mbas902 comp-1027 dpst1091 comp7315 eppd1033 m06 ee3025 msci231 bb113/bbs1063 fc709 comp3425 comp9417 econ42915 cb9101 math1102e chme0017 fc307 mkt60104 5522usst litr1-uc6201.200 ee1102 cosc2803 math39512 omp9727 int2067/int5051 bsb151 mgt253 fc021 babs2202 mis2002s phya21 18-213 cege0012 mdia1002 math38032 mech5125 07 cisc102 mgx3110 cs240 11175 fin3020s eco3420 ictten622 comp9727 cpt111 de114102d mgm320h5s bafi1019 math21112 efim20036 mn-3503 fins5568 110.807 bcpm000028 info6030 bma0092 bcpm0054 math20212 ce335 cs365 cenv6141 ftec5580 math2010 ec3450 comm1170 ecmt1010 csci-ua.0480-003 econ12-200 ib3960 ectb60h3f cs247—assignment tk3163 ics3u ib3j80 comp20008 comp9334 eppd1063 acct2343 cct109 isys1055/3412 math350-real math2014 eec180 stat141b econ2101 msinm014/msing014/msing014b fit2004 comp643 bu1002 cm2030
联系我们
EMail: 99515681@qq.com
QQ: 99515681
留学生作业帮-留学生的知心伴侣!
工作时间:08:00-21:00
python代写
微信客服:codinghelp
站长地图