2020-04-29 22:44:16 +02:00
package org.hso.ecommerce.controller.shop ;
2020-04-28 22:41:29 +02:00
2020-05-02 14:38:40 +02:00
import org.hso.ecommerce.entities.shop.Article ;
import org.hso.ecommerce.entities.user.User ;
2020-04-28 22:41:29 +02:00
import org.springframework.stereotype.Controller ;
2020-05-02 14:38:40 +02:00
import org.springframework.ui.Model ;
import org.springframework.web.bind.annotation.* ;
import javax.servlet.http.HttpSession ;
import java.util.ArrayList ;
import java.util.List ;
2020-04-28 22:41:29 +02:00
@Controller
2020-05-02 14:38:40 +02:00
@RequestMapping ( " /shop/articles " )
2020-05-01 10:48:12 +02:00
public class ShopArticleController {
2020-05-02 14:38:40 +02:00
@GetMapping ( " /{id} " )
public String shopArticlesById ( Model model , @PathVariable ( " id " ) Integer Id ) {
//TODO: Get Article by Id instead of this dummy shit
Article d1 = new Article ( ) ;
d1 . description = " this is dummy1 " ;
d1 . title = " dummy1 " ;
d1 . shopPricePerUnitNetCent = 1500 ;
d1 . id = 1234 ;
model . addAttribute ( " article " , d1 ) ;
//TODO: Check if in Stock
if ( false ) {
model . addAttribute ( " inStock " , true ) ;
} else {
model . addAttribute ( " inStock " , false ) ;
}
//TODO: Get 2 Commercialised Articles
List < Article > commercialArticles = new ArrayList < Article > ( ) ;
Article d2 = new Article ( ) ;
d2 . description = " this is dummy2 " ;
d2 . title = " dummy2 " ;
d2 . shopPricePerUnitNetCent = 2000 ;
d2 . id = 2345 ;
Article d3 = new Article ( ) ;
d3 . description = " this is dummy3 " ;
d3 . title = " dummy3 " ;
d3 . shopPricePerUnitNetCent = 2500 ;
d3 . id = 3456 ;
commercialArticles . add ( d2 ) ;
commercialArticles . add ( d3 ) ;
model . addAttribute ( " commercialArticles " , commercialArticles ) ;
return " shop/articles/id " ;
}
@PostMapping ( " /{id} " )
public String shopArticlesByIdBuy ( HttpSession session ,
@RequestAttribute ( value = " user " , required = false ) User customer ,
// @RequestAttribute(value = "shoppingCart", required = true) ShoppingCart shoppingCart,
@PathVariable ( " id " ) Integer id ,
@RequestParam ( " fastcheckout " ) Boolean fastcheckout
) {
if ( customer ! = null ) {
//TODO: Add Article to Shopping Cart
if ( ! fastcheckout ) {
return " shop/articles/post_add " ;
} else {
return " shop/checkout " ;
}
} else {
session . setAttribute ( " afterLogin " , " /shop/articles/ " + id ) ;
return " redirect:/login " ;
}
}
2020-04-28 22:41:29 +02:00
}