Skip to content

Commit 677e1e0

Browse files
authored
Merge pull request #17 from tsarnadelis/alex
Fixing comment density where needed
2 parents c5f986d + 012085a commit 677e1e0

8 files changed

Lines changed: 60 additions & 1 deletion

File tree

controllers/LicensePlate.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,28 @@
33
var utils = require('../utils/writer.js');
44
var LicensePlate = require('../service/LicensePlateService');
55

6+
// Function to handle modifying a license plate
67
module.exports.modifyPlate = function modifyPlate (req, res, next, body) {
78
LicensePlate.modifyPlate(body)
89
.then(function (response) {
10+
// Write the response using the utility function
911
utils.writeJson(res, response);
1012
})
1113
.catch(function (response) {
14+
// Write the error response using the utility function
1215
utils.writeJson(res, response);
1316
});
1417
};
1518

19+
//Function to handle registering a new license plate
1620
module.exports.registerPlate = function registerPlate (req, res, next, body) {
1721
LicensePlate.registerPlate(body)
1822
.then(function (response) {
23+
// Write the response using the utility function
1924
utils.writeJson(res, response);
2025
})
2126
.catch(function (response) {
27+
// Write the error response using the utility function
2228
utils.writeJson(res, response);
2329
});
2430
};

controllers/Payment.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
var utils = require('../utils/writer.js');
44
var Payment = require('../service/PaymentService');
55

6+
//Function to handle making a payment
67
module.exports.makePayment = function makePayment (req, res, next, body) {
78
Payment.makePayment(body)
89
.then(function (response) {
10+
// Write the response using the utility function
911
utils.writeJson(res, response);
1012
})
1113
.catch(function (response) {
14+
// Write the error response using the utility function
1215
utils.writeJson(res, response);
1316
});
1417
};

controllers/Reservation.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,41 @@
33
var utils = require('../utils/writer.js');
44
var Reservation = require('../service/ReservationService');
55

6+
// Function to handle deleting a reservation
67
module.exports.deleteReservation = function deleteReservation (req, res, next, id) {
78
Reservation.deleteReservation(id)
89
.then(function (response) {
10+
// Write the response using the utility function
911
utils.writeJson(res, response);
1012
})
1113
.catch(function (response) {
14+
// Write the error response using the utility function
1215
utils.writeJson(res, response);
1316
});
1417
};
1518

19+
//Function to handle making a reservation
1620
module.exports.makeReservation = function makeReservation (req, res, next, body) {
1721
Reservation.makeReservation(body)
1822
.then(function (response) {
23+
// Write the response using the utility function
1924
utils.writeJson(res, response);
2025
})
2126
.catch(function (response) {
27+
// Write the error response using the utility function
2228
utils.writeJson(res, response);
2329
});
2430
};
2531

32+
//Function to handle modifying a reservation
2633
module.exports.modifyReservation = function modifyReservation (req, res, next, body, spotId, userId, startTime, duration, date, id) {
2734
Reservation.modifyReservation(body, spotId, userId, startTime, duration, date, id)
2835
.then(function (response) {
36+
// Write the response using the utility function
2937
utils.writeJson(res, response);
3038
})
3139
.catch(function (response) {
40+
// Write the error response using the utility function
3241
utils.writeJson(res, response);
3342
});
3443
};

controllers/Spot.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,52 +3,67 @@
33
var utils = require('../utils/writer.js');
44
var Spot = require('../service/SpotService');
55

6+
//Function to handle creating a new spot
67
module.exports.createSpot = function createSpot (req, res, next, body) {
78
Spot.createSpot(body)
89
.then(function (response) {
10+
// Write the response using the utility function
911
utils.writeJson(res, response);
1012
})
1113
.catch(function (response) {
14+
// Write the error response using the utility function
1215
utils.writeJson(res, response);
1316
});
1417
};
1518

19+
//Function to handle retrieving all spots
1620
module.exports.getSpots = function getSpots (req, res, next) {
1721
Spot.getSpots()
1822
.then(function (response) {
23+
// Write the response using the utility function
1924
utils.writeJson(res, response);
2025
})
2126
.catch(function (response) {
27+
// Write the error response using the utility function
2228
utils.writeJson(res, response);
2329
});
2430
};
2531

32+
//Function to handle modifying an existing parking spot
2633
module.exports.modifySpot = function modifySpot (req, res, next, body, address, type, charger, id) {
2734
Spot.modifySpot(body, address, type, charger, id)
2835
.then(function (response) {
36+
// Write the response using the utility function
2937
utils.writeJson(res, response);
3038
})
3139
.catch(function (response) {
40+
// Write the error response using the utility function
3241
utils.writeJson(res, response);
3342
});
3443
};
3544

45+
// Function to handle removing a parking spot
3646
module.exports.removeSpot = function removeSpot (req, res, next, id) {
3747
Spot.removeSpot(id)
3848
.then(function (response) {
49+
// Write the response using the utility function
3950
utils.writeJson(res, response);
4051
})
4152
.catch(function (response) {
53+
// Write the error response using the utility function
4254
utils.writeJson(res, response);
4355
});
4456
};
4557

