286 lines
7.3 KiB
Java
286 lines
7.3 KiB
Java
package org.hso.ecommerce.app;
|
|
|
|
import org.hso.ecommerce.contoller.Login;
|
|
import org.hso.ecommerce.db.ArticleRepository;
|
|
import org.hso.ecommerce.db.CustomerRepository;
|
|
import org.hso.ecommerce.entities.Article;
|
|
import org.hso.ecommerce.entities.Customer;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.ui.Model;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import javax.servlet.http.Cookie;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import java.util.UUID;
|
|
|
|
/**
|
|
* TODO clean up this class
|
|
*/
|
|
@Controller
|
|
public class RequestController {
|
|
|
|
static int notSoRandom = 0;
|
|
|
|
// TODO move this to a separate controller
|
|
private final ArticleRepository articleRepo;
|
|
|
|
@Autowired
|
|
public RequestController(ArticleRepository articleRepo) {
|
|
this.articleRepo = articleRepo;
|
|
}
|
|
|
|
|
|
@GetMapping("/")
|
|
public String home() {
|
|
return "redirect:/shop/";
|
|
}
|
|
|
|
@GetMapping("/login")
|
|
public String login() {
|
|
return "login";
|
|
}
|
|
|
|
@PostMapping("/login")
|
|
public String loginPost(HttpServletResponse response, @RequestParam(value = "goto", required = false) String gto) {
|
|
response.addCookie(new Cookie("login", "true"));
|
|
|
|
if (gto != null && gto.startsWith("/")) {
|
|
return "redirect:" + gto;
|
|
} else {
|
|
return "redirect:/";
|
|
}
|
|
}
|
|
|
|
@PostMapping("/logout")
|
|
public String logoutPost(HttpServletResponse response) {
|
|
response.addCookie(new Cookie("login", "false"));
|
|
return "redirect:/";
|
|
}
|
|
|
|
@GetMapping("/register")
|
|
public String register() {
|
|
return "register";
|
|
}
|
|
|
|
@GetMapping("/shop/")
|
|
public String shop() {
|
|
return "shop/index";
|
|
}
|
|
|
|
@GetMapping("/shop/search")
|
|
public String shopSearch() {
|
|
return "shop/search";
|
|
}
|
|
|
|
@GetMapping("/shop/checkout")
|
|
public String shopCheckout() {
|
|
return "shop/checkout";
|
|
}
|
|
|
|
@PostMapping("/shop/checkoutFinish")
|
|
public String shopCheckoutFinish() {
|
|
return "shop/checkoutFinish";
|
|
}
|
|
|
|
@GetMapping("/shop/checkoutFinish")
|
|
public String shopCheckoutFinishGET() {
|
|
return "shop/checkoutFinish";
|
|
}
|
|
|
|
@GetMapping("/shop/articles/{id}")
|
|
public String shopArticlesById() {
|
|
return "shop/articles/id";
|
|
}
|
|
|
|
@PostMapping("/shop/articles/{id}")
|
|
public String shopArticlesByIdBuy(@RequestAttribute("customer") Boolean isCustomer, @PathVariable("id") Integer id) {
|
|
if (isCustomer) {
|
|
return "redirect:/shop/checkout";
|
|
} else {
|
|
return "redirect:/login?goto=%2Fshop%2Farticles%2F" + id;
|
|
}
|
|
}
|
|
|
|
@GetMapping("/user/")
|
|
public String user() {
|
|
return "redirect:/user/settings";
|
|
}
|
|
|
|
@GetMapping("/user/settings")
|
|
public String userSettings() {
|
|
return "user/settings";
|
|
}
|
|
|
|
|
|
@GetMapping("/user/orders/")
|
|
public String userOrdeers() {
|
|
return "user/orders/index";
|
|
}
|
|
|
|
@GetMapping("/user/bonuspoints")
|
|
public String userBonuspoints() {
|
|
return "user/bonuspoints";
|
|
}
|
|
|
|
@GetMapping("/user/notifications/")
|
|
public String userNotifications() {
|
|
return "user/notifications/index";
|
|
}
|
|
|
|
@GetMapping("/about")
|
|
public String about() {
|
|
return "about";
|
|
}
|
|
|
|
@GetMapping("/terms")
|
|
public String terms() {
|
|
return "terms";
|
|
}
|
|
|
|
@GetMapping("/privacy")
|
|
public String privacy() {
|
|
return "privacy";
|
|
}
|
|
|
|
|
|
@GetMapping("/intern/")
|
|
public String intern() {
|
|
return "intern/index";
|
|
}
|
|
|
|
@GetMapping("/intern/listedArticles/")
|
|
public String internListedArticles() {
|
|
return "intern/listedArticles/index";
|
|
}
|
|
|
|
@GetMapping("/intern/listedArticles/{id}")
|
|
public String internListedArticlesId() {
|
|
Article article = new Article();
|
|
article.setTitle("Test-Artikel");
|
|
article.setCategory("Ding");
|
|
article.setDescription("Ein einfacher Artikel.");
|
|
article.setRefArticle(123);
|
|
article.setSellingPrice(1000);
|
|
article.setMaxPurchasePrice(5000);
|
|
article.setMaxStock(20);
|
|
article.setCurrentStock(4);
|
|
|
|
articleRepo.save(article);
|
|
System.out.println("Article saved!");
|
|
|
|
return "intern/listedArticles/id";
|
|
}
|
|
|
|
|
|
@GetMapping("/intern/articles/")
|
|
public String internArticles() {
|
|
return "intern/articles/index";
|
|
}
|
|
|
|
@GetMapping("/intern/articles/{id}")
|
|
public String internArticlesId() {
|
|
return "intern/articles/id";
|
|
}
|
|
|
|
@GetMapping("/intern/customers/")
|
|
public String internCustomers() {
|
|
return "intern/customers/index";
|
|
}
|
|
|
|
@GetMapping("/intern/customers/{id}")
|
|
public String internCustomersId() {
|
|
return "intern/customers/id";
|
|
}
|
|
|
|
@GetMapping("/intern/customerOrders/")
|
|
public String internCustomerOrder() {
|
|
return "intern/customerOrders/index";
|
|
}
|
|
|
|
@GetMapping("/intern/customerOrders/{id}")
|
|
public String internCustomerOrdersId() {
|
|
return "intern/customerOrders/id";
|
|
}
|
|
|
|
@GetMapping("/intern/suppliers/")
|
|
public String internSuppliers() {
|
|
return "intern/suppliers/index";
|
|
}
|
|
|
|
@GetMapping("/intern/suppliers/{id}")
|
|
public String internSuppliersId() {
|
|
return "intern/suppliers/id";
|
|
}
|
|
|
|
@GetMapping("/intern/supplierOrders/")
|
|
public String internSupplierOrders() {
|
|
return "intern/supplierOrders/index";
|
|
}
|
|
|
|
@GetMapping("/intern/supplierOrders/{id}")
|
|
public String internSupplierOrdersId() {
|
|
return "intern/supplierOrders/id";
|
|
}
|
|
|
|
@GetMapping("/intern/accounting/")
|
|
public String accounting() {
|
|
return "intern/accounting/index";
|
|
}
|
|
|
|
@GetMapping("/intern/accounting/vat")
|
|
public String accountingVat() {
|
|
return "intern/accounting/vat";
|
|
}
|
|
|
|
@GetMapping("/intern/accounting/main")
|
|
public String accountingIntern() {
|
|
return "intern/accounting/main";
|
|
}
|
|
|
|
@GetMapping("/intern/accounting/addManual")
|
|
public String accountingAddManual() {
|
|
return "intern/accounting/addManual";
|
|
}
|
|
|
|
@GetMapping("/intern/warehouse/")
|
|
public String accountingWarehouse() {
|
|
return "intern/warehouse/index";
|
|
}
|
|
|
|
@GetMapping("/intern/warehouse/todo")
|
|
public String accountingWarehouseTodo() {
|
|
return "intern/warehouse/todo";
|
|
}
|
|
|
|
@GetMapping("/intern/warehouse/addManual")
|
|
public String accountingWarehouseAddManual() {
|
|
return "intern/warehouse/addManual";
|
|
}
|
|
|
|
@PostMapping("/intern/warehouse/progress/{id}")
|
|
public String accountingWarehouseProgressIdPost(HttpServletResponse response) {
|
|
if ((notSoRandom++) % 2 == 1) {
|
|
return "redirect:/intern/warehouse/progress/450";
|
|
} else {
|
|
response.setStatus(409);
|
|
return "intern/warehouse/error_progress_failed";
|
|
}
|
|
}
|
|
|
|
@GetMapping("/intern/warehouse/progress/{id}")
|
|
public String accountingWarehouseProgressId() {
|
|
return "intern/warehouse/id_progress";
|
|
}
|
|
|
|
@GetMapping("/intern/warehouse/error_progress_failed")
|
|
public String err() {
|
|
return "intern/warehouse/error_progress_failed";
|
|
}
|
|
|
|
@GetMapping("/intern/warehouse/slots/")
|
|
public String accountingWarehouseSlots() {
|
|
return "intern/warehouse/slots/index";
|
|
}
|
|
}
|