
# Initializing the project
## Creating the DB
docker run --name postgresdb -e POSTGRES_USER=admin -e POSTGRES_PASSWORD=secret -e POSTGRES_DB=zeromonos -p 5432:5432 -d postgres:latest

<br>

## Testing 
- start docker (with DB)

``` mvn clean test ```

- (tested through jacoco)  

```mvn clean test jacoco:report```


- SonarQube  

```mvn clean verify sonar:sonar -Dsonar.projectKey=zeroMonos -Dsonar.projectName='zeroMonos' -Dsonar.host.url=http://localhost:32768 -Dsonar.token=sqp_ef7ffc2fd2e80a3dc98400cc947717db904c810f ```

zeroMonos2025!


<br>

## Running the project
```mvn spring-boot:run```


<br>

# Endpoints and results

## Create booking (POST)
**http://localhost:8081/citizen**
```json
{
  "citizenName": "Ana",
  "citizenPhone": "912345678",
  "municipality": "Vila Nova de Gaia",
  "description": "TV"
}
```

<details>
<summary>Response</summary>

```json
{
    "id": 1,
    "citizenName": "Ana",
    "citizenPhone": "912345678",
    "municipality": "Vila Nova de Gaia",
    "date": "2025-10-31",
    "time": "17:25:15.9093359",
    "description": "TV",
    "token": "6D2D56",
    "state": "RECEIVED",
    "stateHistory": "[\"RECEIVED@2025-10-31T17:25:15.909335900\"]",
    "lastUpdated": "2025-10-31T17:25:15.9093359"
}
```
</details>

<br>

## Get all bookings (GET)
**http://localhost:8081/staff/bookings**

```json
[
    {
        "id": 1,
        "citizenName": "Ana",
        "citizenPhone": "912345678",
        "municipality": "Vila Nova de Gaia",
        "date": "2025-10-31",
        "time": "17:25:15.909",
        "description": "TV",
        "token": "6D2D56",
        "state": "RECEIVED",
        "stateHistory": "[\"RECEIVED@2025-10-31T17:25:15.909335900\"]",
        "lastUpdated": "2025-10-31T17:25:15.909336"
    },
    {
        "id": 2,
        "citizenName": "Tiago",
        "citizenPhone": "914567876",
        "municipality": "Aguiar da Beira",
        "date": "2025-10-31",
        "time": "17:32:26.391",
        "description": "Fridge",
        "token": "E19F51",
        "state": "RECEIVED",
        "stateHistory": "[\"RECEIVED@2025-10-31T17:32:26.391404\"]",
        "lastUpdated": "2025-10-31T17:32:26.391404"
    }
]
```

<br>


## Get booking by token (GET)
**http://localhost:8081/staff/bookings/6D2D56**

```json
{
    "id": 1,
    "citizenName": "Ana",
    "citizenPhone": "912345678",
    "municipality": "Vila Nova de Gaia",
    "date": "2025-10-31",
    "time": "17:25:15.909",
    "description": "TV",
    "token": "6D2D56",
    "state": "RECEIVED",
    "stateHistory": "[\"RECEIVED@2025-10-31T17:25:15.909335900\"]",
    "lastUpdated": "2025-10-31T17:25:15.909336"
}
```

<br>


## Update state (PUT)
**http://localhost:8081/staff/bookings/6D2D56/state**

```json
"ASSIGNED"
```

<details>
<summary>Response</summary>

```json
{
    "id": 1,
    "citizenName": "Ana",
    "citizenPhone": "912345678",
    "municipality": "Vila Nova de Gaia",
    "date": "2025-10-31",
    "time": "17:25:15.909",
    "description": "TV",
    "token": "6D2D56",
    "state": "ASSIGNED",
    "stateHistory": "[\"RECEIVED@2025-10-31T17:25:15.909335900\", \"ASSIGNED@2025-10-31T17:56:16.612926800\"]",
    "lastUpdated": "2025-10-31T17:56:16.6129268"
}
```
</details>


<br>


## Get booking state history (GET)
**http://localhost:8081/staff/bookings/6D2D56/history**

```json
["RECEIVED@2025-10-31T17:25:15.909335900", "ASSIGNED@2025-10-31T17:56:16.612926800"]
```

<br>


 