package com.quinn.controller;

import com.quinn.pojo.Star;
import com.quinn.service.StarService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author limqsh
 * @since 2020-06-30
 */
@Controller
public class StarController extends BaseModelController {

    private static final Logger log = LoggerFactory.getLogger(StarController.class);

    @Autowired
    StarService starService;

    // 取消收藏
    @GetMapping("/user/star/delete/{starId}")
    public String deleteComment(HttpServletRequest request, @PathVariable String starId){
        String loginUserId = getLoginUserId(request);
        Star star = starService.getById(starId);
        if (loginUserId.equals(star.getUserId())){
            starService.removeById(star);
        }else {
            log.error("非法取消收藏!");
        }
        return "redirect:/user/star";
    }

}

