package com.yunzhi.marketing.controller;


import com.yunzhi.marketing.base.BaseController;
import com.yunzhi.marketing.base.ResponseBean;
import com.yunzhi.marketing.service.ITaSaveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 表  前端控制器
 * </p>
 *
 * @author jobob
 * @since 2019-07-25
 */
@RestController
@RequestMapping("/api")
public class TaSaveController extends BaseController {

    @Autowired
    private ITaSaveService iTaSaveService;

    /**
     * 收藏
     * @param typeOf
     * @param id
     * @param request
     * @return
     */
    @PostMapping("/wx/{typeOf}/save/{id}")
    public ResponseBean giveFavor(@PathVariable String typeOf, @PathVariable String id, HttpServletRequest request) {
        String openid = getOpenId(request);

        return iTaSaveService.postLike(openid, typeOf, id,getOrgId(request));
    }

    /**
     * 取消收藏
     * @param typeOf
     * @param id
     * @param request
     * @return
     */
    @DeleteMapping("/wx/{typeOf}/save/{id}")
    public ResponseBean cancelFavor(@PathVariable String typeOf, @PathVariable String id, HttpServletRequest request) {
        String openid = getOpenId(request);
        return iTaSaveService.cancelLike(openid, typeOf, id);
    }

}
