package com.yunzhi.marketing.controller;


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

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 点赞表 前端控制器
 * </p>
 *
 * @author jobob
 * @since 2019-05-10
 */
@RestController
@RequestMapping("/api")
public class TaFavorController extends BaseController {

    @Autowired
    ITaFavorService taFavorService;

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

        return taFavorService.postLike(openid, typeOf, id);
    }

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