-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'release/2.0.0' into master
- Loading branch information
Showing
68 changed files
with
7,200 additions
and
5,808 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# editorconfig.org | ||
root = true | ||
|
||
[*] | ||
indent_size = 2 | ||
indent_style = space | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
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,14 @@ | ||
NODE_ENV=development | ||
|
||
HOST=0.0.0.0 | ||
PORT=3333 | ||
|
||
APP_NAME=calendz-api-calendar | ||
APP_URL=http://${HOST}:${PORT} | ||
# Please generate a new key: | ||
# > $ adonis key:generate | ||
APP_KEY=im_a_secret | ||
|
||
REDIS_HOST=localhost | ||
REDIS_PORT=6379 | ||
REDIS_PASSWORD= |
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,14 @@ | ||
NODE_ENV=testing | ||
|
||
HOST=127.0.0.1 | ||
PORT=4000 | ||
|
||
# APP_NAME=calendz-api-calendar | ||
# APP_URL=http://${HOST}:${PORT} | ||
# # Please generate a new key: | ||
# # > $ adonis key:generate | ||
# APP_KEY= | ||
|
||
REDIS_HOST=localhost | ||
REDIS_PORT=6379 | ||
REDIS_PASSWORD= |
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,21 @@ | ||
module.exports = { | ||
env: { | ||
commonjs: true, | ||
es6: true, | ||
node: true | ||
}, | ||
extends: [ | ||
'standard' | ||
], | ||
globals: { | ||
Atomics: 'readonly', | ||
SharedArrayBuffer: 'readonly', | ||
use: true, | ||
make: true | ||
}, | ||
parserOptions: { | ||
ecmaVersion: 2018 | ||
}, | ||
rules: { | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,16 +1,22 @@ | ||
# editor configuration | ||
.vscode/ | ||
.idea/ | ||
|
||
# app dependencies | ||
node_modules/ | ||
# Node modules | ||
node_modules | ||
|
||
# config | ||
# Adonis directory for storing tmp files | ||
tmp | ||
|
||
# Environment variables, never commit this file | ||
.env | ||
.env.dev | ||
.env.prod | ||
|
||
# coverage | ||
coverage/ | ||
# Code coverage | ||
.nyc_output/ | ||
coverage/ | ||
|
||
# ssh key for deployment | ||
deploy_key | ||
deploy_key.pub | ||
deploy_key.pub |
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
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,21 @@ | ||
'use strict' | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Ace Commands | ||
|-------------------------------------------------------------------------- | ||
| | ||
| The ace file is just a regular Javascript file but with no extension. You | ||
| can call `node ace` followed by the command name and it just works. | ||
| | ||
| Also you can use `adonis` followed by the command name, since the adonis | ||
| global proxies all the ace commands. | ||
| | ||
*/ | ||
|
||
const { Ignitor } = require('@adonisjs/ignitor') | ||
|
||
new Ignitor(require('@adonisjs/fold')) | ||
.appRoot(__dirname) | ||
.fireAce() | ||
.catch(console.error) |
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,69 @@ | ||
'use strict' | ||
|
||
const moment = require('moment') | ||
const Cache = use('Cache') | ||
const Scrapper = use('Scrapper') | ||
const DateUtils = use('DateUtils') | ||
const ScrappingException = use('App/Exceptions/ScrappingException') | ||
const InvalidDateException = use('App/Exceptions/InvalidDateException') | ||
|
||
class DayController { | ||
/** | ||
* Get courses of current day | ||
*/ | ||
async getCurrent ({ request }) { | ||
const { firstname, lastname, ignoreCache } = request.only(['firstname', 'lastname', 'ignoreCache']) | ||
|
||
// get current date and format with moment | ||
const date = moment(new Date()).format('MM/DD/YY') | ||
|
||
// try to retrieve and return data from cache/redis | ||
if (!ignoreCache) { | ||
const data = await Cache.getDay(firstname, lastname, date) | ||
if (data) return data | ||
} | ||
|
||
// if not cached, scrap it | ||
const result = await Scrapper.fetchDay(firstname, lastname, date) | ||
.catch(() => { | ||
/* istanbul ignore next */ | ||
throw new ScrappingException() | ||
}) | ||
|
||
// set scrap result in cache | ||
await Cache.setDay(firstname, lastname, date, result) | ||
|
||
return result | ||
} | ||
|
||
/** | ||
* Get courses of a given day | ||
*/ | ||
async getByDate ({ request, params }) { | ||
const { firstname, lastname, ignoreCache } = request.only(['firstname', 'lastname', 'ignoreCache']) | ||
|
||
// check if date is valid, if yes format it | ||
if (!DateUtils.isValid(params.date)) throw new InvalidDateException() | ||
const date = moment(params.date, 'MM-DD-YYYY').format('MM/DD/YY') | ||
|
||
// try to retrieve and return data from cache/redis | ||
if (!ignoreCache) { | ||
const data = await Cache.getDay(firstname, lastname, date) | ||
if (data) return data | ||
} | ||
|
||
// if not cached, scrap it | ||
const result = await Scrapper.fetchDay(firstname, lastname, date) | ||
.catch(() => { | ||
/* istanbul ignore next */ | ||
throw new ScrappingException() | ||
}) | ||
|
||
// set scrap result in cache | ||
await Cache.setDay(firstname, lastname, date, result) | ||
|
||
return result | ||
} | ||
} | ||
|
||
module.exports = DayController |
Oops, something went wrong.