From 7653d0380cd55590b7b7d904dd872a51279e7f97 Mon Sep 17 00:00:00 2001
From: Florian Meissner <florian.meissner@mailbox.org>
Date: Fri, 23 Jun 2023 16:15:37 +0200
Subject: [PATCH] finished printMeals

---
 src/main/java/ohm/softa/a11/App.java | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/src/main/java/ohm/softa/a11/App.java b/src/main/java/ohm/softa/a11/App.java
index 8639757..b9e4e56 100644
--- a/src/main/java/ohm/softa/a11/App.java
+++ b/src/main/java/ohm/softa/a11/App.java
@@ -4,6 +4,7 @@ import ohm.softa.a11.openmensa.OpenMensaAPI;
 import ohm.softa.a11.openmensa.OpenMensaAPIService;
 import ohm.softa.a11.openmensa.model.Canteen;
 import ohm.softa.a11.openmensa.model.PageInfo;
+import retrofit2.HttpException;
 
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
@@ -109,6 +110,21 @@ public class App {
 		/* TODO fetch all meals for the currently selected canteen
 		 * to avoid errors retrieve at first the state of the canteen and check if the canteen is opened at the selected day
 		 * don't forget to check if a canteen was selected previously! */
+		if (currentCanteenId == -1) {
+			System.out.println("Error: no canteen selected");
+			return;
+		}
+
+		openMensaAPI
+			.getMeals(currentCanteenId, dateFormat.format(currentDate.getTime()))
+			.exceptionally((e) -> {
+				System.out.println(e.getMessage());
+				if (e instanceof HttpException) System.out.println(((HttpException) e).response());
+				return List.of();
+			})
+			.thenAccept(meals -> meals.forEach(System.out::println))
+			.join();
+
 	}
 
 	/**
-- 
GitLab