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

router.get('/', count);
router.get('/get-app', getApp);
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) {
    appService.count(req.query)
        .then(result => res.json(result))
        .catch(next);
}

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

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

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

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

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

