Skip to content

Commit

Permalink
prepare for V2 and new features
Browse files Browse the repository at this point in the history
  • Loading branch information
AAP9002 committed Nov 1, 2023
1 parent 9456595 commit 563480b
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 9 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
[![CodeQL](https://github.com/AAP9002/Timetable-ICS-Live-Editor/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/AAP9002/Timetable-ICS-Live-Editor/actions/workflows/github-code-scanning/codeql)
[![.github/workflows/deploy.yml](https://github.com/AAP9002/Timetable-ICS-Live-Editor/actions/workflows/deploy.yml/badge.svg)](https://github.com/AAP9002/Timetable-ICS-Live-Editor/actions/workflows/deploy.yml)
[![GitHub last commit (branch)](https://img.shields.io/github/last-commit/AAP9002/Timetable-ICS-Live-Editor/main?label=Last%20Live%20Publish&logo=iterm2)](https://github.com/AAP9002/Timetable-ICS-Live-Editor/)
[![Website](https://img.shields.io/website?url=https%3A%2F%2Faap9002.github.io%2FTimetable-ICS-Live-Editor%2F&logo=githubpages)](https://aap9002.github.io/Timetable-ICS-Live-Editor/)


![Screenshot from 2023-09-30 11-49-35](https://github.com/AAP9002/Timetable-ICS-Live-Editor/assets/42409957/390a7f9b-e74f-4b9f-89a6-818cba1577e7)
Expand Down Expand Up @@ -29,3 +31,14 @@ Get started at [https://aap9002.github.io/Timetable-ICS-Live-Editor/](https://aa
- [x] Materials Science
- [x] Areospace Engineering
- [x] Physics

# Contributing
## Adding courses
Add courses in allCourses.md
## Adding features
1. Create an issue
1. fork the project
1. create a new branch
1. read ```/server/features/_new_feature_doc.md```
1. add your feature
1. create a pull request
14 changes: 11 additions & 3 deletions server/features/_new_feature_doc.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@


## Implement your feature in its own file in /server/features
```js
// your feature
// @author : your github username
Expand All @@ -18,4 +17,13 @@ function run(cal) {
module.exports = {
run,
};
```
```

## Set up your feature in /server/index.js
- import your code within the commented section 'IMPORT FEATURES'
- Add a switch case for your feature in the performModifications method

## Finally
- add your feature to the README.md
- create a pull request
- once merged, I will add code on the front end to users can enable your feature
82 changes: 76 additions & 6 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,46 @@ var fs = require('fs');
const syncForcedBreakpoint = require('./features/forcedBreakPoint.js')
const replaceTitle = require('./features/replaceCodeName.js')


///////////////////////////////////////////// IMPORT FEATURES END //////////////////////////////////////////////

///////////////////////////////////////////////// FEATURES /////////////////////////////////////////////////////

/**
* perform modification defined by the user in stepsString
* - example of stepsString would be "00-02"
* - each code (e.g. "00") corresponds to one feature
* - perform steps in order
* @param {string} cal
* @param {string} stepsString
* @returns modified cal
*/
function performModifications(cal, stepsString) {

const steps = stepsString.split('-')

for (let i = 0; i < steps.length; i++) {
let step = steps[i];
console.log(step)

switch (step) {
case "00": // replace course code with just course name
cal = replaceTitle.replaceCourseCodesWithNames(cal, courses);
break;
case "01": // replace course code with course code and course name
cal = replaceTitle.replaceCourseCodesWithCodeAndNames(cal, courses);
break;
case "02": // force restyling of calender every 24 hours
cal = syncForcedBreakpoint.run(cal);
break;
default:
console.log("step "+ step + " called but not defined in performModifications switch")
}
}

return cal;
}

/////////////////////////////////////////////// FEATURES END////////////////////////////////////////////////////

/////////////////////////////////////////////////// SETUP /////////////////////////////////////////////////////

Expand Down Expand Up @@ -52,10 +89,9 @@ app.get('/api/v1/:uniqueAPI/tt.ics', function (req, res) {
getTimetable(rebuild).then(cal => {
if (cal != null) {

////// modification steps //////
cal = replaceTitle.replaceCourseCodesWithNames(cal, courses);
cal = syncForcedBreakpoint.run(cal);
//// modification steps end ////
// steps for default V1 modifications
let steps = "00-02"
cal = performModifications(cal, steps);

res.writeHead(200, {
"Content-Type": "text/calendar",
Expand All @@ -81,6 +117,40 @@ app.get('/api/v1/:uniqueAPI/tt.ics', function (req, res) {

////////////////////////////////////////////////// API V1 END ///////////////////////////////////////////////////

/////////////////////////////////////////////////// API V2 /////////////////////////////////////////////////////
app.get('/api/v2/:steps/:uniqueAPIPart1/:uniqueAPIPart2/tt.ics', function (req, res) {
console.log("V2 API hit")

// Decoding a UoM Timetable URL encoded value
const { steps, uniqueAPIPart1, uniqueAPIPart2 } = req.params;

let URL = "https://scientia-eu-v4-api-d3-02.azurewebsites.net//api/ical/" + uniqueAPIPart1 + "/" + uniqueAPIPart2 + "/timetable.ics";

try {
getTimetable(URL).then(cal => {
if (cal != null) {

cal = performModifications(cal, steps)

res.writeHead(200, {
"Content-Type": "text/calendar",
"Content-Disposition": "attachment; filename=tt.ics"
})
res.end(cal) // return response as download
}
else {
throw ('Calender not received')
}
});
}
catch (e) {
console.log(e);
res.status(500).send("error")
}
});

////////////////////////////////////////////////// API V2 END ///////////////////////////////////////////////////

////////////////////////////////////////////// FUNDAMENTAL METHODS //////////////////////////////////////////////
/**
* Test for valid api url
Expand Down Expand Up @@ -121,4 +191,4 @@ async function getTimetable(timetableUri) {
}
}

////////////////////////////////////////////// FUNDAMENTAL METHODS END //////////////////////////////////////////////
////////////////////////////////////////////// FUNDAMENTAL METHODS END //////////////////////////////////////////////

0 comments on commit 563480b

Please sign in to comment.