From f5bc2a420545d2c78ca9879555a623c5b0284b0d Mon Sep 17 00:00:00 2001 From: 5d-jh Date: Thu, 6 Dec 2018 14:13:10 +0900 Subject: [PATCH] =?UTF-8?q?=EB=A7=8C=EB=A3=8C=EC=9D=BC=EC=9D=84=20?= =?UTF-8?q?=ED=83=84=EB=A0=A5=EC=A0=81=EC=9C=BC=EB=A1=9C=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/responseCache.js | 18 +++++++++++++++--- api/route.js | 14 +++++--------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/api/responseCache.js b/api/responseCache.js index 874656c..72dede1 100644 --- a/api/responseCache.js +++ b/api/responseCache.js @@ -25,7 +25,18 @@ class ResponseCache { } const date = new Date(); - NODE_ENV === 'development' ? date.setMinutes(date.getMinutes() + 2) : date.setDate(date.getDate() + 6); + + const condition = ((date.getFullYear() < this.menuYear) || + ((date.getMonth()+1 < this.menuMonth))); + + if (condition) { + date.setDate(date.getDate() + 1); + } else { + NODE_ENV === 'development' + ? date.setMinutes(date.getMinutes() + 2) + : date.setFullYear(date.getFullYear() + 3); + } + return date; } @@ -68,7 +79,6 @@ class ResponseCache { } if (schoolMenu.length !== 0) { - console.log(schoolMenu) return schoolMenu; } else { throw new Error('식단을 찾을 수 없습니다. 학교 코드를 다시 확인해 주세요.'); @@ -108,4 +118,6 @@ class ResponseCache { } } -module.exports = ResponseCache; \ No newline at end of file +module.exports = (schoolType, schoolCode, menuYear, menuMonth) => { + return new ResponseCache(schoolType, schoolCode, menuYear, menuMonth); +} \ No newline at end of file diff --git a/api/route.js b/api/route.js index b1304f3..f8615c1 100644 --- a/api/route.js +++ b/api/route.js @@ -3,7 +3,7 @@ const express = require('express'); const router = express.Router(); -const ResponseCache = require('./ResponseCache'); +const responseCache = require('./responseCache'); const removeAllergyInfo = (month, hideAllergyInfo) => { let singleDay = false; @@ -34,8 +34,7 @@ router.get('/:schoolType/:schoolCode', (req, res, next) => { const menuYear = Number(req.query.year) || new Date().getFullYear(); const menuMonth = Number(req.query.month) || new Date().getMonth()+1; - const responseCache = new ResponseCache(req.params.schoolType, req.params.schoolCode, menuYear, menuMonth); - responseCache.getCache() + responseCache(req.params.schoolType, req.params.schoolCode, menuYear, menuMonth).getCache() .then((schoolMenuData) => { const responseJSON = { menu: schoolMenuData.schoolMenu, @@ -51,7 +50,7 @@ router.get('/:schoolType/:schoolCode', (req, res, next) => { const remainingHours = Math.floor(remainingTime / (3600000 * (remainingDays+1))); remainingMessage = `${remainingDays}일 ${remainingHours}시간`; if ((remainingDays && remainingHours) === 0) { - const remainingMins = Math.floor(remainingTime / 60000); + const remainingMins = Math.floor((remainingTime / 60000) % 60); const remainingSecs = Math.ceil((remainingTime / 1000) % 60); remainingMessage += ` ${remainingMins}분 ${remainingSecs}초`; }; @@ -59,9 +58,9 @@ router.get('/:schoolType/:schoolCode', (req, res, next) => { } const hideAllergyInfo = req.query.hideAllergy === "true" ? true : false; - const date = req.query.date; + const menuDate = Number(req.query.date); - responseJSON.menu = date ? responseJSON.menu[Number(date)-1] : responseJSON.menu; + if (menuDate) responseJSON.menu =responseJSON.menu[menuDate-1]; responseJSON.menu = removeAllergyInfo(responseJSON.menu, hideAllergyInfo); responseJSON.server_message.push(...require('./serverMessage.json').content); @@ -70,9 +69,6 @@ router.get('/:schoolType/:schoolCode', (req, res, next) => { res.json(responseJSON); }) .catch(err => next(err)); - /*responseCache.getCache(, (schoolMenuCache, err) => { - - }); */ }); module.exports.router = router; \ No newline at end of file