package top.awin_x.learn.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.awin_x.learn.dao.impl.CourseDBImpl;
import top.awin_x.learn.pojo.CourseInfo;
import top.awin_x.learn.service.CourseService;

import java.util.ArrayList;

@Service
public class CourseServiceImpl implements CourseService {
    @Autowired
    private CourseDBImpl courseDB;

    @Override
    public ArrayList<CourseInfo> listCourses(int page, int pageSize, String keyword, int type) {
        return new CourseDBImpl().getCourseInfos(page, pageSize, keyword, type);
    }

    @Override
    public boolean editCourse(CourseInfo course) {
        CourseDBImpl courseDBImpl = new CourseDBImpl();
        CourseInfo courseInfo = courseDBImpl.getCourseInfoByID(course.getId());
        if (courseInfo != null) {
            courseDBImpl.updateCourseInfo(course);
            return true;
        }else{
            return false;
        }
    }
}