58+
//Function to handle searching for a parking spot
4659
module.exports.searchSpot = function searchSpot (req, res, next, address, type, charger) {
4760
Spot.searchSpot(address, type, charger)
4861
.then(function (response) {
62+
// Write the response using the utility function
4963
utils.writeJson(res, response);
5064
})
5165
.catch(function (response) {
66+
// Write the error response using the utility function
5267
utils.writeJson(res, response);
5368
});
5469
};

controllers/SpotOwner.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
var utils = require('../utils/writer.js');
44
var SpotOwner = require('../service/SpotOwnerService');
55

6+
//Function to handle adding a new spot owner
67
module.exports.addSpotOwner = function addSpotOwner (req, res, next, body) {
78
SpotOwner.addSpotOwner(body)
89
.then(function (response) {
10+
// Write the response using the utility function
911
utils.writeJson(res, response);
1012
})
1113
.catch(function (response) {
14+
// Write the error response using the utility function
1215
utils.writeJson(res, response);
1316
});
1417
};

cypress/e2e/GET_spot.cy.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,31 @@
11
describe('GET /spot', () => {
22
beforeEach(() => {
3+
// Visit the Swagger UI page before each test
34
cy.visit('http://localhost:8080/docs')
45
})
56

67
it('Title exists', () => {
8+
//Check if the title contains the text 'Curbsprings API'
79
cy.get('.title').should('contain.text', 'Curbsprings API')
810
})
911

1012
it('Description exists', () => {
13+
// Check if the description includes the specified text
1114
cy.get('.description').should('include.text', 'API for managing parking spots, reservations, users, and payments.')
1215
})
1316

1417
it('All types of endpoints exists', () => {
18+
// Check if there are 5 endpoint tags in the Swagger UI
1519
cy.get('.opblock-tag').should('have.length', 5)
1620
})
1721

1822
it('Click on accordion', () => {
23+
// Click on the 'GET /spot' accordion to expand it
1924
cy.get('#operations-Spot-getSpots').click();
2025
})
2126

2227
it('Open accordion should include description', () => {
28+
// Check if the expanded accordion includes the specified text
2329
cy.get('#operations-Spot-getSpots')
2430
.click()
2531
.find('.opblock-description')

cypress/e2e/POST_payment.cy.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,31 @@
11
describe('POST /payment', () => {
22
beforeEach(() => {
3+
// Visit the Swagger UI before each test
34
cy.visit('http://localhost:8080/docs')
45
})
56

67
it('Title exists', () => {
8+
//Check if the title contains the text 'Curbsprings API'
79
cy.get('.title').should('contain.text', 'Curbsprings API')
810
})
911

1012
it('Description exists', () => {
13+
// Check if the description includes the specified text
1114
cy.get('.description').should('include.text', 'API for managing parking spots, reservations, users, and payments.')
1215
})
1316

1417
it('All types of endpoints exists', () => {
18+
// Check if there are 5 endpoint tags in the Swagger UI
1519
cy.get('.opblock-tag').should('have.length', 5)
1620
})
1721

1822
it('Click on accordion', () => {
23+
// Click on the 'POST /payment' accordion to expand it
1924
cy.get('#operations-Payment-makePayment').click();
2025
})
2126

2227
it('Open accordion should include description', () => {
28+
// Check if the expanded accordion includes the specified text
2329
cy.get('#operations-Payment-makePayment')
2430
.click()
2531
.find('.opblock-description')

utils/writer.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,37 @@
1+
// Constructor for creating a response payload with a status code and payload
12
var ResponsePayload = function(code, payload) {
23
this.code = code;
34
this.payload = payload;
45
}
56

7+
// Function to create a ResponsePayload object with a given status code and payload
68
exports.respondWithCode = function(code, payload) {
79
return new ResponsePayload(code, payload);
810
}
911

12+
// Function to write a JSON response
1013
var writeJson = exports.writeJson = function(response, arg1, arg2) {
1114
var code;
1215
var payload;
13-
16+
17+
// If arg1 is an instance of ResponsePayload, extract the payload and code
1418
if(arg1 && arg1 instanceof ResponsePayload) {
1519
writeJson(response, arg1.payload, arg1.code);
1620
return;
1721
}
1822

23+
// Determine the status code from arg2 if it is an integer
1924
if(arg2 && Number.isInteger(arg2)) {
2025
code = arg2;
2126
}
2227
else {
28+
// Determine the status code from arg1 if it is an integer
2329
if(arg1 && Number.isInteger(arg1)) {
2430
code = arg1;
2531
}
2632
}
33+
34+
// Set the payload based on the provided arguments
2735
if(code && arg1) {
2836
payload = arg1;
2937
}
@@ -35,9 +43,12 @@ var writeJson = exports.writeJson = function(response, arg1, arg2) {
3543
// if no response code given, we default to 200
3644
code = 200;
3745
}
46+
// If the payload is an object, convert it to a JSON string
3847
if(typeof payload === 'object') {
3948
payload = JSON.stringify(payload, null, 2);
4049
}
50+
// Set the response header with the response code and content type
4151
response.writeHead(code, {'Content-Type': 'application/json'});
52+
//Send the response with the payload
4253
response.end(payload);
4354
}

0 commit comments

Comments
 (0)