Showing pictures of the MdBs

This commit is contained in:
vysitor 2025-03-16 21:34:04 +01:00
parent 04b08ad8fa
commit 4064ca42bd
3 changed files with 33 additions and 3 deletions

View file

@ -65,6 +65,11 @@ public class MongoPprUtils {
return agendaItemsCollection;
}
public static MongoCollection<Document> getPicturesCollection() {
if (picturesCollection == null) picturesCollection = MongoDBHandler.getMongoDatabase().getCollection(PICTURES_COLLECTION_NAME);
return picturesCollection;
}
/**
* Create the Speaker Collection and useful indices for it
*/
@ -157,6 +162,24 @@ public class MongoPprUtils {
return p;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Parlamentarier - Picture
/**
*
* @param id : ID des Parlamentariers
* @return Das Foto (als Base64-encoded String)
*/
public static String getParlamentarierPictureByID(String id) {
Document doc = MongoDBHandler.findFirstDocumentInCollection(getPicturesCollection(), "memberId", id);
if (doc == null) {
return null;
} else return doc.getString("base64");
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View file

@ -89,6 +89,7 @@ public class ParlamentarierController {
String id = ctx.pathParam("id");
Logger.info("getParlamentarierDetails, ID = " + id);
// Alle Details des Abgeordnetes (Vor- und Nachname, Geburts- und Sterbeort, Partei, Vita etc.)
ParlamentarierDetails pd = MongoPprUtils.getParlamentarierDetailsByID(id);
Map<String, Object> attributes = new HashMap<>();
@ -101,6 +102,10 @@ public class ParlamentarierController {
attributes.put("speechesPlaceholder", emptyList);
}
// Foto des Abgeordnetes
String picture = MongoPprUtils.getParlamentarierPictureByID(id);
attributes.put("pic", picture);
ctx.render("parlamentarierDetails.ftl", attributes);
}

View file

@ -18,10 +18,12 @@
</header>
<br>
<#if p.primaryFoto??>
<img style="max-width: 400px; height: auto; " src="${p.primaryFoto}" alt="Abgeordneterfoto" >
<br> <br>
<#if pic??>
<img style="max-width: 400px; height: auto;" src="data:image/jpeg;base64,${pic}" alt="Foto von ${p.vorname} ${p.nachname} (${p.partei})" />
<#else>
<h2>(kein Foto verfügbar)</h2>
</#if>
<br> <br>
<main>
<section>