Exercise 8 PR #95
|
@ -167,3 +167,25 @@ Date: Sun, 17 Oct 2021 21:32:25 GMT
|
||||||
Internally, this request is mapped to a
|
Internally, this request is mapped to a
|
||||||
[TaskExecutedEvent](src/main/java/ch/unisg/tapastasks/tasks/application/port/in/TaskExecutedEvent.java).
|
[TaskExecutedEvent](src/main/java/ch/unisg/tapastasks/tasks/application/port/in/TaskExecutedEvent.java).
|
||||||
The HTTP response returns a `200 OK` status code together with the updated representation of the task.
|
The HTTP response returns a `200 OK` status code together with the updated representation of the task.
|
||||||
|
|
||||||
|
## Working with MongoDB
|
||||||
|
The provided TAPAS Tasks service is connected to a MongoDB as a repository for persisting data.
|
||||||
|
|
||||||
|
Here are some pointers to start integrating the MongoDB with the other microservices:
|
||||||
|
* [application.properties](src/main/resources/application.properties) defines the
|
||||||
|
* URI of the DB server that Spring will connect to (`mongodb`service running in Docker container). Username and password for the server can be found in [docker-compose.yml](../docker-compose.yml).
|
||||||
|
* Name of the database for the microservice (`tapas-tasks`)
|
||||||
|
* [docker-compose.yml](../docker-compose.yml) defines
|
||||||
|
* in lines 74-82: the configuration of the mongodb service based on the mongodb container including the root username and password (once deployed this cannot be changed anymore!)
|
||||||
|
* in lines 84-102: the configuration of a web application called `mongo-express` to manage the MongoDB server. The web app can be reached via the URI: [http://dbadmin.${PUB_IP}.nip.io]([http://dbadmin.${PUB_IP}.nip.io]). Login credentials for mongo-express can be found in lines 89 and 90.
|
||||||
|
* in lines 104-105: the volume to be used by the mongodb service for writing and storing data (do not forget!).
|
||||||
|
* The [pom.xml](./pom.xml) needs to have `spring-boot-starter-data-mongodb` and `spring-data-mongodb` as new dependencies.
|
||||||
|
* The [TapasTasksApplication.java](/src/main/java/ch/unisg/tapastasks/TapasTasksApplication.java) specifies in line 9 the location of the MongoRepository classes for the microservice.
|
||||||
|
* The [persistence.mongodb](/src/main/java/ch/unisg/tapastasks/tasks/adapter/out/persistence/mongodb) package has the relevant classes to work with MongoDB:
|
||||||
|
* The [MongoTaskDocument.java](/src/main/java/ch/unisg/tapastasks/tasks/adapter/out/persistence/mongodb/MongoTaskDocument.java) class defines the attributes of a Document for storing a task in the collection `tasks`.
|
||||||
|
* The [TaskRepository.java](/src/main/java/ch/unisg/tapastasks/tasks/adapter/out/persistence/mongodb/TaskRepository.java) class specifies the MongoRepository.
|
||||||
|
* The [TaskPersistenceAdapter.java](/src/main/java/ch/unisg/tapastasks/tasks/adapter/out/persistence/mongodb/TaskPersistenceAdapter.java) implements the two ports to add a new task ([AddTaskPort](/src/main/java/ch/unisg/tapastasks/tasks/application/port/out/AddTaskPort.java)) and retrieve a task ([LoadTaskPort](/src/main/java/ch/unisg/tapastasks/tasks/application/port/out/LoadTaskPort.java)). These ports are used in the classes [AddNewTaskToTaskListService.java](/src/main/java/ch/unisg/tapastasks/tasks/application/service/AddNewTaskToTaskListService.java) and [RetrieveTaskFromTaskListService.java](/src/main/java/ch/unisg/tapastasks/tasks/application/service/RetrieveTaskFromTaskListService.java).
|
||||||
|
|
||||||
|
#### General hints:
|
||||||
|
* To not overload the VMs we recommend to use only one MongoDB server that all microservices connect to. Per microservice you could use one database or one collection (discuss in your ADRs!). To use more than one MongoDB server you have to extend the [docker-compose.yml](../docker-compose.yml) file by basically replicating lines 74-105 and changing the names of the services and volumes to be unique (ask your tutors!).
|
||||||
|
* For local testing you have to install the MongoDB server locally on your computers and change the `spring.data.mongodb.uri` String in [application.properties](./src/main/resources/application.properties).
|
||||||
|
|
Loading…
Reference in New Issue
Block a user