package kr.co.jinwoosi.clfd.clfd.bod.web;

import kr.co.jinwoosi.clfd.conts.bod.model.BodArtiSearch;
import kr.co.jinwoosi.clfd.conts.bod.service.BodArtiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;

@Controller
public class ClfdBodController {

    @Autowired
    private BodArtiService bodArtiService;

    @RequestMapping(value = "/clfd/bod/notice/list.do")
    public String noticeList() {
        return "clfd/bod/notice/list";
    }

    @RequestMapping(value = "/clfd/bod/list.json")
    @ResponseBody
    public HashMap<String, Object> boardListJson(BodArtiSearch bodArtiSearch) {
        HashMap<String, Object> result = new HashMap<>();
        result.put("boardList", bodArtiService.selectList(bodArtiSearch));
        result.put("result", "success");
        return result;
    }

    @RequestMapping(value = "/clfd/bod/notice/dtl.do")
    public String noticeDtl(Model model, HttpServletRequest request, BodArtiSearch bodArtiSearch) {
        bodArtiService.updateHit(Long.parseLong(request.getParameter("artiId")));
        model.addAttribute("bodArti", bodArtiService.select(bodArtiSearch));
        return "clfd/bod/notice/dtl";
    }

}
