const express = require('express');
const router = express.Router();
const projectService = require('./project.service');
const authorize = require('../../../../middlewares/authorize-sapps');

router.get('/', count);
router.get('/get-project', getProject);
router.get('/get-development', getDevelopment);
router.get('/get-development-detail', authorize(), getDevelopmentDetail);
router.get('/get-feature-count', authorize(), getFeatureCount);
router.get('/get-course', authorize(), getCourse);
router.get('/get-course-without-auth', getCourse);

module.exports = router;

function count(req, res, next) {
    projectService.count(req.query)
        .then(result => res.json(result))
        .catch(next);
}

function getProject(req, res, next) {
    projectService.getProject(req.query)
        .then(result => res.json(result))
        .catch(next);
}

function getDevelopment(req, res, next) {
    projectService.getDevelopment(req.query)
        .then(result => res.json(result))
        .catch(next);
}

function getDevelopmentDetail(req, res, next) {
    projectService.getDevelopmentDetail(req.query)
        .then(result => res.json(result))
        .catch(next);
}

function getFeatureCount(req, res, next) {
    projectService.getFeatureCount(req.query)
        .then(result => res.json(result))
        .catch(next);
}

function getCourse(req, res, next) {
    projectService.getCourse(req.query)
        .then(result => res.json(result))
        .catch(next);
}
