package com.quinn.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.quinn.pojo.Comment;
import com.quinn.pojo.Star;
import com.quinn.service.CommentService;
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 CommentController extends BaseModelController {

    private static final Logger log = LoggerFactory.getLogger(CommentController.class);
    @Autowired
    CommentService commentService;

    // 删除评论
    @GetMapping("/user/comment/delete/{cid}")
    public String deleteComment(HttpServletRequest request, @PathVariable String cid){
        String loginUserId = getLoginUserId(request);
        Comment comment = commentService.getOne(new QueryWrapper<Comment>().eq("comment_id", cid));
        if (loginUserId.equals(comment.getUserId())){
            commentService.removeById(comment);
        }else {
            log.error("非法取消收藏!");
        }
        return "redirect:/user/comment";
    }

}

