<commit_before>package ro.jademy.presentation;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import ro.jademy.domain.entities.Media;
import ro.jademy.domain.entities.ProductType;
import ro.jademy.domain.entities.ShoppingCart;
import ro.jademy.domain.entities.User;
import ro.jademy.domain.service.MediaService;
import ro.jademy.domain.service.ShoppingCartService;

@Controller
public class CartController {
	
	@Autowired
	ShoppingCartService shoppingCartService;  
	
	@Autowired
	MediaService mediaService;   
	
	@RequestMapping("/addProductToCart")
	public ModelAndView addProductToCart(String productCode, int cantitate, ProductType productType,
			HttpServletRequest request) {
		if (cantitate == 0) {
			ModelAndView mv = new ModelAndView("redirect:productList/" + productType.toString());
			return mv;
		}	
		
		Media media = mediaService.getProductByProductTypeAndCode(productType, productCode);
		ShoppingCart shoppingCart = (ShoppingCart)request.getSession().getAttribute("shoppingCart");
		if(shoppingCart == null){
			shoppingCart = new ShoppingCart();
			request.getSession().setAttribute("shoppingCart", shoppingCart);
		}
		
		shoppingCart.addToCart(media, cantitate);
		ModelAndView mv = new ModelAndView("redirect:productList/" + productType.toString());
		return mv;

	}
	
	@RequestMapping("/displayCart")
	public ModelAndView displayCart(){
		return new ModelAndView("displayCart");
	}
	
	@RequestMapping("/checkout")
	public ModelAndView checkout(HttpServletRequest request){
		ShoppingCart shoppingCart = (ShoppingCart) request.getSession().getAttribute("shoppingCart");
		if(shoppingCart == null){
			return new ModelAndView("displayCart");
		}
		if(shoppingCart.getCartItems().size()==0){
			return new ModelAndView("displayCart");
		}
		User currentUser = (User) request.getSession().getAttribute("currentUser");
		ShoppingCart dbCart = shoppingCartService.saveShoppingCart(shoppingCart, currentUser);
		request.getSession().setAttribute("shoppingCart", dbCart);
		return new ModelAndView("redirect:/mainMenu");
	}
<commit_msg>cos scos de pe sesiune<commit_after>package ro.jademy.presentation;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import ro.jademy.domain.entities.Media;
import ro.jademy.domain.entities.ProductType;
import ro.jademy.domain.entities.ShoppingCart;
import ro.jademy.domain.entities.User;
import ro.jademy.domain.service.MediaService;
import ro.jademy.domain.service.ShoppingCartService;

@Controller
public class CartController {
	
	@Autowired
	ShoppingCartService shoppingCartService;  
	
	@Autowired
	MediaService mediaService;   
	
	@RequestMapping("/addProductToCart")
	public ModelAndView addProductToCart(String productCode, int cantitate, ProductType productType,
			HttpServletRequest request) {
		if (cantitate == 0) {
			ModelAndView mv = new ModelAndView("redirect:productList/" + productType.toString());
			return mv;
		}	
		
		Media media = mediaService.getProductByProductTypeAndCode(productType, productCode);
		ShoppingCart shoppingCart = (ShoppingCart)request.getSession().getAttribute("shoppingCart");
		if(shoppingCart == null){
			shoppingCart = new ShoppingCart();
			//request.getSession().setAttribute("shoppingCart", shoppingCart);
		}
		
		shoppingCart.addToCart(media, cantitate);
		ModelAndView mv = new ModelAndView("redirect:productList/" + productType.toString());
		return mv;

	}
	
	@RequestMapping("/displayCart")
	public ModelAndView displayCart(){
		return new ModelAndView("displayCart");
	}
	
	@RequestMapping("/checkout")
	public ModelAndView checkout(HttpServletRequest request){
		ShoppingCart shoppingCart = (ShoppingCart) request.getSession().getAttribute("shoppingCart");
		if(shoppingCart == null){
			return new ModelAndView("displayCart");
		}
		if(shoppingCart.getCartItems().size()==0){
			return new ModelAndView("displayCart");
		}
		User currentUser = (User) request.getSession().getAttribute("currentUser");
		ShoppingCart dbCart = shoppingCartService.saveShoppingCart(shoppingCart, currentUser);
		request.getSession().setAttribute("shoppingCart", dbCart);
		return new ModelAndView("redirect:/mainMenu");
	}

{'fraction_non_alphanumeric': 0.11196151322982725, 'fraction_numerical': 0.0008746993221080254, 'mean_word_length': 6.389337641357027, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5104277', 'n_tokens_mistral': 1401, 'n_tokens_neox': 1348, 'n_words': 236}