/*
 * Copyright 2002-2008 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
*/
package anyframe.sample.struts.web.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import anyframe.sample.struts.web.form.ShoppingCartForm;
import anyframe.web.struts.action.DefaultDispatchActionSupport;

public class ShoppingCartAction extends DefaultDispatchActionSupport {

	private Log log = LogFactory.getLog(this.getClass().getName());
	
	public ActionForward add(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		log.debug(this.getClass().getName() + "add start");

		// TODO : add 기능 관련 로직
		
		HttpSession session = request.getSession();
		ShoppingCartForm shoppingCartForm = (ShoppingCartForm)form;
		int addCount = shoppingCartForm.getAddCount() + 1;
		session.setAttribute("addCount", addCount + "");
		log.debug(this.getClass().getName() + "add end");
		return mapping.findForward("add");
	}

	public ActionForward update(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {

		log.debug(this.getClass().getName() + "update start");
		
		// TODO : update 기능 관련 로직
		
		HttpSession session = request.getSession();
		ShoppingCartForm shoppingCartForm = (ShoppingCartForm)form;
		int updateCount = shoppingCartForm.getUpdateCount() + 1;
		session.setAttribute("updateCount", updateCount + "");
		log.debug(this.getClass().getName() + "update end");
		return mapping.findForward("update");
	}

	public ActionForward list(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {

		log.debug(this.getClass().getName() + "list start");
		
		// TODO : search 기능 관련 로직
		
		HttpSession session = request.getSession();
		ShoppingCartForm shoppingCartForm = (ShoppingCartForm)form;
		int listCount = shoppingCartForm.getListCount() + 1;
		session.setAttribute("listCount", listCount + "");
		log.debug(this.getClass().getName() + "list end");
		return mapping.findForward("list");
	}

	public ActionForward delete(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {

		
		log.debug(this.getClass().getName() + "delete start");
		
		// TODO : delete 기능 관련 로직
		
		HttpSession session = request.getSession();
		ShoppingCartForm shoppingCartForm = (ShoppingCartForm)form;
		int deleteCount = shoppingCartForm.getDeleteCount() + 1;
		session.setAttribute("deleteCount", deleteCount + "");
		log.debug(this.getClass().getName() + "delete end");
		return mapping.findForward("delete");
	}
}

