103 lines
3.5 KiB
Java
103 lines
3.5 KiB
Java
|
package org.hso.ecommerce.controller.intern.warehouse;
|
||
|
|
||
|
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.web.bind.annotation.GetMapping;
|
||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||
|
|
||
|
import javax.servlet.http.HttpServletRequest;
|
||
|
import javax.servlet.http.HttpServletResponse;
|
||
|
import java.util.Optional;
|
||
|
|
||
|
@Controller
|
||
|
@RequestMapping("/intern/warehouse/")
|
||
|
public class TodoController {
|
||
|
|
||
|
@Autowired
|
||
|
private final WarehouseBookingRepository warehouseBookingRepository = null;
|
||
|
|
||
|
@GetMapping("todo")
|
||
|
public String accountingWarehouseTodo(
|
||
|
HttpServletRequest request
|
||
|
) {
|
||
|
request.setAttribute("bookings", warehouseBookingRepository.findNotDone());
|
||
|
return "intern/warehouse/todo";
|
||
|
}
|
||
|
|
||
|
|
||
|
@PostMapping("progress/{id}")
|
||
|
public String postProgressId(
|
||
|
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.");
|
||
|
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
|
||
|
return "error/404";
|
||
|
}
|
||
|
|
||
|
if (booking.get().isInProgress) {
|
||
|
response.setStatus(409);
|
||
|
return "intern/warehouse/error_progress_failed";
|
||
|
}
|
||
|
|
||
|
booking.get().isInProgress = true;
|
||
|
warehouseBookingRepository.save(booking.get());
|
||
|
|
||
|
return "redirect:/intern/warehouse/progress/" + id;
|
||
|
}
|
||
|
|
||
|
@PostMapping("progress/{id}/finish")
|
||
|
public String postProgressIdFinish(
|
||
|
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.");
|
||
|
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
|
||
|
return "error/404";
|
||
|
}
|
||
|
|
||
|
booking.get().isInProgress = true;
|
||
|
booking.get().isDone = true;
|
||
|
|
||
|
warehouseBookingRepository.save(booking.get());
|
||
|
|
||
|
return "redirect:/intern/warehouse/todo";
|
||
|
}
|
||
|
|
||
|
@GetMapping("progress/{id}")
|
||
|
public String getProgressId(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.");
|
||
|
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
|
||
|
return "error/404";
|
||
|
}
|
||
|
|
||
|
if (booking.get().isDone) {
|
||
|
request.setAttribute("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!");
|
||
|
}
|
||
|
|
||
|
request.setAttribute("booking", booking.get());
|
||
|
return "intern/warehouse/id_progress";
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|