Inhaltsverzeichnis

database

Table of Content

Motivation

Die Motivation hinter einer Datenbank im BeuthBot Projekt kommt durch das Problem, dass Benutzer ihre Wünsche immer wieder komplett ausführen müssen.
Als Beispiel: Wenn der Benutzer die Mensa nach veganen Gerichten anfragt, dann muss er das bei der nächsten Anfrage wiederholen.
Die Datenbank soll das Problem beheben und den Benutzern die Möglichkeit bieten ihre Vorlieben zu persistieren, ohne dass diese sich einen extra Account anlegen müssen. Dabei muss darauf geachtet werden, dass in der Zukunft noch neue Services dazu kommen können. Die Architektur und die Datenbank sollten so konzipiert werden, dass neue Details die zu neuen Services gehören gespeichert werden können, ohne dass die Datenbank dazu angepasst werden muss.

Requirements

# Was soll die DB können?

Functional

Non Functional

Referenz WS2019:

User Stories

"Als <Rolle> möchte ich <Ziel/Wunsch>, um <Nutzen>"

Use Cases

BeuthBotDBController«Application»Remember NicknameForget NicknameRemember DetailForget DetailForget All DetailStudent

Klassendiagramm User

Userid: Intnickname: String?details: Dictionary<String, AnyObject>

Technologies

Durch die Anforderung, dass die Details, die zu einem User gespeichert werden sehr variabel sein können, ist von einer relationalen Datenbank wie MySQL o.ä. abzuraten. MongoDB ist eine dokumentenorientierte NoSQL-Datenbank. Mit ihr können Sammlungen von JSON-ähnlichen Dokumenten erstellt und verwaltet werden. So können wir die Daten zu einem User in komplexen Hierarchien verschachteln und erweitern ohne uns Gedanken zu einem Tabellen-Schema machen zu müssen.

docker-compose.ymlMongoDB (Container)DB Controller (Container)

Integration

BeuthBotPersistencegatewaydatabase-containerDB_NAMEUsertelgram-bot

Sequenzdiagramm mit angesteuertem Service

gatewaygatewaydeconcentratordeconcentratordatabasecontrollerdatabasecontrollerdatabasedatabaseserviceserviceRequestResponse (Intent + [Args]Request UserGet UserReturn UserResponses UserRequest (User + [Args])Answer

Sequenzdiagramm nur Datenbank betreffend

gatewaygatewaydeconcentratordeconcentratordatabasecontrollerdatabasecontrollerdatabasedatabaseRequest "Merke dir, dass ich vegetarisch esse."Response (Intent + [Args])Add Detail "vegetarisch"Store "vegetarisch"ResultGW: Result

Nächsten Schritte

Getting Started

Die Datenbank wurde mit Docker erstellt. Um diese zum laufen zu bringen müssen folgende Befehle ausgeführt werden:

# clone the repository
git clone https://github.com/beuthbot/database.git

# go to the folder
cd database

# start the docker container to run the mongodb and its corresponding database microservice
docker-compose up

Windows

Damit es auf Windows funktionieren kann müssen folgende Zeilen in der docker-compose.yml Datei geändert werden:

...
    volumes:
      - mongodata:/data/db # needed for me to run container on Windows 10
      #- ./../.database:/data/db # For Mac/Linux
...
# needed for me to run container on Windows 10
volumes:
  mongodata:

Außerdem muss ein shared Folder existieren, welcher beispielsweise 'mongodb' genannt werden muss, worin sich der Ordner 'data' mit den Unterordnern 'db' und 'configdb' befindet. Die Ordnerstruktur sollte nun wie folgt aussehen:

E:\mongodb
    └───data
          ├───configdb
          └───db

API

Request all Users

Requests all Users in the collection

GET http://localhost:27000/users
Response
{...},
{
  "id": 12345678,
  "nickname": "Alan",
  "details" : {
    "eating_habit" : "vegetarisch",
    "city" : "Berlin"
  }
},
{...}
Error
{
  "error": ...
}

Request User

GET http://localhost:27000/users/<id>
Reponse

Request a single user with the given id.

{
  "id": 12345678,
  "nickname": "Alan",
  "details" : {
    "eating_habit" : "vegetarisch",
    "city" : "Berlin"
  }
}
Error
{
  "error": ...
}

Add / Change Detail

Add/Change a Detaile to/from the User with the given id.

POST http://localhost:27000/users/<id>/detail
Request Body
{
  "detail": "eating_habit",
  "value": "vegetarisch"
}
Reponse

If the operation was successful the error will be set to null and the success will be set to true. If the operation failed an error message will be set and the success will be set to false.

{
  "error": null,
  "success": true | false
}

Delete all Details

Deletes all Details from the User with the given id

DELETE http://localhost:27000/user/<id>/detail?q=<value>
Reponse

If the operation was successful the error will be set to null and the success will be set to true. If the operation failed an error message will be set and the success will be set to false.

{
  "error": null,
  "success": true | false
}

Delete Detail

Deletes one Detail from the User with the given id.

DELETE http://localhost:27000/user/<id>/detail?q=<value>
Reponse

If the operation was successful the error will be set to null and the success will be set to true. If the operation failed an error message will be set and the success will be set to false.

{
  "error": null,
  "success": true | false
}