Skip to content

Commit

Permalink
API and code refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
emagnier committed Feb 24, 2020
1 parent b657385 commit 735ed32
Show file tree
Hide file tree
Showing 65 changed files with 5,441 additions and 5,049 deletions.
53 changes: 22 additions & 31 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,29 @@
module.exports = {
parser: '@typescript-eslint/parser',
plugins: [
'@typescript-eslint'
parserOptions: {
project: 'tsconfig.json',
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin'],
extends: [
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'prettier',
'prettier/@typescript-eslint',
],
extends: 'airbnb-base',
settings: {
'import/extensions': ['.js','.jsx','.ts','.tsx'],
'import/parsers': {
'@typescript-eslint/parser': ['.ts','.tsx']
},
'import/resolver': {
'node': {
'extensions': ['.js','.jsx','.ts','.tsx']
}
}
root: true,
env: {
node: true,
jest: true,
},
rules: {
'padded-blocks': ['error', {
blocks: 'never',
classes: 'never',
switches: 'never',
}, {
allowSingleLineBlocks: true,
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'max-len': ["error", {
"code": 120,
"comments": 120,
"ignoreRegExpLiterals": true,
}],
'import/extensions': [
'error',
'ignorePackages',
{
'js': 'never',
'jsx': 'never',
'ts': 'never',
'tsx': 'never'
}
],
'max-len': 120
}
},
};
46 changes: 33 additions & 13 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,16 +1,36 @@
# package directories and files
node_modules
jspm_packages
npm-debug.log
dist
# compiled output
/.serverless
/dist
/node_modules

# Serverless directories
.serverless
dist
# Logs
logs
*.log
.eslintcache
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Webpack directories
.webpack
# OS
.DS_Store

# Others
**.DS_Store**
.eslintcache
# Tests
/coverage
/.nyc_output

# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ webpack.config.js
serverless.yml
_config.yml
jest.config.js
coverage
apidoc
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"singleQuote": true,
"trailingComma": "all",
"quoteProps": "consistent",
"printWidth": 120,
}
44 changes: 22 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ With romcal-api installed, add the application code in the `handler.js`:
// handler.js

const romcalAPI = require('romcal-api');
module.exports.romcalAPI = romcalAPI.handler;
module.exports.romcalHandler = romcalAPI.handler;
```

Sample settings and romcal function to add in the `serverless.yml`:
Expand All @@ -103,8 +103,8 @@ provider:
runtime: nodejs12.x

functions:
app:
handler: handler.romcalAPI
romcal:
handler: handler.romcalHandler
events:
- http: ANY /
- http: 'ANY {proxy+}'
Expand All @@ -119,21 +119,21 @@ $ sls deploy

You can use tools like [Postman](https://www.getpostman.com/) to play with the API.

### <a name="getCalendars"></a> List all available calendars
### <a name="getCalendars"></a> Get all available calendars

- Get all calendars `GET /calendars`

Output an `Array` of calendar names, supported by romcal.

### <a name="getLocales"></a> List all supported locales
### <a name="getLocales"></a> Get all supported locales

- Get all locales `GET /locales`

Output an `Array` of locales keys, supported by romcal.

### <a name="getCalendar"></a> Get calendar data

- Get celebrations `GET /calendar/{name}/{locale}/{date}`
### <a name="getCalendar"></a> Get the celebrations over a specific period

Output an `Object` where the `celebrations` property contains an `Array` of celebrations ordered by date. For all endpoints:

Expand All @@ -146,15 +146,16 @@ However another [specific endpoint](#getLocales) is available to get the list of

| `{date}`: Get celebrations... | Endpoint
|---|---
| For the current year: | `GET /calendar/{name}/{locale}`
| For a specific year: | `GET /calendar/{name}/{locale}/{YYYY}`
| For a specific month within a year: | `GET /calendar/{name}/{locale}/{YYYY-MM}`
| For a specific date: | `GET /calendar/{name}/{locale}/{YYYY-MM-DD}`
| For yesterday: | `GET /calendar/{name}/{locale}/yesterday`
| For today: | `GET /calendar/{name}/{locale}/today`
| For tomorrow: | `GET /calendar/{name}/{locale}/tomorrow`
| For a specific liturgical period within a year: <br> _The `period` key is described below this table._ | `GET /calendar/{name}/{locale}/{YYYY-period}`
| For a date that matches a given liturgical celebration within a year: <br> _The `celebration-lookup` is described below this table.<br>Not fully supported yet_ | `GET /calendar/{name}/{locale}/{YYYY-celebration-lookup}` <br>&nbsp;
| For the current civil year: | `GET /calendars/{name}/{locale}`
| For a specific civil year: | `GET /calendars/{name}/{locale}/{YYYY}`
| For a specific liturgical year: | `GET /calendars/{name}/{locale}/{YYYY-YYYY}`
| For a specific month within a year: | `GET /calendars/{name}/{locale}/{YYYY}/{MM}`
| For a specific date: | `GET /calendars/{name}/{locale}/{YYYY}/{MM}/{DD}`
| For yesterday: | `GET /calendars/{name}/{locale}/yesterday`
| For today: | `GET /calendars/{name}/{locale}/today`
| For tomorrow: | `GET /calendars/{name}/{locale}/tomorrow`
| For a specific liturgical period within a year: <br> _The `period` key is described below this table._ | `GET /calendars/{name}/{locale}/{YYYY}/pediod/{period}`
| For a date that matches a given liturgical celebration within a year: <br> _The `celebration-lookup` is described below this table.<br>Not fully supported yet_ | `GET /calendars/{name}/{locale}/{YYYY}/lookup/{celebration-lookup}` <br>&nbsp;

The `period` key name must be written in kebab case.
If the period key name doesn't exist, it will return an error (`404 NOT FOUND`).
Expand All @@ -176,9 +177,9 @@ When dates are computed within a liturgical period, `year` corresponds to the ye

#### → Some examples

- `/calendar/france/fr` return an array of dates from 1 January to 31 December of the current year.
- `/calendar/poland/pl?type=liturgical` return an array of date from the 1st Sunday of Advent to the last Saturday of Ordinary Time of the current liturgical year.
- `/calendar/canada/en/2018-12?type=liturgical` return an array of dates from December 2, 2018 (which is the first day of the liturgical year for 2018-2019) to December 31, 2018.
- `/calendars/france/fr` return an array of dates from 1 January to 31 December of the current year.
- `/calendars/poland/pl?type=liturgical` return an array of date from the 1st Sunday of Advent to the last Saturday of Ordinary Time of the current liturgical year.
- `/calendars/canada/en/2018-12?type=liturgical` return an array of dates from December 2, 2018 (which is the first day of the liturgical year for 2018-2019) to December 31, 2018.

#### → Filtering results

Expand All @@ -187,7 +188,7 @@ Theses optional query strings are available for filtering data directly from the
- `weekday=[int]`: Filter the results on a specific weekday. `0` is Sunday, `6` is Saturday. For example `?weekday=0`.
- `title=[string]`: Filter the results on a specific celebration title. The title needs to be in kebab-case. For example `?title=patron-of-europe`.

You can, of course, combine different filters. For example `/calendar/spain/es?weekday=4&title=martyr`
You can, of course, combine different filters. For example `/calendars/spain/es?weekday=4&title=martyr`

#### → Group results by criteria

Expand Down Expand Up @@ -252,10 +253,8 @@ Note: this step as well as tests are run automatically before releasing a new ve

## <a name="roadmap"></a> Roadmap (non-exclusive)

- [ ] Add full API support for Calendars, Locales, Dates
- [ ] Get dates within a custom range: between 2 dates (civil or liturgical date), or 2 periods (the first day of the first period and the last day of the 2nd period)
- [ ] Replace Express by Fastify or Koa -> they are more modern (but still very mature), highly maintained and focus on speed.
- [ ] Move to GraphQL (or support both REST API and GraphQL)
- [ ] Support GraphQL
- [ ] Support date offset to manage different time zones between clients and the back-end API
- [ ] Support Docker
- [ ] More tests
Expand All @@ -265,6 +264,7 @@ Note: this step as well as tests are run automatically before releasing a new ve

## History

- 1.2.0 Update the Rest API (please check the documentation) & Code refactor.
- 1.1.0 Update romcal dependency. API change, the returned data is now an `Object` that contains the celebrations in a specific `celebrations` property. On each celebration, the `moment` property is renamed to `date`.
- 1.0.6 Calendar refactor and a lot of new tests added. Bug fixes.
- 1.0.5 Add new calendar tests and fix bugs. Fix the nodemon debug mode.
Expand Down
1 change: 0 additions & 1 deletion _config.yml

This file was deleted.

6 changes: 6 additions & 0 deletions apidoc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "romcal-api",
"description": "The REST API documentation for romcal.",
"title": "romcal-api - REST API documentation",
"url" : ""
}
Loading

0 comments on commit 735ed32

Please sign in to comment.