Use Spring model for template attributes
This commit is contained in:
parent
a192f0ac51
commit
eb82d05f4f
|
@ -3,6 +3,7 @@ package org.hso.ecommerce.controller.intern;
|
|||
import org.hso.ecommerce.repos.warehouse.WarehouseBookingRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
|
@ -17,9 +18,10 @@ public class WarehouseController {
|
|||
|
||||
@GetMapping("/")
|
||||
public String accountingWarehouse(
|
||||
Model model,
|
||||
HttpServletRequest request
|
||||
) {
|
||||
request.setAttribute("bookings", warehouseBookingRepository.findAll());
|
||||
model.addAttribute("bookings", warehouseBookingRepository.findAll());
|
||||
return "intern/warehouse/index";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import org.hso.ecommerce.repos.warehouse.WarehouseBookingPositionSlotEntryReposi
|
|||
import org.hso.ecommerce.repos.warehouse.WarehouseBookingRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
@ -37,17 +38,18 @@ public class ManuelBookingController {
|
|||
|
||||
@GetMapping("addManual")
|
||||
public String warehouseAddManual(
|
||||
HttpServletRequest request
|
||||
Model model
|
||||
) {
|
||||
|
||||
request.setAttribute("articles", articleRepository.findAll());
|
||||
request.setAttribute("slots", slotRepository.findAll());
|
||||
model.addAttribute("articles", articleRepository.findAll());
|
||||
model.addAttribute("slots", slotRepository.findAll());
|
||||
|
||||
return "intern/warehouse/addManual";
|
||||
}
|
||||
|
||||
@PostMapping("addManual")
|
||||
public String warehouseAddMaualPost(
|
||||
Model model,
|
||||
HttpServletRequest request,
|
||||
HttpServletResponse response,
|
||||
@RequestParam("articleId") String articleIdText,
|
||||
|
@ -65,7 +67,7 @@ public class ManuelBookingController {
|
|||
try {
|
||||
articleId = Long.parseLong(articleIdText.split(" - ", 2)[0].trim());
|
||||
} catch (NumberFormatException e) {
|
||||
request.setAttribute("error", "Die Artikel Id konnte nicht erkannt werden.");
|
||||
model.addAttribute("error", "Die Artikel Id konnte nicht erkannt werden.");
|
||||
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
|
||||
return "intern/warehouse/addManual";
|
||||
}
|
||||
|
@ -74,7 +76,7 @@ public class ManuelBookingController {
|
|||
Optional<Article> optionalArticle = articleRepository.findById(articleId);
|
||||
Article article = null;
|
||||
if (!optionalArticle.isPresent()) {
|
||||
request.setAttribute("error", "Der Artikel konnte nicht gefunden werden.");
|
||||
model.addAttribute("error", "Der Artikel konnte nicht gefunden werden.");
|
||||
response.setStatus(HttpServletResponse.SC_EXPECTATION_FAILED);
|
||||
return "intern/warehouse/addManual";
|
||||
} else {
|
||||
|
@ -82,13 +84,13 @@ public class ManuelBookingController {
|
|||
}
|
||||
|
||||
if (amount <= 0) {
|
||||
request.setAttribute("error", "Eine Anzahl <= 0 kann nicht verbucht werden.");
|
||||
model.addAttribute("error", "Eine Anzahl <= 0 kann nicht verbucht werden.");
|
||||
response.setStatus(HttpServletResponse.SC_EXPECTATION_FAILED);
|
||||
return "intern/warehouse/addManual";
|
||||
}
|
||||
|
||||
if (sourceIsSlot == false && destinationIsSlot == false) {
|
||||
request.setAttribute("error", "Jede Buchung benötigt ein Ziel oder eine Quelle.");
|
||||
model.addAttribute("error", "Jede Buchung benötigt ein Ziel oder eine Quelle.");
|
||||
response.setStatus(HttpServletResponse.SC_EXPECTATION_FAILED);
|
||||
return "intern/warehouse/addManual";
|
||||
}
|
||||
|
@ -123,11 +125,11 @@ public class ManuelBookingController {
|
|||
new CreateManuelBookingAction(article, amount, sourceSlot, destinationSlot, reason).finish()
|
||||
);
|
||||
} catch (CreateManuelBookingAction.ArticleSlotConstraintArticleTypeFailedException e) {
|
||||
request.setAttribute("error", "Es befindet sich der falsche Artikeltyp in Quell- oder Ziellagerplatz. ");
|
||||
model.addAttribute("error", "Es befindet sich der falsche Artikeltyp in Quell- oder Ziellagerplatz. ");
|
||||
response.setStatus(HttpServletResponse.SC_EXPECTATION_FAILED);
|
||||
return "intern/warehouse/addManual";
|
||||
} catch (CreateManuelBookingAction.ArticleSlotConstraintFailedException e) {
|
||||
request.setAttribute("error", "Die maximale Anzahl an lagerbaren Artikeln im Ziellagerplatz wurde überschritten.");
|
||||
model.addAttribute("error", "Die maximale Anzahl an lagerbaren Artikeln im Ziellagerplatz wurde überschritten.");
|
||||
response.setStatus(HttpServletResponse.SC_EXPECTATION_FAILED);
|
||||
return "intern/warehouse/addManual";
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import org.hso.ecommerce.repos.warehouse.SlotRepository;
|
|||
import org.hso.ecommerce.repos.warehouse.WarehouseBookingPositionSlotEntryRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
|
@ -25,6 +26,7 @@ public class SlotsController {
|
|||
|
||||
@GetMapping("slots/")
|
||||
public String accountingWarehouseSlots(
|
||||
Model model,
|
||||
HttpServletRequest request
|
||||
) {
|
||||
|
||||
|
@ -36,9 +38,9 @@ public class SlotsController {
|
|||
.getBySlotNum(s.slotNum)
|
||||
.orElseGet(() -> WarehouseBookingPositionSlotEntry.empty(null, s))
|
||||
).collect(Collectors.toList());
|
||||
request.setAttribute("entries", entries);
|
||||
model.addAttribute("entries", entries);
|
||||
|
||||
request.setAttribute("stats", new CalculateWarehouseStatsAction(entries).finish());
|
||||
model.addAttribute("stats", new CalculateWarehouseStatsAction(entries).finish());
|
||||
return "intern/warehouse/slots/index";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import org.hso.ecommerce.entities.warehouse.WarehouseBooking;
|
|||
import org.hso.ecommerce.repos.warehouse.WarehouseBookingRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
@ -23,22 +24,23 @@ public class TodoController {
|
|||
|
||||
@GetMapping("todo")
|
||||
public String accountingWarehouseTodo(
|
||||
HttpServletRequest request
|
||||
Model model
|
||||
) {
|
||||
request.setAttribute("bookings", warehouseBookingRepository.findNotDone());
|
||||
model.addAttribute("bookings", warehouseBookingRepository.findNotDone());
|
||||
return "intern/warehouse/todo";
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("progress/{id}")
|
||||
public String postProgressId(
|
||||
Model model,
|
||||
HttpServletRequest request,
|
||||
HttpServletResponse response,
|
||||
@PathVariable("id") Long id
|
||||
) {
|
||||
Optional<WarehouseBooking> booking = warehouseBookingRepository.findById(id);
|
||||
if (!booking.isPresent()) {
|
||||
request.setAttribute("error", "Die Buchung wurde nicht gefunden.");
|
||||
model.addAttribute("error", "Die Buchung wurde nicht gefunden.");
|
||||
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
|
||||
return "error/404";
|
||||
}
|
||||
|
@ -56,13 +58,14 @@ public class TodoController {
|
|||
|
||||
@PostMapping("progress/{id}/finish")
|
||||
public String postProgressIdFinish(
|
||||
Model model,
|
||||
HttpServletRequest request,
|
||||
HttpServletResponse response,
|
||||
@PathVariable("id") Long id
|
||||
) {
|
||||
Optional<WarehouseBooking> booking = warehouseBookingRepository.findById(id);
|
||||
if (!booking.isPresent()) {
|
||||
request.setAttribute("error", "Die Buchung wurde nicht gefunden.");
|
||||
model.addAttribute("error", "Die Buchung wurde nicht gefunden.");
|
||||
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
|
||||
return "error/404";
|
||||
}
|
||||
|
@ -81,26 +84,27 @@ public class TodoController {
|
|||
}
|
||||
|
||||
@GetMapping("progress/{id}")
|
||||
public String getProgressId(HttpServletRequest request,
|
||||
public String getProgressId(Model model,
|
||||
HttpServletRequest request,
|
||||
HttpServletResponse response,
|
||||
@PathVariable("id") Long id) {
|
||||
Optional<WarehouseBooking> booking = warehouseBookingRepository.findById(id);
|
||||
if (!booking.isPresent()) {
|
||||
request.setAttribute("error", "Die Buchung wurde nicht gefunden.");
|
||||
model.addAttribute("error", "Die Buchung wurde nicht gefunden.");
|
||||
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
|
||||
return "error/404";
|
||||
}
|
||||
|
||||
if (booking.get().isDone) {
|
||||
request.setAttribute("info", "Die Buchung wurde schon abgeschlossen.");
|
||||
model.addAttribute("info", "Die Buchung wurde schon abgeschlossen.");
|
||||
}
|
||||
|
||||
if (!booking.get().isInProgress) {
|
||||
// Only reachable if path is manipulated.
|
||||
request.setAttribute("error", "Die Buchung wurde noch nicht zugewiesen!");
|
||||
model.addAttribute("error", "Die Buchung wurde noch nicht zugewiesen!");
|
||||
}
|
||||
|
||||
request.setAttribute("booking", booking.get());
|
||||
model.addAttribute("booking", booking.get());
|
||||
return "intern/warehouse/id_progress";
|
||||
}
|
||||
|
||||
|
|
Reference in New Issue