Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit


Ticket Tracking System API


Objectives

Build out a back-end RESTful API application/service for ticket-tracking system.

Overview

In this project you will practice writing basic CRUD operations with RESTful API services. For this API, you will be generating a single resource, a ticket, which is one of the primary tools for managing the software development lifecylce in modern       software development -- a ticket tracking system (e.g. Jira).

Requirements

We have provided you with a pre-structured express server application. You will make the app respond at various requests by implementing RESTful routes.

The first thing you need to do is to run npm install at the root level of the express application to install all the necessary packages. The server is configured to run on port 4000. You need to complete the following tasks:

. In app.js, you need to:

Set the ticketsRouter to prepend its endpoints with api/v1/tickets.

Declare the dbUser and dbPass variables. You will use the database admin user id and password you set up in

Mongo Atlas, as you work on this project. Your program should receive the database admin and password from command-line. (i.e., use process.env). Do NOT set values for the id and password in the code.

Declare the uri for the connection string that mongoose uses to be the one for your instance of a mongo cluster

you created and the database you instantiated for it. We will use our URI

Write code that connects to your database.

. In models/ticket.js you need to define the schema for your ticket model. It should have the following fields:

title, type: String

author, type: String

description, type: String

type, type: String

dueDate, type: Date

assignedTo, type: String

status, type: String

All of these fields are required with the exception of the AssignedTo field - that can be null, indicating that it has not been assigned to a developer.

. In routes/api/v1/tickets.js you need to define the following 5 endpoints as well as which type of request they will respond to:

INDEX route - '/' which should respond to a GET request and return all the tickets in the database.

CREATE route - '/', which should respond to a POST request and create a new instance of a ticket in the

database with the values received in the request.



SHOW route - '/:id'which should respond to a GET request and return the specific ticket in the database

that has the :id url params value for its own id.

UPDATE route - '/:id', which should respond to a PUT request and update the specific ticket whose id in the

database is the same as the id in the url params.

DELETE route - '/:id' which should respond to a DELETE request and remove the specific ticket from the

database whose id is the same as the id in the url params

NOTE: your endpoints need to be exact. An API is a contract and as such needs to convey to the end-user the exact          specifications with which to configure their own applications. Additionally, each of your endpoints should invoke a method defined in the ticketController to handle the business logic of the incoming request.

. In controllers/ticketController.js, you need to define the following functions that will serve as the               controller actions for your ticket endpoints. For each of these controller functions, you will need to handle possible      errors and inform the client of success or failure of the initial request using http status codes as specified below. (You may use callback or promise).

getTicketList, which will handle the functionality of retrieving the details of all instances of a ticket in the

database and send them to the client as a json string (e.g., res.json(tickets); ) where tickets is the        variable that holds the retrieved tickets). If any error happens, respond with the status code 500 and an error message (e.g., res.status(500).send('your message')).

createTicket, which will handle the functionality of creating a new instance of ticket in the database. At

successful creation, respond with the status code 201 and the ticket created as a json (e.g.,

res.status(201).json(ticket);) where ticket is the newly added ticket. If any error happens, respond with the status code 500 and an error message.

getTicket, which will handle the functionality of retrieving the details of a single instance of a ticket in the

database and send it to the client as a json. If there is an error in retrieving a new ticket (by the ticket id created by mongoDB), respond with the status code 500 and an error message.

updateTicket, which will handle the functionality of updating the details of a single instance of a ticket in the

database. If there is an error in updating the ticket, respond with the status code 500 and an error message. If

the ticket is successfully updated, respond with the status code 204 and send an empty string (e.g., res.status(204).send(''));)).

deleteTicket, which will handle the functionality of removing a single instance of a ticket in the database. If

any error happens in the deletion process, respond with the status code 500 and an error message. If successfully deleted, respond with the status code 204 and send an empty string.

Grading

(20 pts) Correct Schema

(80 pts) Correct implementation of the required endpoints and controller functions

General Requirements

When you first start your project, do not forget to execute npm install inside of the tickets-api directory to install

the necessary packages.

We have provided you the bootstrapped structure for your project. You should not modify the structure but place the

necessary code in the files provided.

You should define whatever necessary custom middleware you need to minimize code duplication and apply it at the

appropriate layer (i.e. controller, route, app)

Do not use var, except for the code we have provided you with ; use let or const for variable definition. You can test your API by using the Postman as shown in lectures (or something like it - Curl for example).



Submission

. Delete the node_module folder in the tickets-api folder.

. Assign an empty string to the mongoDB URI variables in app.js. Your program should receive the database admin   and password from command-line. (i.e., use process.env). Do NOT set values for the id and password in the code. Do NOT set values for the id and password in the code.

. Create a folder named your directory id and move the tickets-api folder into the created folder.

. Compress the folder (the one named your directory id) into a zip file.

. Rename the zip file to YourDirectoryID-P2.zip.

when we uncompress your work, we must have the tickets-api folder inside the folder named to your directory

id -- i.e., /directoryID/tickets-api/...

. Submit the compressed file to the submit server.

. Once submitted, make sure that you download your code, uncompress, check directory structure, and verify your code to verify if your code work fine. Again, you can make requests using the Postman or Curl.