diff --git a/src/main/java/com/csaba79coder/littersnap/view/LitterViewController.java b/src/main/java/com/csaba79coder/littersnap/view/LitterViewController.java index 644a033..414c33f 100644 --- a/src/main/java/com/csaba79coder/littersnap/view/LitterViewController.java +++ b/src/main/java/com/csaba79coder/littersnap/view/LitterViewController.java @@ -7,9 +7,15 @@ import com.csaba79coder.littersnap.util.Mapper; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.multipart.MultipartFile; +import java.util.Base64; import java.util.List; import java.util.NoSuchElementException; import java.util.UUID; @@ -40,7 +46,6 @@ public String getAllLitters(Model model) { @GetMapping("/{id}") public String getLitterById(@PathVariable("id") UUID id, Model model) { - try { LitterModel litter = litterService.getLitterById(id); model.addAttribute("id", litter.getId()); @@ -51,7 +56,11 @@ public String getLitterById(@PathVariable("id") UUID id, Model model) { model.addAttribute("country", litter.getAddress().getCountry()); model.addAttribute("postcode", litter.getAddress().getPostCode()); model.addAttribute("description", litter.getDescription()); - model.addAttribute("image", litter.getImage()); + + // Convert the byte array to a base64 encoded string + String base64Image = Base64.getEncoder().encodeToString(litter.getImage()); + model.addAttribute("image", base64Image); + model.addAttribute("status", litter.getStatus()); model.addAttribute("view", "litter_details"); return "welcome"; @@ -64,7 +73,11 @@ public String getLitterById(@PathVariable("id") UUID id, Model model) { @GetMapping("/create") public String showAddLitterForm(Model model) { try { - model.addAttribute("litter", new LitterCreateOrModifyModel()); + LitterCreateOrModifyModel litterModel = new LitterCreateOrModifyModel(); + + // Set any other necessary properties in the litterModel object + + model.addAttribute("litter", litterModel); return "litter_add_form"; } catch (NoSuchElementException e) { model.addAttribute("errorMessage", e.getMessage()); @@ -75,7 +88,8 @@ public String showAddLitterForm(Model model) { @PostMapping("/create") public String addNewLitter(@ModelAttribute("litter") LitterCreateOrModifyModel litterModel, @ModelAttribute("address") Address address, - @RequestParam("file") MultipartFile file,Model model) { + @RequestParam("file") MultipartFile file, + Model model) { try { litterService.addNewLitter(litterModel, address, file); return "redirect:/thy/litter"; diff --git a/src/main/resources/templates/litter_details.html b/src/main/resources/templates/litter_details.html index 1cdaebb..3087b27 100644 --- a/src/main/resources/templates/litter_details.html +++ b/src/main/resources/templates/litter_details.html @@ -26,7 +26,7 @@

Description:

Image:

-

+ Litter Image

Status:

diff --git a/src/main/resources/templates/welcome.html b/src/main/resources/templates/welcome.html index 1dc18e9..29f3376 100644 --- a/src/main/resources/templates/welcome.html +++ b/src/main/resources/templates/welcome.html @@ -58,7 +58,7 @@
-
+