package com.huiju.estateagents.controller;


import com.huiju.estateagents.base.ResponseBean;
import com.huiju.estateagents.common.JWTUtils;
import com.huiju.estateagents.service.ITaFavorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.huiju.estateagents.base.BaseController;

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);
    }
}
