7
7
import com .csaba79coder .littersnap .util .Mapper ;
8
8
import org .springframework .stereotype .Controller ;
9
9
import 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 ;
11
16
import org .springframework .web .multipart .MultipartFile ;
12
17
18
+ import java .util .Base64 ;
13
19
import java .util .List ;
14
20
import java .util .NoSuchElementException ;
15
21
import java .util .UUID ;
@@ -40,7 +46,6 @@ public String getAllLitters(Model model) {
40
46
41
47
@ GetMapping ("/{id}" )
42
48
public String getLitterById (@ PathVariable ("id" ) UUID id , Model model ) {
43
-
44
49
try {
45
50
LitterModel litter = litterService .getLitterById (id );
46
51
model .addAttribute ("id" , litter .getId ());
@@ -51,7 +56,11 @@ public String getLitterById(@PathVariable("id") UUID id, Model model) {
51
56
model .addAttribute ("country" , litter .getAddress ().getCountry ());
52
57
model .addAttribute ("postcode" , litter .getAddress ().getPostCode ());
53
58
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
+
55
64
model .addAttribute ("status" , litter .getStatus ());
56
65
model .addAttribute ("view" , "litter_details" );
57
66
return "welcome" ;
@@ -64,7 +73,11 @@ public String getLitterById(@PathVariable("id") UUID id, Model model) {
64
73
@ GetMapping ("/create" )
65
74
public String showAddLitterForm (Model model ) {
66
75
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 );
68
81
return "litter_add_form" ;
69
82
} catch (NoSuchElementException e ) {
70
83
model .addAttribute ("errorMessage" , e .getMessage ());
@@ -75,7 +88,8 @@ public String showAddLitterForm(Model model) {
75
88
@ PostMapping ("/create" )
76
89
public String addNewLitter (@ ModelAttribute ("litter" ) LitterCreateOrModifyModel litterModel ,
77
90
@ ModelAttribute ("address" ) Address address ,
78
- @ RequestParam ("file" ) MultipartFile file ,Model model ) {
91
+ @ RequestParam ("file" ) MultipartFile file ,
92
+ Model model ) {
79
93
try {
80
94
litterService .addNewLitter (litterModel , address , file );
81
95
return "redirect:/thy/litter" ;
0 commit comments