Skip to content

Commit 667e668

Browse files
Merge pull request #11 from Csaba79-coder/master
Merge master into developer (image solved!)
2 parents 337fb36 + 3a1fb19 commit 667e668

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

src/main/java/com/csaba79coder/littersnap/view/LitterViewController.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,15 @@
77
import com.csaba79coder.littersnap.util.Mapper;
88
import org.springframework.stereotype.Controller;
99
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;
1116
import org.springframework.web.multipart.MultipartFile;
1217

18+
import java.util.Base64;
1319
import java.util.List;
1420
import java.util.NoSuchElementException;
1521
import 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";

src/main/resources/templates/litter_details.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ <h4><span class="text-muted">Description:</span></h4>
2626
<p><span th:text="${description}"></span></p>
2727

2828
<h4><span class="text-muted">Image:</span></h4>
29-
<p><span th:text="${image}"></span></p>
29+
<img th:src="@{'data:image/png;base64,' + ${image}}" alt="Litter Image" />
3030

3131
<h4><span class="text-muted">Status:</span></h4>
3232
<p><span th:text="${status}"></span></p>

src/main/resources/templates/welcome.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
<div th:if="~{${view}}" class="row m-4">
5959
<div class="col">
6060
<!-- Dynamic Content Placeholder -->
61-
<div th:include="~{${view}}"></div>
61+
<div th:insert="~{${view}}"></div>
6262

6363
</div>
6464
</div>

0 commit comments

Comments
 (0)