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 ;
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
2019-12-08 17:16:17 +01:00
private final CustomerRepository customerRepo ;
2020-01-05 01:41:45 +01:00
@Autowired
2019-12-08 17:16:17 +01:00
public RequestController ( CustomerRepository customerRepo ) {
this . customerRepo = customerRepo ;
}
2019-11-26 16:21:29 +01:00
@GetMapping ( " / " )
public String greeting ( ) {
return " redirect:/home " ;
2019-11-19 19:34:57 +01:00
}
2019-11-25 16:15:36 +01:00
@GetMapping ( " /home " )
2020-01-19 18:46:32 +01:00
public String home ( @CookieValue ( value = " loginToken " , defaultValue = " " ) String loginToken , Model model ) {
if ( ! loginToken . equals ( " " ) ) {
model . addAttribute ( new Customer ( ) ) ;
}
2019-11-25 16:15:36 +01:00
return " home " ;
}
2020-01-11 16:39:34 +01:00
@GetMapping ( " /articledetail " )
2020-01-15 10:55:24 +01:00
public String articledetail ( ) {
2020-01-23 18:46:49 +01:00
return " articleDetail " ;
2020-01-15 10:55:24 +01:00
}
2020-01-11 16:39:34 +01:00
@GetMapping ( " /searchresults " )
2020-01-15 10:55:24 +01:00
public String searchresults ( ) {
2020-01-20 20:22:37 +01:00
return " searchResults " ;
2020-01-18 15:34:54 +01:00
}
@GetMapping ( " /shoppingcart " )
public String shoppingcart ( ) {
2020-01-20 20:22:37 +01:00
return " shoppingCart " ;
2020-01-15 10:55:24 +01:00
}
2020-01-11 16:39:34 +01:00
2020-01-16 21:01:15 +01:00
@GetMapping ( " /intern/customerdetail " )
2020-01-22 19:27:45 +01:00
public String customerdetail ( ) {
// TODO @PH
2020-01-16 21:01:15 +01:00
return " intern/customer " ;
2020-01-22 19:27:45 +01:00
}
2020-01-16 21:01:15 +01:00
@GetMapping ( " /intern/customerorders " )
public String customerorders ( ) {
2020-01-22 19:27:45 +01:00
// TODO @PH
2020-01-16 21:01:15 +01:00
return " intern/customerorders " ;
}
@GetMapping ( " /intern/accounting " )
public String accounting ( ) {
return " intern/accounting " ;
}
2020-01-22 19:27:45 +01:00
@GetMapping ( " /intern/accountingvat " )
public String accountingvat ( ) {
return " intern/accountingvat " ;
}
2020-01-16 21:01:15 +01:00
2020-01-22 19:27:45 +01:00
@GetMapping ( " /intern/accountingmain " )
public String accountingmain ( ) {
2020-01-16 21:01:15 +01:00
return " intern/accountingmain " ;
2020-01-22 19:27:45 +01:00
}
2020-01-16 21:01:15 +01:00
2020-01-19 18:43:19 +01:00
@GetMapping ( " /intern/accountingmanual " )
public String accountingmanual ( ) {
return " intern/accountingmanual " ;
}
2020-01-16 21:01:15 +01:00
2020-01-19 18:48:09 +01:00
@GetMapping ( " /intern/addarticle " )
public String addarticle ( ) {
return " intern/addarticle " ;
}
2020-01-16 20:17:48 +01:00
@GetMapping ( " /intern/articles " )
2020-01-15 10:55:24 +01:00
public String articles ( ) {
2020-01-16 20:17:48 +01:00
return " intern/articles " ;
2020-01-15 10:55:24 +01:00
}
2020-01-12 18:00:40 +01:00
2020-01-16 20:17:48 +01:00
@GetMapping ( " /intern/listedarticles " )
2020-01-15 10:55:24 +01:00
public String listedarticles ( ) {
2020-01-16 20:17:48 +01:00
return " intern/listedArticles " ;
2020-01-15 10:55:24 +01:00
}
2020-01-12 18:00:40 +01:00
2020-01-16 20:17:48 +01:00
@GetMapping ( " /intern/listedarticlesedit " )
2020-01-15 10:55:24 +01:00
public String listedarticlesedit ( ) {
2020-01-16 20:17:48 +01:00
return " intern/listedArticlesEdit " ;
2020-01-15 10:55:24 +01:00
}
2020-01-19 18:46:32 +01:00
@GetMapping ( " /notification " )
public String notification ( ) {
return " notification " ;
}
2020-01-20 20:59:35 +01:00
@GetMapping ( " /intern/customers_allOrders_overview " )
2020-01-22 19:27:45 +01:00
public String customers_allOrders_overview ( ) {
return " intern/customers_allOrders_overview " ;
}
2020-01-20 20:59:35 +01:00
@GetMapping ( " /intern/customers_order_detailview " )
2020-01-22 19:27:45 +01:00
public String customers_order_detailview ( ) {
return " intern/customers_order_detailview " ;
}
2020-01-20 20:59:35 +01:00
@GetMapping ( " /intern/customers_overview " )
2020-01-22 19:27:45 +01:00
public String customers_overview ( ) {
return " intern/customers_overview " ;
}
2020-01-20 20:59:35 +01:00
@GetMapping ( " /intern/customers_detailview_bookings_orders " )
2020-01-22 19:27:45 +01:00
public String customers_detailview_bookings_orders ( ) {
return " intern/customers_detailview_bookings_orders " ;
}
2020-01-20 20:59:35 +01:00
@GetMapping ( " /intern/suppliers_overview " )
2020-01-22 19:27:45 +01:00
public String suppliers_overview ( ) {
return " intern/suppliers_overview " ;
}
2020-01-20 20:59:35 +01:00
@GetMapping ( " /intern/suppliers_detailview_bookings_orders " )
2020-01-22 19:27:45 +01:00
public String suppliers_detailview_bookings_orders ( ) {
return " intern/suppliers_detailview_bookings_orders " ;
}
2020-01-20 20:59:35 +01:00
@GetMapping ( " /intern/suppliers_allOrders_overview " )
2020-01-22 19:27:45 +01:00
public String suppliers_allOrders_overview ( ) {
return " intern/suppliers_allOrders_overview " ;
}
2020-01-20 20:59:35 +01:00
@GetMapping ( " /intern/suppliers_order_detailview " )
2020-01-22 19:27:45 +01:00
public String suppliers_order_detailview ( ) {
return " intern/suppliers_order_detailview " ;
}
2020-01-20 20:59:35 +01:00
2020-01-15 10:55:24 +01:00
@GetMapping ( " /customer/accountsettings " )
public String customerAccountSettings ( Model model ) {
Customer customer = new Customer ( ) ;
customer . setFirstname ( " Max " ) ;
customer . setLastname ( " Mustermann " ) ;
customer . setUsername ( " Max.TestKunde " ) ;
customer . setPassword ( " test123 " ) ;
model . addAttribute ( customer ) ;
model . addAttribute ( " fullname " , customer . getFirstname ( ) + " " + customer . getLastname ( ) ) ;
model . addAttribute ( " email " , " Test.User@ecommere.com " ) ;
model . addAttribute ( " street " , " Musterstraße 42a " ) ;
model . addAttribute ( " city " , " Musterstadt " ) ;
model . addAttribute ( " zipcode " , " 12345 " ) ;
model . addAttribute ( " country " , " Musterland " ) ;
2020-01-20 20:22:37 +01:00
return " /customer/accountSettings " ;
2020-01-15 10:55:24 +01:00
}
2020-01-22 19:27:45 +01:00
@GetMapping ( " /customer/orderhistory " )
public String customerOrderHistory ( ) {
return " customer/orderHistory " ;
}
@GetMapping ( " /customer/bonusprogram " )
public String customerBonusProgram ( ) {
return " customer/bonusProgram " ;
}
@RequestMapping ( value = " /updateAccountSettings " , method = RequestMethod . POST , params = " action=updateAccountSettings " )
2020-01-15 10:55:24 +01:00
public String updateAccountSettings ( @ModelAttribute Customer customer , HttpServletResponse response ) {
// do the login magic and get a loginToken
System . out . println ( customer . username ) ;
System . out . println ( customer . password ) ;
2020-01-20 20:22:37 +01:00
return " /customer/accountsettings " ;
2020-01-15 10:55:24 +01:00
}
2020-01-12 19:42:04 +01:00
2019-12-08 17:16:17 +01:00
@GetMapping ( " /login " )
public String login ( @CookieValue ( value = " loginToken " , defaultValue = " " ) String loginToken , Model model ) {
model . addAttribute ( new Customer ( ) ) ;
System . out . println ( loginToken ) ; // TODO if cookie is present, redirect to home
return " login " ;
}
2020-01-22 19:27:45 +01:00
@RequestMapping ( value = " /login " , method = RequestMethod . POST , params = " action=login " )
2019-12-08 17:16:17 +01:00
public String loginAction ( @ModelAttribute Customer customer , HttpServletResponse response ) {
2020-01-20 20:22:37 +01:00
Cookie cookie = new Login ( customerRepo ) . getLoginToken ( customer ) ;
if ( cookie ! = null ) {
2019-12-08 17:16:17 +01:00
response . addCookie ( cookie ) ;
2020-01-20 20:22:37 +01:00
return " redirect:home " ;
2019-12-08 17:16:17 +01:00
} else {
2020-01-20 20:22:37 +01:00
return " redirect:login " ; // redirect so the input files get cleared, otherwise only pwd gets cleared
2019-12-08 17:16:17 +01:00
}
}
2019-12-08 12:24:28 +01:00
2019-12-08 17:16:17 +01:00
@GetMapping ( " /register " )
public String register ( @CookieValue ( value = " loginToken " , defaultValue = " " ) String loginToken , Model model ) {
model . addAttribute ( new Customer ( ) ) ;
System . out . println ( loginToken ) ; // TODO if cookie is present, redirect to home
return " register " ;
}
2020-01-22 19:27:45 +01:00
@RequestMapping ( value = " /register " , method = RequestMethod . POST , params = " action=register " )
2019-12-08 17:16:17 +01:00
public String registerAction ( @ModelAttribute Customer customer , HttpServletResponse response ) {
// do the register magic and get a loginToken
System . out . println ( customer . username ) ;
System . out . println ( customer . password ) ;
if ( customerRepo . findByUsername ( customer . username ) . size ( ) ! = 0 ) {
// TODO
System . out . println ( " The customer exists already " ) ;
2020-01-20 20:22:37 +01:00
return " redirect:register " ;
2019-12-08 17:16:17 +01:00
} else {
customerRepo . save ( customer ) ;
System . out . println ( customerRepo . findByUsername ( customer . username ) . size ( ) ) ;
}
// return a login token after successful registration
2019-12-08 12:24:28 +01:00
String loginToken = UUID . randomUUID ( ) . toString ( ) ;
// set the loginToken as session cookie
Cookie cookie = new Cookie ( " loginToken " , loginToken ) ;
response . addCookie ( cookie ) ;
2020-01-20 20:22:37 +01:00
return " home " ;
2019-12-08 12:24:28 +01:00
}
2020-01-15 10:55:24 +01:00
@GetMapping ( " /about " )
public String about ( ) {
return " about " ;
}
@GetMapping ( " /terms " )
public String terms ( ) {
return " terms " ;
}
@GetMapping ( " /privacy " )
public String privacy ( ) {
return " privacy " ;
}
2019-11-19 19:34:57 +01:00
}