package com.example.system.service.impl;

import com.example.system.mapper.ArticleMapper;
import com.example.system.mapper.CommentMapper;
import com.example.system.model.ArticleTable;
import com.example.system.model.UserTable;
import com.example.system.repository.RegistrationRepository;
import com.example.system.service.ArticleService;
import com.example.system.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class ArticleServiceImpl implements ArticleService {

    @Autowired
    private ArticleMapper articleMapper;

    @Autowired
    private CommentMapper commentMapper;


    @Override
    @Transactional
    public Integer createArticle(ArticleTable article) {
        articleMapper.createArticle(article);
        return article.getArticleId();
    }


    @Override
    public List<ArticleTable> getHistoryArticle() {
        return articleMapper.getHistoryArticle();
    }

    @Override
    public ArticleTable getArticleById(Integer id) {
        return articleMapper.getArticleById(id);
    }

    @Override
    public Boolean deleteArticleById(Integer id) {
        //删除该篇文章的评论
        commentMapper.deleteCommentByArticleId(id);
        //删除该篇文章
        return articleMapper.deleteArticleById(id) == 1;
    }

    @Override
    public Boolean updateArticle(ArticleTable articleTable) {
        return articleMapper.updataArtical(articleTable) == 1;
    }

    @Override
    public void notifyParticipants(Integer competitionId) {

    }
}