Skip to content

Commit

Permalink
BRS-615 adding subArea UID (#35)
Browse files Browse the repository at this point in the history
* BRS-615 adding subArea UID

* BRS-615 improving test code coverage

* BRS-615 reverting subarea pk to park::<orcs>
  • Loading branch information
cameronpettit authored May 24, 2022
1 parent 2abe2b4 commit 16c8050
Show file tree
Hide file tree
Showing 15 changed files with 113 additions and 80 deletions.
71 changes: 37 additions & 34 deletions __tests__/global/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,37 @@
{
"sk": "0041",
"subAreas": [
"Maple Bay",
"Teapot Hill"
{
"name": "Maple Bay",
"id": "0087"
},
{
"name": "Teapot Hill",
"id": "0089"
}
],
"pk": "park",
"parkName": "Cultus Lake Park"
},
{
"sk": "6161",
"subAreas": [
"Holt Creek"
{
"name": "Holt Creek",
"id": "0074"
}
],
"pk": "park",
"parkName": "Cowichan River Park"
}
],
"SUBAREA_INFORMATION": [
{
"sk": "Maple Bay",
"sk": "0087",
"pk": "park::0041",
"parkName": "Cultus Lake Park",
"activities": [
"Boating",
"Frontcountry Camping",
"Day Use"
],
"orcs": 41,
Expand All @@ -34,9 +43,9 @@
"SUBAREAS": [
{
"pk": "park::0041",
"sk": "Maple Bay",
"sk": "0087",
"activities": [
"Boating",
"Frontcountry Camping",
"Day Use"
],
"parkName": "Cultus Lake Park",
Expand All @@ -45,7 +54,7 @@
},
{
"pk": "park::0041",
"sk": "Teapot Hill",
"sk": "0089",
"activities": [
"Day Use"
],
Expand All @@ -55,24 +64,22 @@
},
{
"pk": "park::6161",
"sk": "Holt Creek",
"sk": "0074",
"activities": [
"Day Use"
],
"orcs": 41,
"orcs": "6161",
"subAreaName": "Holt Creek"
}
],
"SUBAREA_ENTRIES": [
{
"pk": "0041::Maple Bay::Day Use",
"pk": "0087::Day Use",
"sk": "202204",
"parkName": "Cultus Lake Park",
"picnicRevenue": 2.5,
"pplCalculations": {
"vehicleModifier": 3.5,
"busModifier": 40
},
"attendanceVehicleModifier": 3.5,
"attendanceBusModifier": 40,
"pplVehicleCount": 12,
"subAreaName": "Maple Bay",
"otherHotSpringsRevenue": 5.55,
Expand All @@ -84,14 +91,12 @@
"picnicRentals": 5
},
{
"pk": "0041::Maple Bay::Boating",
"pk": "0087::Frontcountry Camping",
"sk": "202204",
"parkName": "Cultus Lake Park",
"picnicRevenue": 2.5,
"pplCalculations": {
"vehicleModifier": 3.5,
"busModifier": 40
},
"attendanceVehicleModifier": 3.5,
"attendanceBusModifier": 40,
"pplVehicleCount": 12,
"subAreaName": "Maple Bay",
"otherHotSpringsRevenue": 5.55,
Expand All @@ -105,28 +110,26 @@
],
"CONFIG_ENTRIES": [
{
"pk": "0041::Maple Bay::Day Use",
"sk": "config",
"pk": "config::0087",
"sk": "Day Use",
"parkName": "Cultus Lake Park",
"pplCalculations": {
"vehicleModifier": 3.5,
"busModifier": 40
},
"attendanceVehicleModifier": 3.5,
"attendanceBusModifier": 40,
"orcs": "0041",
"subAreaName": "Maple Bay",
"subAreaId": "0087",
"activity": "Day Use"
},
{
"pk": "0041::Maple Bay::Boating",
"sk": "config",
"pk": "config::0087",
"sk": "Frontcountry Camping",
"parkName": "Cultus Lake Park",
"pplCalculations": {
"vehicleModifier": 3.5,
"busModifier": 40
},
"attendanceVehicleModifier": 3.5,
"attendanceBusModifier": 40,
"subAreaName": "Maple Bay",
"subAreaId": "0087",
"orcs": "0041",
"activity": "Day Use"
"activity": "Frontcountry Camping"
}
]
}
}
2 changes: 1 addition & 1 deletion __tests__/park.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe('Pass Succeeds', () => {
const response = await parkGET.handler({
queryStringParameters: {
orcs: PARKSLIST[0].sk,
subAreaName: specificSubAreas[0].subAreaName
subAreaId: specificSubAreas[0].sk
}
}, null);

Expand Down
12 changes: 6 additions & 6 deletions __tests__/subarea.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ describe('Subarea Test', () => {
{
queryStringParameters: {
orcs: SUBAREA_ENTRIES[0].orcs,
subAreaName: SUBAREA_ENTRIES[0].subAreaName,
activity: SUBAREA_ENTRIES[0].pk.split("::")[2],
subAreaId: SUBAREA_ENTRIES[0].pk.split("::")[0],
activity: SUBAREA_ENTRIES[0].pk.split("::")[1],
date: SUBAREA_ENTRIES[0].sk
}
}, null);
Expand All @@ -76,8 +76,8 @@ describe('Subarea Test', () => {
},
body: JSON.stringify({
orcs: SUBAREA_ENTRIES[0].orcs,
subAreaName: SUBAREA_ENTRIES[0].subAreaName,
activity: SUBAREA_ENTRIES[0].pk.split("::")[2],
subAreaId: SUBAREA_ENTRIES[0].pk.split("::")[0],
activity: SUBAREA_ENTRIES[0].pk.split("::")[1],
date: "202201"
})
}, null);
Expand Down Expand Up @@ -139,8 +139,8 @@ describe('Subarea Test', () => {
},
body: JSON.stringify({
orcs: SUBAREA_ENTRIES[0].orcs,
subAreaName: SUBAREA_ENTRIES[0].subAreaName,
activity: SUBAREA_ENTRIES[0].pk.split("::")[2],
subAreaId: SUBAREA_ENTRIES[0].pk.split("::")[0],
activity: SUBAREA_ENTRIES[0].pk.split("::")[1],
date: "2022" // Invalid
})
}, null);
Expand Down
8 changes: 4 additions & 4 deletions lambda/park/GET/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ exports.handler = async (event, context) => {
} else if (event.queryStringParameters?.orcs) {
// Get me a list of this parks' subareas with activities details, including config details
queryObj.ExpressionAttributeValues = {};
queryObj.ExpressionAttributeValues[':pk'] = { S: 'park::' + event.queryStringParameters?.orcs };
queryObj.ExpressionAttributeValues[':pk'] = { S: 'park::'+ event.queryStringParameters?.orcs };
queryObj.KeyConditionExpression = 'pk =:pk';

if (event?.queryStringParameters?.subAreaName) {
// sk for month or a range
queryObj.ExpressionAttributeValues[':sk'] = { S: `${event.queryStringParameters?.subAreaName}` };
if (event?.queryStringParameters?.subAreaId) {
// get specific subarea by subAreaId
queryObj.ExpressionAttributeValues[':sk'] = { S: `${event.queryStringParameters?.subAreaId}` };
queryObj.KeyConditionExpression += ' AND sk =:sk';
}

Expand Down
12 changes: 5 additions & 7 deletions lambda/subarea/GET/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,17 @@ exports.handler = async (event, context) => {
};

try {
if (event?.queryStringParameters?.orcs
&& event?.queryStringParameters?.subAreaName
if (event?.queryStringParameters?.subAreaId
&& event?.queryStringParameters?.activity
&& event?.queryStringParameters?.date) {
// Get the subarea details
const orcs = event.queryStringParameters?.orcs;
const subAreaName = event.queryStringParameters?.subAreaName;
const subAreaId = event.queryStringParameters?.subAreaId;
const activity = event.queryStringParameters?.activity;
const date = event.queryStringParameters?.date;

// Get me a list of this park's subarea details
queryObj.ExpressionAttributeValues = {};
queryObj.ExpressionAttributeValues[':pk'] = { S: `${orcs}::${subAreaName}::${activity}` };
queryObj.ExpressionAttributeValues[':pk'] = { S: `${subAreaId}::${activity}` };
queryObj.ExpressionAttributeValues[':sk'] = { S: `${date}` };

queryObj.KeyConditionExpression = 'pk =:pk AND sk =:sk';
Expand All @@ -35,8 +33,8 @@ exports.handler = async (event, context) => {
let configObj = {
TableName: TABLE_NAME,
ExpressionAttributeValues: {
':pk': { S: `${orcs}::${subAreaName}::${activity}` },
':sk': { S: 'config' }
':pk': { S: `config::${subAreaId}` },
':sk': { S: activity }
},
KeyConditionExpression: 'pk =:pk AND sk =:sk'
};
Expand Down
14 changes: 7 additions & 7 deletions lambda/subarea/POST/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ exports.handler = async (event, context) => {
async function handleActivity(body, context) {
// Set pk/sk
try {
if (!body.orcs || !body.subAreaName || !body.activity || !body.date) {
if (!body.subAreaId || !body.activity || !body.date) {
throw "Invalid request.";
}

const pk = `${body.orcs}::${body.subAreaName}::${body.activity}`;
const pk = `${body.subAreaId}::${body.activity}`;

// Get config to attach to activity
const configObj = {
TableName: TABLE_NAME,
ExpressionAttributeValues: {
":pk": { S: pk },
":sk": { S: "config" },
":pk": { S: `config::${body.subAreaId}`},
":sk": { S: body.activity },
},
KeyConditionExpression: "pk =:pk AND sk =:sk",
};
Expand Down Expand Up @@ -69,12 +69,12 @@ async function handleConfig(body, context) {
try {
// Set pk/sk

if (!body.orcs || !body.subAreaName || !body.activity) {
if (!body.subAreaId || !body.activity) {
throw "Invalid request.";
}

body["pk"] = `${body.orcs}::${body.subAreaName}::${body.activity}`;
body["sk"] = "config";
body["pk"] = `config::${body.subAreaId}`;
body["sk"] = body.activity;

const newObject = AWS.DynamoDB.Converter.marshall(body);

Expand Down
3 changes: 2 additions & 1 deletion miscellaneous/Example Subareas/Backcountry Cabins.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"pk": "0005::Naiset Cabins::Backcountry Cabins",
"pk": "0271::Backcountry Cabins",
"sk": "202201",
"parkName": "Mount Assiniboine",
"subAreaName": "Naiset Cabins",
"subAreaId":"0271",
"orcs": "0005",
"peopleAdult": 0,
"peopleChild": 0,
Expand Down
3 changes: 2 additions & 1 deletion miscellaneous/Example Subareas/Backcountry Camping.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"pk": "0001::Della Falls::Backcountry Camping",
"pk": "0404::Backcountry Camping",
"sk": "202201",
"parkName": "Strathcona Park",
"subAreaName": "Della Falls",
"subAreaId": "0404",
"orcs": "0001",
"people": 0,
"grossCampingRevenue": 0,
Expand Down
3 changes: 2 additions & 1 deletion miscellaneous/Example Subareas/Boating.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"pk": "0365::Halkett Bay::Boating",
"pk": "0173::Boating",
"sk": "202201",
"parkName": "Halkett Bay Marine Park",
"subAreaName": "Halkett Bay",
"subAreaId": "0173",
"orcs": "0365",
"boatAttendanceNightsOnDock": 0,
"boatAttendanceNightsOnBouys": 0,
Expand Down
3 changes: 2 additions & 1 deletion miscellaneous/Example Subareas/Day Use.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"pk": "0001::Bedwell::Day Use",
"pk": "0421::Bedwell::Day Use",
"sk": "202201",
"parkName": "Strathcona Park",
"subAreaName": "Strathcona Corridor",
"subAreaId": "0421",
"orcs": "0001",
"peopleAndVehiclesTrail": 0,
"peopleAndVehiclesVehicle": 0,
Expand Down
3 changes: 2 additions & 1 deletion miscellaneous/Example Subareas/Frontcountry Cabins.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"pk": "0041::Maple Bay Cabins::Frontcountry Cabins",
"pk": "0086::Frontcountry Cabins",
"sk": "202201",
"parkName": "Cultus Lake Park",
"subAreaName": "Maple Bay Cabins",
"subAreaId": "0086",
"orcs": "0041",
"totalAttendanceParties": 4,
"revenueGrossCamping": 5.55,
Expand Down
3 changes: 2 additions & 1 deletion miscellaneous/Example Subareas/Frontcountry Camping.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"pk": "0001::Bedwell::Frontcountry Camping",
"pk": "0421::Frontcountry Camping",
"sk": "202201",
"campingPartyNightsAttendanceSocial": 0,
"parkName": "Strathcona Park",
Expand All @@ -8,6 +8,7 @@
"otherRevenueGrossSani": 0,
"secondCarsAttendanceSocial": 0,
"subAreaName": "Bedwell",
"subAreaId": "0421",
"secondCarsAttendanceSenior": 0,
"campingPartyNightsAttendanceSenior": 0,
"otherRevenueShower": 0,
Expand Down
3 changes: 2 additions & 1 deletion miscellaneous/Example Subareas/Group Camping.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"pk": "6161::Stoltz Pool::Group Camping",
"pk": "0077::Group Camping",
"sk": "202201",
"parkName": "Cowichan River Park",
"subAreaName": "Stoltz Pool",
"subAreaId": "0077",
"orcs": "6161",
"standardRateGroupsTotalPeopleStandard": 0,
"standardRateGroupsTotalPeopleAdults": 0,
Expand Down
Binary file modified tools/Park Name Comparisons.xlsx
100644 → 100755
Binary file not shown.
Loading

0 comments on commit 16c8050

Please sign in to comment.