Skip to content

mp343hd/ise25-26_assignment06

 
 

Repository files navigation

CampusCoffee (WS 25/26)

Prerequisites

  • Install Docker Desktop or a compatible open-source alternative such as Rancher Desktop.
  • Install the Temurin JDK 21 and Maven 3.9 either via the provided mise.toml file (see getting started guide for details) or directly via your favorite package manager. If you use mise, run mise trust mise.toml and then mise install in the project root to set up the required tool versions.
  • Install a Java IDE. We recommend IntelliJ, but you are free to use alternatives such as VS Code with suitable extensions.
  • Import the project into your IDE. In IntelliJ, you can do this via File -> New -> Project from Existing Sources. Select the root-level pom.xml and import the project. If you have the mise plugin installed, IntelliJ will ask you to select the appropriate tool versions.
  • Ensure that your IDE as initialized the project correctly, including all src, test, and resources folders.

Build application

First, make sure that the Docker daemon is running. Then, to build the application, run the following command in the command line (or use the Maven integration of your IDE):

mvn clean install

Note: In the dev profile, all repositories are cleared before startup, the initial data is loaded (see LoadInitialData.java).

You can use the quiet mode to suppress most log messages:

mvn clean install -q

Start application (dev)

First, make sure that the Docker daemon is running. Before you start the application, you first need to start a Postgres docker container:

docker run -d --name db -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres -p 5432:5432 postgres:17-alpine

Then, you can start the application:

cd application
mvn spring-boot:run -Dspring-boot.run.profiles=dev

Note: The data source is configured via the application.yaml file.

REST API

You can use curl in the command line to send HTTP requests to the REST API.

POS endpoint

Get POS

All POS:

curl http://localhost:8080/api/pos

POS by ID:

curl http://localhost:8080/api/pos/1 # add valid POS id here

POS by name:

curl http://localhost:8080/api/pos/filter?name=Schmelzpunkt # add valid POS name here

Create POS

Create a POS based on a JSON object provided in the request body:

curl --request POST --header "Content-Type: application/json" --data '{"name":"New Café","description":"Description","type":"CAFE","campus":"ALTSTADT","street":"Hauptstraße","houseNumber":"100","postalCode":69117,"city":"Heidelberg"}' http://localhost:8080/api/pos

Create a POS based on an OpenStreetMap node:

curl --request POST --header "Content-Type: application/json" --data '"ALTSTADT"' http://localhost:8080/api/pos/import/osm/5589879349 # set a valid OSM node ID here

IDs for testing:

  • 5589879349 (Rada Coffee & Rösterei in ALTSTADT)
  • 1864600258 (La Fée in ALTSTADT)
  • 1864600236 (Café Moro in ALTSTADT) --> missing address

See bean validation in action:

curl --header "Content-Type: application/json" --request POST -i --data '{"name":"","description":"","type":"CAFE","campus":"ALTSTADT","street":"Hauptstraße","houseNumber":"100","postalCode":69117,"city":"Heidelberg"}' http://localhost:8080/api/pos

Update POS

Update title and description:

curl --header "Content-Type: application/json" --request PUT --data '{"id":4,"name":"New coffee","description":"Great croissants","type":"CAFE","campus":"ALTSTADT","street":"Hauptstraße","houseNumber":"95","postalCode":69117,"city":"Heidelberg"}' http://localhost:8080/api/pos/4 # set correct POS id here and in the body

Delete POS

Delete POS by ID:

curl --request DELETE -i http://localhost:8080/api/pos/1 # set existing POS ID here

Users endpoint

Get users

All users:

curl http://localhost:8080/api/users

User by ID:

curl http://localhost:8080/api/users/1 # add valid user id here

User by login name:

curl http://localhost:8080/api/users/filter?login_name=jane_doe # add valid user login name here

Create users

curl --header "Content-Type: application/json" --request POST --data '{"loginName":"other_login_name","emailAddress":"[email protected]","firstName":"New","lastName":"Person"}' http://localhost:8080/api/users

See bean validation in action:

curl --header "Content-Type: application/json" --request POST -i --data '{"loginName":"other_login_name!","emailAddress":"other.personATuni-heidelberg.de","firstName":"","lastName":""}' http://localhost:8080/api/users

Update user

Update the login name and the email address:

curl --header "Content-Type: application/json" --request PUT --data '{"id":1,"createdAt":"2025-06-03T12:00:00","updatedAt":"2025-06-03T12:00:00","loginName":"jane_doe_new","emailAddress":"[email protected]","firstName":"Jane","lastName":"Doe"}' http://localhost:8080/api/users/1 # set correct user id here and in the body

Delete user

Delete user by ID:

curl --request DELETE -i http://localhost:8080/api/users/1 # set existing POS ID here

Docker

Building an image from the Dockerfile

docker build -t campus-coffee:latest .

Manually create and run a Docker container based on the created image

First, create a new Docker network named campus-coffee-net, then run a Postgres container and connect it to campus-coffee-net. Finally, run the container with the application (in dev profile, do not use in production), connect it to the network, and configure the application to use the database provided in the started Postgres container.

docker network create campus-coffee-net 2>/dev/null || true
docker rm -f db 2>/dev/null || true
docker run -d --name db --net campus-coffee-net -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres -p 5432:5432 postgres:16-alpine
docker run --net campus-coffee-net -e SPRING_PROFILES_ACTIVE=dev -e SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/postgres -p 8080:8080  -it --rm campus-coffee:latest

Explanation of selected options:

docker run -p 8080:8080 runs the container with port 8080 exposed to the host machine. You can change the port mapping if needed. docker run ... -it runs a container in interactive mode with a pseudo-TTY (terminal). docker run ... --rm automatically removes the container (and its associated resources) if it exists already.

Use Docker compose to run the app container together with the DB container

Build container image:

docker compose build

Delete existing DB container (if you manually created it before):

docker rm -f db 2>/dev/null || true

Create and start containers:

docker compose down && docker compose up

Stop and remove containers and networks:

docker compose down

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Java 98.4%
  • Gherkin 1.3%
  • Other 0.3%