This repository has been archived by the owner on Jan 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from Glimpse/NicoleIntegrationFinal
Connected client to api gateway; auth and checkout service working E2E
- Loading branch information
Showing
41 changed files
with
1,013 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
FROM node:latest | ||
LABEL Name=stickerapp-apigateway Version=0.1.0 | ||
COPY package.json /tmp/package.json | ||
RUN cd /tmp && npm install | ||
RUN mkdir -p /usr/src/app && mv /tmp/node_modules /usr/src | ||
WORKDIR /usr/src/app | ||
COPY . /usr/src/app | ||
EXPOSE 3000 | ||
CMD npm start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
|
||
//Default URL for the checkout service which provides Feedback and Order CRUD operations | ||
checkoutServiceUrl: 'http://localhost:5000' | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
'use strict'; | ||
|
||
//TODO: This functionality is temporary until integated with the new cart microservice; note that this currently calls into the "dummy" data access layer | ||
const express = require('express'); | ||
const bodyParser = require('body-parser'); | ||
const router = express.Router(); | ||
|
||
const dataAccess = require('../temp/db/data-access'); | ||
|
||
router.use(bodyParser.json()); | ||
|
||
router.get('/', function stickerRouteBrowse(req, res) { | ||
const renderData = { pageTitle: 'Browse', entry: 'browse' }; | ||
|
||
console.log('Render values: ', renderData); | ||
|
||
res.render('index', renderData); | ||
}); | ||
|
||
router.get('/api/items', function stickerRouteApiBrowse(req, res) { | ||
// Do things with req.query.tags | ||
let tags; | ||
if (req.query.tags) { | ||
tags = req.query.tags.split(','); | ||
} | ||
|
||
dataAccess.getStickers(tags, (items) => { | ||
console.info('%d stickers found', items.length); | ||
if (tags) { | ||
console.log('Tags used in filter: ', tags); | ||
} | ||
|
||
res.send({ | ||
items | ||
}); | ||
}); | ||
}); | ||
|
||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
'use strict'; | ||
|
||
//TODO: This functionality is temporary until integated with the new cart microservice; note that this currently calls into the "dummy" data access layer | ||
const express = require('express'); | ||
const bodyParser = require('body-parser'); | ||
const dataAccess = require('../temp/db/data-access'); | ||
|
||
const router = express.Router(); | ||
router.use(bodyParser.json()); | ||
|
||
router.get('/', function stickerRouteCart(req, res) { | ||
res.render('index', { pageTitle: 'Cart', entry: 'cart' }); | ||
}); | ||
|
||
function sendItems(token, res) { | ||
dataAccess.getCart(token, (items) => { | ||
dataAccess.getStickers(null, (stickers) => { | ||
res.send({ | ||
items: items.map((id) => stickers.filter((sticker) => sticker.id.toString() === id)[0]) | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
router.get('/api/items', (req, res) => { | ||
if (!req.query.token) { | ||
res.status(401).send('Unauthorized'); | ||
return; | ||
} | ||
sendItems(req.query.token, res); | ||
}); | ||
|
||
router.put('/api/items/:item_id', (req, res) => { | ||
if (!req.body.token) { | ||
res.status(401).send('Unauthorized'); | ||
return; | ||
} | ||
|
||
console.log('Item targetted %s', req.params.item_id); | ||
|
||
dataAccess.addToCart(req.body.token, req.params.item_id, () => { | ||
dataAccess.getSticker(req.params.item_id, (item) => { | ||
if (!item) { | ||
dataAccess.addStickers([ req.body.item ], () => sendItems(req.body.token, res)); | ||
} else { | ||
sendItems(req.body.token, res); | ||
} | ||
}); | ||
}); | ||
}); | ||
|
||
router.delete('/api/items/:item_id', (req, res) => { | ||
if (!req.body.token) { | ||
res.status(401).send('Unauthorized'); | ||
return; | ||
} | ||
|
||
console.log('Item targetted', req.params.item_id); | ||
|
||
dataAccess.removeFromCart(req.body.token, req.params.item_id, () => { | ||
sendItems(req.body.token, res); | ||
}); | ||
}); | ||
|
||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
|
||
'use strict'; | ||
|
||
//TODO: This is temporary using the "dummy" data access layer in order to interact with the cart; this will be removed when integrated with new cart microservice | ||
const dataAccess = require('../temp/db/data-access'); | ||
|
||
const express = require('express'); | ||
const request = require('request'); | ||
const guid = require('guid'); | ||
|
||
//This route calls into the ASP.NET Core checkout microservice | ||
const checkoutServiceUrl = require('../config/services-config').checkoutServiceUrl; //TODO: add env url lookup | ||
|
||
const router = express.Router(); | ||
const bodyParser = require('body-parser'); | ||
router.use(bodyParser.urlencoded({ extended: true })); | ||
|
||
router.post('/', function stickerRouteCheckout(req, res) { | ||
|
||
var orderJson = { | ||
Id: guid.raw(), | ||
FullName : req.body['checkout-name'], | ||
Email : req.body['checkout-email'], | ||
Items : req.body['checkout-items'] | ||
}; | ||
|
||
request({ | ||
url: checkoutServiceUrl + '/api/order/', | ||
method: 'POST', | ||
json: true, | ||
body: orderJson, | ||
headers: { | ||
//Pass the current authenticated user's id to the checkout microservice | ||
'stickerUserId': req.user.id | ||
}}, | ||
function finishAddOrder(error){ | ||
if (error) { | ||
console.log('Adding Order failed: ' + error); | ||
} else { | ||
console.log('Order added'); | ||
} | ||
|
||
//TODO: Need to update this when the new cart microservice is integrated; for now, calls into the "dummy" data access layer | ||
dataAccess.clearCart(req.body.token, () => { | ||
res.render('index', { pageTitle: 'Checkout', entry: 'checkout' }); | ||
}); | ||
}); | ||
}); | ||
|
||
module.exports = router; |
Oops, something went wrong.