박권수

feat. RESTful now

......@@ -3,9 +3,9 @@ const bottleCtrl = require('./bottle.ctrl');
const bottle = new Router();
bottle.post('/connect', bottleCtrl.bottleConnect);
bottle.post('/disconnect/:bottleId', bottleCtrl.bottleDisconnect);
bottle.post('/lookupInfo/:bottleId', bottleCtrl.lookupInfo);
bottle.post('/setmedicine/:bottleId', bottleCtrl.setMedicine);
bottle.post('/', bottleCtrl.bottleConnect);
bottle.delete('/:bottleId', bottleCtrl.bottleDisconnect);
bottle.get('/:bottleId', bottleCtrl.lookupInfo);
bottle.patch('/:bottleId', bottleCtrl.setMedicine);
module.exports = bottle;
\ No newline at end of file
......
......@@ -3,7 +3,7 @@ const hubCtrl = require('./hub.ctrl');
const hub = new Router();
hub.post('/connect', hubCtrl.hubConnect);
hub.post('/disconnect/:hubId', hubCtrl.hubDisconnect);
hub.post('/', hubCtrl.hubConnect);
hub.delete('/:hubId', hubCtrl.hubDisconnect);
module.exports = hub;
\ No newline at end of file
......
......@@ -3,6 +3,7 @@ const medicineCtrl = require('./medicine.ctrl');
const medicine = new Router();
medicine.get('/search', medicineCtrl.medicineSearch);
medicine.post('/', medicineCtrl.medicineSearch);
medicine.get('/:medicineId', medicineCtrl.medicineGet);
module.exports = medicine;
\ No newline at end of file
......
......@@ -28,6 +28,25 @@ exports.medicineSearch = async(ctx) => {
}
}
exports.medicineGet = async(ctx) => {
const token = ctx.cookies.get('access_token');
if(!token) {
ctx.status = 401;
return;
}
const { medicineId } = ctx.params;
const medicine = await Medicine.findByMedicineId(medicineId);
if(!medicine) {
ctx.status = 404;
return;
}
ctx.status = 200;
ctx.body = medicine;
}
//이름으로 약 검색
const medicineSearch_ByName = async(name) => {
const result = await Medicine.findByName(name);
......