package com.lightinit.hsdataportal.controller.open;

import com.lightinit.hsdataportal.entity.BaseExample;
import com.lightinit.hsdataportal.model.LoginUser;
import com.lightinit.hsdataportal.model.MyFollowRequirementListModel;
import com.lightinit.hsdataportal.model.MyFollowRequirementSearchModel;
import com.lightinit.hsdataportal.model.ResultState;
import com.lightinit.hsdataportal.service.IMyFollowRequirementService;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping(value = "/open/MyOpenFollow")
public class MyFollowRequirementOpenController {
    @Autowired
    private IMyFollowRequirementService myFollowRequirementService;


    @RequestMapping(value = "list.action")
    @ResponseBody
    @RequiresAuthentication
    public ModelAndView list(HttpSession session) {
        LoginUser loginUser = (LoginUser) session.getAttribute(LoginUser.SESSION_KEY_LOGIN_USER);
        ModelAndView modelAndView = new ModelAndView("open/myrequirement/myfollow/list");
        List<MyFollowRequirementListModel> outputModel = myFollowRequirementService.selectOpenList(loginUser.getId());
        modelAndView.addObject("list", outputModel);
        return modelAndView;
    }

    @RequestMapping(value = "delfollow.action/{id}")
    @RequiresAuthentication
    @ResponseBody
    public ResultState delfollow(@PathVariable long id) {
        ResultState   resultState = myFollowRequirementService.delfollow(id);
        return resultState;
    }
}
