# Endpoints

## Session

## Create a session

<mark style="color:green;">`POST`</mark> `http://localhost:8080/session/new`

This endpoint allows you to create a session

#### Query Parameters

| Name   | Type   | Description              |
| ------ | ------ | ------------------------ |
| voters | number | Planed number of voters  |
| name   | string | The name of the session. |

{% tabs %}
{% tab title="201 Session successfully created." %}

```javascript
{
    "session created"
}
```

{% endtab %}
{% endtabs %}

## Change a session

<mark style="color:orange;">`PUT`</mark> `http://localhost:8080/session/update`

This endpoint allows you to change the name of the session.

#### Query Parameters

| Name | Type   | Description                 |
| ---- | ------ | --------------------------- |
| name | string | The new name of the session |
| id   | string | Id of the session to change |

{% tabs %}
{% tab title="202 Session successfully updated " %}

```javascript
{
    "Session updated"
}
```

{% endtab %}
{% endtabs %}

## Start a session

<mark style="color:green;">`POST`</mark> `http://localhost:8080/session/start`

This endpoint allows you to start a session

#### Query Parameters

| Name | Type   | Description                    |
| ---- | ------ | ------------------------------ |
| id   | string | The id of the session to start |

{% tabs %}
{% tab title="202 Session is successfully started" %}

```javascript
{
    "Session is started"
}
```

{% endtab %}
{% endtabs %}

## Close a session

<mark style="color:green;">`POST`</mark> `http://localhost:8080/session/close`

This endpoint allows you to close an open session

#### Query Parameters

| Name | Type   | Description                    |
| ---- | ------ | ------------------------------ |
| id   | string | The id of the session to close |

{% tabs %}
{% tab title="202 Session is successfully closed" %}

```javascript
{
    "Session is closed"
}
```

{% endtab %}
{% endtabs %}

## Get all sessions

<mark style="color:blue;">`GET`</mark> `http://localhost:8080/session`

This endpoint allows you to get all sessions

{% tabs %}
{% tab title="200 The request is successful" %}

```javascript
[ 
    {
        id    : "session Id"
        name  : "name of session"
        voters: "planed voters"
        state : "state of the session"
    }
]
```

{% endtab %}
{% endtabs %}

## Get a session

<mark style="color:blue;">`GET`</mark> `http://localhost:8080/session/:id`

This endpoint allows you to get a specific session

#### Path Parameters

| Name | Type   | Description           |
| ---- | ------ | --------------------- |
| id   | string | The id of the session |

{% tabs %}
{% tab title="200 The request is successful" %}

```javascript
{
        id    : "session Id"
        name  : "name of session"
        voters: "planed voters"
        state : "state of the session"
}
```

{% endtab %}
{% endtabs %}

## Question

## Create a question

<mark style="color:green;">`POST`</mark> `http://localhost:8080/question/new`

This endpoint allows you to create a new question

#### Query Parameters

| Name     | Type   | Description                                   |
| -------- | ------ | --------------------------------------------- |
| session  | string | id of session, where this question belongs to |
| sentense | string | The question to ask                           |

{% tabs %}
{% tab title="201 Question is successfully created" %}

```javascript
{
    "Question created"
}
```

{% endtab %}
{% endtabs %}

## Change a question

<mark style="color:orange;">`PUT`</mark> `http://localhost:8080/question/update`

This endpoint allows you to update a question

#### Query Parameters

| Name     | Type   | Description            |
| -------- | ------ | ---------------------- |
| sentense | string | The new question       |
| id       | string | The id of the question |

{% tabs %}
{% tab title="202 Question#s sentence is successfully updated" %}

```javascript
{
    "Question updated"
}
```

{% endtab %}
{% endtabs %}

## Start a vote

<mark style="color:green;">`POST`</mark> `http://localhost:8080/question/startVote`

This endpoint allows to open the vote for a question

#### Query Parameters

| Name | Type   | Description            |
| ---- | ------ | ---------------------- |
| id   | string | The id of the question |

{% tabs %}
{% tab title="202 Vote is successfully started" %}

```javascript
{
    "Vote is opened"
}
```

{% endtab %}
{% endtabs %}

## Close a vote

<mark style="color:green;">`POST`</mark> `http://localhost:8080/question/closeVote`

This endpoint allows you to close an open vote

#### Query Parameters

| Name | Type   | Description        |
| ---- | ------ | ------------------ |
| id   | string | id of the question |

{% tabs %}
{% tab title="202 Vote is successfully closed" %}

```javascript
{
    "Vote is closed"
}
```

{% endtab %}
{% endtabs %}

## Vote a question

<mark style="color:green;">`POST`</mark> `http://localhost:8080/question/vote`

This endpoint allows you to vote a question

#### Query Parameters

| Name     | Type   | Description                     |
| -------- | ------ | ------------------------------- |
| user     | string | user id of the voter            |
| decision | string | Yes or No or NoIdea             |
| question | string | The id of the to voted question |

{% tabs %}
{% tab title="202 User successfully voted" %}

```javascript
{
    "success"
}
```

{% endtab %}
{% endtabs %}

## Get a question

<mark style="color:blue;">`GET`</mark> `http://localhost:8080/question/:question`

This method allows you to request a question by its id

#### Path Parameters

| Name     | Type   | Description        |
| -------- | ------ | ------------------ |
| question | string | id of the question |

{% tabs %}
{% tab title="200 Success" %}

```javascript
{ 
       id : "question Id" 
       sentence : "The question to ask."
       Yes : ["user id"] 
       No : ["user id"]
       NoIdea : ["user id"]
       Voted : true or flase
       Session : "session id" 
 }
```

{% endtab %}
{% endtabs %}

## Get all questions of a session

<mark style="color:blue;">`GET`</mark> `http://localhost:8080/question/:session`

This endpoint allows you to request all questions of a specific session

#### Path Parameters

| Name    | Type   | Description                                |
| ------- | ------ | ------------------------------------------ |
| session | string | id of the session containing the questions |

{% tabs %}
{% tab title="200 Success" %}

```javascript
[
    {
        id        :"question id"
        sentense  : "the question"
        yes       : ["user id"]
        no        : ["user id"]
        noIdea    : ["user id"]
        voted     : true or false
        session    : "session id"
    }
]
```

{% endtab %}
{% endtabs %}
