77import com .csaba79coder .littersnap .util .Mapper ;
88import org .springframework .stereotype .Controller ;
99import org .springframework .ui .Model ;
10- import org .springframework .web .bind .annotation .*;
10+ import org .springframework .web .bind .annotation .GetMapping ;
11+ import org .springframework .web .bind .annotation .ModelAttribute ;
12+ import org .springframework .web .bind .annotation .PathVariable ;
13+ import org .springframework .web .bind .annotation .PostMapping ;
14+ import org .springframework .web .bind .annotation .RequestMapping ;
15+ import org .springframework .web .bind .annotation .RequestParam ;
1116import org .springframework .web .multipart .MultipartFile ;
1217
18+ import java .util .Base64 ;
1319import java .util .List ;
1420import java .util .NoSuchElementException ;
1521import java .util .UUID ;
@@ -40,7 +46,6 @@ public String getAllLitters(Model model) {
4046
4147 @ GetMapping ("/{id}" )
4248 public String getLitterById (@ PathVariable ("id" ) UUID id , Model model ) {
43-
4449 try {
4550 LitterModel litter = litterService .getLitterById (id );
4651 model .addAttribute ("id" , litter .getId ());
@@ -51,7 +56,11 @@ public String getLitterById(@PathVariable("id") UUID id, Model model) {
5156 model .addAttribute ("country" , litter .getAddress ().getCountry ());
5257 model .addAttribute ("postcode" , litter .getAddress ().getPostCode ());
5358 model .addAttribute ("description" , litter .getDescription ());
54- model .addAttribute ("image" , litter .getImage ());
59+
60+ // Convert the byte array to a base64 encoded string
61+ String base64Image = Base64 .getEncoder ().encodeToString (litter .getImage ());
62+ model .addAttribute ("image" , base64Image );
63+
5564 model .addAttribute ("status" , litter .getStatus ());
5665 model .addAttribute ("view" , "litter_details" );
5766 return "welcome" ;
@@ -64,7 +73,11 @@ public String getLitterById(@PathVariable("id") UUID id, Model model) {
6473 @ GetMapping ("/create" )
6574 public String showAddLitterForm (Model model ) {
6675 try {
67- model .addAttribute ("litter" , new LitterCreateOrModifyModel ());
76+ LitterCreateOrModifyModel litterModel = new LitterCreateOrModifyModel ();
77+
78+ // Set any other necessary properties in the litterModel object
79+
80+ model .addAttribute ("litter" , litterModel );
6881 return "litter_add_form" ;
6982 } catch (NoSuchElementException e ) {
7083 model .addAttribute ("errorMessage" , e .getMessage ());
@@ -75,7 +88,8 @@ public String showAddLitterForm(Model model) {
7588 @ PostMapping ("/create" )
7689 public String addNewLitter (@ ModelAttribute ("litter" ) LitterCreateOrModifyModel litterModel ,
7790 @ ModelAttribute ("address" ) Address address ,
78- @ RequestParam ("file" ) MultipartFile file ,Model model ) {
91+ @ RequestParam ("file" ) MultipartFile file ,
92+ Model model ) {
7993 try {
8094 litterService .addNewLitter (litterModel , address , file );
8195 return "redirect:/thy/litter" ;
0 commit comments