new API page in docs

This commit is contained in:
les 2020-02-02 21:08:16 +01:00
parent 2bcf1fc9a0
commit a1073642b5
9 changed files with 185 additions and 10 deletions

57
docs/.api.md Normal file
View file

@ -0,0 +1,57 @@
## Add a new event
POST
{: .label .label-orange}
**`/event`**
> info "info"
> `Content-Type` has to be `multipart/form-data` 'cause support image upload
**Params**
| title | `string` | event's title |
| description | `string` | event's description (html accepted and sanitized) |
| place_name | `string` | the name of the place |
| place_address | `string` | the address of the place |
| start_datetime | `integer` | start timestamp |
| multidate | `integer` | is a multidate event? |
| tags | `array` | List of tags |
| recurrent | `object` | Recurrent event details |
| recurrent.frequency | `string` | could be `1w` or `2w` |
| recurrent.type | `string` | not used |
| recurrent.days | `array` | array of days |
| image | `image` | Image |
---
## Get current authenticated user
GET
{: .label .label-green}
**`/api/user`**
**Response**
```json
{
"description" : null,
"recover_code" : "",
"id" : 1,
"createdAt" : "2020-01-29T18:10:16.630Z",
"updatedAt" : "2020-01-30T22:42:14.789Z",
"is_active" : true,
"settings" : "{}",
"email" : "eventi@cisti.org",
"is_admin" : true
}
```
---

View file

@ -1,6 +1,14 @@
--- ---
layout: default layout: default
title: API title: API
permalink: /api permalink: /dev/api
parent: Hacking
nav_order: 8 nav_order: 8
--- ---
1. TOC
{:toc}

8
docs/.api_helpers.js Normal file
View file

@ -0,0 +1,8 @@
exports.if_eq = function(a, b, opts) {
if (a == b) {
return opts.fn(this);
} else {
return opts.inverse(this);
}
}

View file

@ -1,20 +1,34 @@
{{#orphans}} {{#orphans}}
### {{description}} ## {{description}}
{{type.names}} {{type.names}}
{{#if_eq type.names 'POST'}}
{: .label .label-orange}
{{else}}
{: .label .label-green} {: .label .label-green}
{{/if_eq}}
`{{name}}` **`{{name}}`**
{{#each params}}
| {{name}} | `{{type.names}}` | {{{description}}} |
{{/each}}
{{#each customTags}} {{#each customTags}}
> {{tag}} "{{tag}}" > {{tag}} "{{tag}}"
> {{{value}}} > {{{value}}}
{{/each}} {{/each}}
{{#if params}}
**Params**
{{#each params}}
| {{name}} | `{{type.names}}` | {{{description}}} |
{{/each}}
{{/if}}
{{#each examples}}
{{{this}}}
{{/each}}
---
{{/orphans}} {{/orphans}}

View file

@ -4,7 +4,7 @@
} }
.navigation-list-item a { .navigation-list-item a {
color: blue; color: #7253ed;
} }
.navigation-list-item a:hover { .navigation-list-item a:hover {

71
docs/dev/api.md Normal file
View file

@ -0,0 +1,71 @@
---
layout: default
title: API
permalink: /dev/api
parent: Hacking
nav_order: 8
---
1. TOC
{:toc}
## Add a new event
POST
{: .label .label-orange}
**`/event`**
> info "info"
> `Content-Type` has to be `multipart/form-data` 'cause support image upload
**Params**
| title | `string` | event's title |
| description | `string` | event's description (html accepted and sanitized) |
| place_name | `string` | the name of the place |
| place_address | `string` | the address of the place |
| start_datetime | `integer` | start timestamp |
| multidate | `integer` | is a multidate event? |
| tags | `array` | List of tags |
| recurrent | `object` | Recurrent event details |
| recurrent.frequency | `string` | could be `1w` or `2w` |
| recurrent.type | `string` | not used |
| recurrent.days | `array` | array of days |
| image | `image` | Image |
---
## Get current authenticated user
GET
{: .label .label-green}
**`/api/user`**
**Response**
```json
{
"description" : null,
"recover_code" : "",
"id" : 1,
"createdAt" : "2020-01-29T18:10:16.630Z",
"updatedAt" : "2020-01-30T22:42:14.789Z",
"is_active" : true,
"settings" : "{}",
"email" : "eventi@cisti.org",
"is_admin" : true
}
```
---

View file

@ -326,6 +326,9 @@ export default {
min-height: 300px; min-height: 300px;
max-width: 600px; max-width: 600px;
width: 100%; width: 100%;
.el-dialog__body {
word-break: normal;
}
} }
} }

View file

@ -26,6 +26,20 @@ api.use(express.json())
* @category User * @category User
* @name /api/user * @name /api/user
* @type GET * @type GET
* @example **Response**
* ```json
{
"description" : null,
"recover_code" : "",
"id" : 1,
"createdAt" : "2020-01-29T18:10:16.630Z",
"updatedAt" : "2020-01-30T22:42:14.789Z",
"is_active" : true,
"settings" : "{}",
"email" : "eventi@cisti.org",
"is_admin" : true
}
```
*/ */
api.get('/user', isAuth, (req, res) => res.json(req.user)) api.get('/user', isAuth, (req, res) => res.json(req.user))

View file

@ -4,7 +4,7 @@ module.exports = (sequelize, DataTypes) => {
const User = sequelize.define('user', { const User = sequelize.define('user', {
settings: { settings: {
type: DataTypes.JSON, type: DataTypes.JSON,
defaultValue: '{}' defaultValue: []
}, },
email: { email: {
type: DataTypes.STRING, type: DataTypes.STRING,