2019-11-19 19:34:57 +01:00
package org.hso.ecommerce.app ;
2020-01-20 20:22:37 +01:00
import org.hso.ecommerce.contoller.Login ;
2019-12-08 17:16:17 +01:00
import org.hso.ecommerce.db.CustomerRepository ;
import org.hso.ecommerce.entities.Customer ;
2020-01-05 01:41:45 +01:00
import org.springframework.beans.factory.annotation.Autowired ;
2019-11-19 19:34:57 +01:00
import org.springframework.stereotype.Controller ;
import org.springframework.ui.Model ;
2019-12-08 12:24:28 +01:00
import org.springframework.web.bind.annotation.* ;
import javax.servlet.http.Cookie ;
2020-03-06 15:19:56 +01:00
import javax.servlet.http.HttpServletRequest ;
2019-12-08 12:24:28 +01:00
import javax.servlet.http.HttpServletResponse ;
import java.util.UUID ;
2019-11-19 19:34:57 +01:00
2020-01-15 10:55:24 +01:00
/ * *
* TODO clean up this class
* /
2019-11-19 19:34:57 +01:00
@Controller
2019-11-26 16:21:29 +01:00
public class RequestController {
2019-11-19 19:34:57 +01:00
2020-02-03 20:53:02 +01:00
static int notSoRandom = 0 ;
2019-11-26 16:21:29 +01:00
@GetMapping ( " / " )
2020-01-23 19:08:04 +01:00
public String home ( ) {
return " redirect:/shop/ " ;
2019-11-19 19:34:57 +01:00
}
2020-01-23 19:08:04 +01:00
@GetMapping ( " /login " )
public String login ( ) {
2020-02-09 15:00:07 +01:00
return " login " ;
2019-11-25 16:15:36 +01:00
}
2020-01-25 20:30:26 +01:00
@PostMapping ( " /login " )
2020-02-11 23:36:34 +01:00
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:/ " ;
}
2020-01-25 20:30:26 +01:00
}
2020-01-25 22:13:26 +01:00
@PostMapping ( " /logout " )
public String logoutPost ( HttpServletResponse response ) {
response . addCookie ( new Cookie ( " login " , " false " ) ) ;
return " redirect:/ " ;
}
2020-01-23 19:08:04 +01:00
@GetMapping ( " /register " )
public String register ( ) {
2020-02-09 15:00:07 +01:00
return " register " ;
2020-01-15 10:55:24 +01:00
}
2020-01-11 16:39:34 +01:00
2020-01-23 19:08:04 +01:00
@GetMapping ( " /shop/ " )
public String shop ( ) {
2020-02-09 15:00:07 +01:00
return " shop/index " ;
2020-01-18 15:34:54 +01:00
}
2020-01-23 19:08:04 +01:00
@GetMapping ( " /shop/search " )
public String shopSearch ( ) {
2020-02-09 15:00:07 +01:00
return " shop/search " ;
2020-01-15 10:55:24 +01:00
}
2020-01-11 16:39:34 +01:00
2020-01-25 20:30:26 +01:00
@GetMapping ( " /shop/checkout " )
public String shopCheckout ( ) {
2020-02-09 15:00:07 +01:00
return " shop/checkout " ;
2020-01-25 20:30:26 +01:00
}
@PostMapping ( " /shop/checkoutFinish " )
public String shopCheckoutFinish ( ) {
2020-02-09 15:00:07 +01:00
return " shop/checkoutFinish " ;
2020-01-25 20:30:26 +01:00
}
@GetMapping ( " /shop/checkoutFinish " )
public String shopCheckoutFinishGET ( ) {
2020-02-09 15:00:07 +01:00
return " shop/checkoutFinish " ;
2020-01-25 20:30:26 +01:00
}
2020-01-23 19:08:04 +01:00
@GetMapping ( " /shop/articles/{id} " )
public String shopArticlesById ( ) {
2020-02-09 15:00:07 +01:00
return " shop/articles/id " ;
2020-01-22 19:27:45 +01:00
}
2020-01-16 21:01:15 +01:00
2020-01-25 20:30:26 +01:00
@PostMapping ( " /shop/articles/{id} " )
2020-03-06 15:19:56 +01:00
public String shopArticlesByIdBuy ( @RequestAttribute ( " customer " ) Boolean isCustomer , @PathVariable ( " id " ) Integer id , @RequestParam ( " fastcheckout " ) Boolean fastcheckout ) {
2020-02-11 23:36:34 +01:00
if ( isCustomer ) {
2020-03-06 15:19:56 +01:00
if ( ! fastcheckout ) {
return " shop/articles/post_add " ;
} else {
return " shop/checkout " ;
}
2020-02-11 23:36:34 +01:00
} else {
return " redirect:/login?goto=%2Fshop%2Farticles%2F " + id ;
}
2020-01-25 20:30:26 +01:00
}
2020-01-23 19:08:04 +01:00
@GetMapping ( " /about " )
public String about ( ) {
2020-02-09 15:00:07 +01:00
return " about " ;
2020-01-15 10:55:24 +01:00
}
2020-01-23 19:08:04 +01:00
@GetMapping ( " /terms " )
public String terms ( ) {
2020-02-09 15:00:07 +01:00
return " terms " ;
2020-01-19 18:46:32 +01:00
}
2020-01-23 19:08:04 +01:00
@GetMapping ( " /privacy " )
public String privacy ( ) {
2020-02-09 15:00:07 +01:00
return " privacy " ;
2020-01-22 19:27:45 +01:00
}
2020-01-20 20:59:35 +01:00
2020-01-23 19:08:04 +01:00
@GetMapping ( " /intern/ " )
public String intern ( ) {
2020-02-09 15:00:07 +01:00
return " intern/index " ;
2020-01-22 19:27:45 +01:00
}
2020-01-20 20:59:35 +01:00
2020-01-23 19:08:04 +01:00
@GetMapping ( " /intern/listedArticles/ " )
public String internListedArticles ( ) {
2020-02-09 15:00:07 +01:00
return " intern/listedArticles/index " ;
2020-01-22 19:27:45 +01:00
}
2020-02-01 23:43:44 +01:00
@GetMapping ( " /intern/listedArticles/{id} " )
public String internListedArticlesId ( ) {
2020-02-09 15:00:07 +01:00
return " intern/listedArticles/id " ;
2020-02-01 23:43:44 +01:00
}
2020-01-23 19:08:04 +01:00
@GetMapping ( " /intern/articles/ " )
public String internArticles ( ) {
2020-02-09 15:00:07 +01:00
return " intern/articles/index " ;
2020-01-22 19:27:45 +01:00
}
2020-01-20 20:59:35 +01:00
2020-01-23 19:08:04 +01:00
@GetMapping ( " /intern/articles/{id} " )
public String internArticlesId ( ) {
2020-02-09 15:00:07 +01:00
return " intern/articles/id " ;
2020-01-22 19:27:45 +01:00
}
2020-01-20 20:59:35 +01:00
2020-01-23 19:08:04 +01:00
@GetMapping ( " /intern/customers/ " )
public String internCustomers ( ) {
2020-02-09 15:00:07 +01:00
return " intern/customers/index " ;
2020-01-22 19:27:45 +01:00
}
2020-01-20 20:59:35 +01:00
2020-01-23 19:08:04 +01:00
@GetMapping ( " /intern/customers/{id} " )
public String internCustomersId ( ) {
2020-02-09 15:00:07 +01:00
return " intern/customers/id " ;
2020-01-15 10:55:24 +01:00
}
2020-01-23 19:08:04 +01:00
@GetMapping ( " /intern/customerOrders/ " )
public String internCustomerOrder ( ) {
2020-02-09 15:00:07 +01:00
return " intern/customerOrders/index " ;
2020-01-22 19:27:45 +01:00
}
2020-01-23 19:08:04 +01:00
@GetMapping ( " /intern/customerOrders/{id} " )
public String internCustomerOrdersId ( ) {
2020-02-09 15:00:07 +01:00
return " intern/customerOrders/id " ;
2020-01-22 19:27:45 +01:00
}
2020-01-23 19:08:04 +01:00
@GetMapping ( " /intern/suppliers/ " )
public String internSuppliers ( ) {
2020-02-09 15:00:07 +01:00
return " intern/suppliers/index " ;
2020-01-15 10:55:24 +01:00
}
2020-01-12 19:42:04 +01:00
2020-01-23 19:08:04 +01:00
@GetMapping ( " /intern/suppliers/{id} " )
public String internSuppliersId ( ) {
2020-02-09 15:00:07 +01:00
return " intern/suppliers/id " ;
2019-12-08 17:16:17 +01:00
}
2020-01-22 19:27:45 +01:00
2020-01-23 19:08:04 +01:00
@GetMapping ( " /intern/supplierOrders/ " )
public String internSupplierOrders ( ) {
2020-02-09 15:00:07 +01:00
return " intern/supplierOrders/index " ;
2019-12-08 17:16:17 +01:00
}
2019-12-08 12:24:28 +01:00
2020-01-23 19:08:04 +01:00
@GetMapping ( " /intern/supplierOrders/{id} " )
public String internSupplierOrdersId ( ) {
2020-02-09 15:00:07 +01:00
return " intern/supplierOrders/id " ;
2019-12-08 17:16:17 +01:00
}
2020-01-23 19:08:04 +01:00
@GetMapping ( " /intern/accounting/ " )
public String accounting ( ) {
2020-02-09 15:00:07 +01:00
return " intern/accounting/index " ;
2020-01-23 19:08:04 +01:00
}
2019-12-08 17:16:17 +01:00
2020-01-23 19:08:04 +01:00
@GetMapping ( " /intern/accounting/vat " )
public String accountingVat ( ) {
2020-02-09 15:00:07 +01:00
return " intern/accounting/vat " ;
2019-12-08 12:24:28 +01:00
}
2020-01-27 20:37:54 +01:00
@GetMapping ( " /intern/accounting/main " )
2020-01-23 19:08:04 +01:00
public String accountingIntern ( ) {
2020-02-09 15:00:07 +01:00
return " intern/accounting/main " ;
2020-01-15 10:55:24 +01:00
}
2020-01-23 19:08:04 +01:00
@GetMapping ( " /intern/accounting/addManual " )
public String accountingAddManual ( ) {
2020-02-09 15:00:07 +01:00
return " intern/accounting/addManual " ;
2020-01-15 10:55:24 +01:00
}
2020-01-23 19:08:04 +01:00
@GetMapping ( " /intern/warehouse/ " )
public String accountingWarehouse ( ) {
2020-02-09 15:00:07 +01:00
return " intern/warehouse/index " ;
2020-02-03 20:53:02 +01:00
}
@GetMapping ( " /intern/warehouse/todo " )
public String accountingWarehouseTodo ( ) {
2020-02-09 15:00:07 +01:00
return " intern/warehouse/todo " ;
2020-01-15 10:55:24 +01:00
}
2020-01-23 19:08:04 +01:00
@GetMapping ( " /intern/warehouse/addManual " )
public String accountingWarehouseAddManual ( ) {
2020-02-09 15:00:07 +01:00
return " intern/warehouse/addManual " ;
2020-01-23 19:08:04 +01:00
}
2020-02-03 20:53:02 +01:00
@PostMapping ( " /intern/warehouse/progress/{id} " )
public String accountingWarehouseProgressIdPost ( HttpServletResponse response ) {
if ( ( notSoRandom + + ) % 2 = = 1 ) {
return " redirect:/intern/warehouse/progress/450 " ;
} else {
response . setStatus ( 409 ) ;
2020-02-09 15:00:07 +01:00
return " intern/warehouse/error_progress_failed " ;
2020-02-03 20:53:02 +01:00
}
}
@GetMapping ( " /intern/warehouse/progress/{id} " )
public String accountingWarehouseProgressId ( ) {
2020-02-09 15:00:07 +01:00
return " intern/warehouse/id_progress " ;
2020-02-03 20:53:02 +01:00
}
@GetMapping ( " /intern/warehouse/slots/ " )
public String accountingWarehouseSlots ( ) {
2020-02-09 15:00:07 +01:00
return " intern/warehouse/slots/index " ;
2020-02-03 20:53:02 +01:00
}
2019-11-19 19:34:57 +01:00
}