Question
Implement an Android app (SMS Gateway APP) that continuously use: - getSMS() returns the oldest unsent message as a JSON object; e.g., {id: 10, phone:00000000,
Implement an Android app (SMS Gateway APP) that continuously use:
- getSMS() returns the oldest unsent message as a JSON object; e.g., {id: 10, phone:00000000, body:hgdfhghdsgfhjs }: GET
-sentSMS(msg_id): GET
in order to deliver the SMS messages. Use Postman to simulate the client that calls sendSMS API to request sending an SMS message.
Note: sendSMS(phone, message_body): POST
Here is the 3 APIs sendSMS, getSMS, sentSMS
var express = require('express'); var router = express.Router(); var bodyParser = require('body-parser'); var db = require('../db');
router.use(bodyParser.urlencoded({ extended: true })); router.use(bodyParser.json());
router.post("/sendSMS", function (req, res) { var sql ="INSERT INTO smsQ(phone, body, sentFlag) values(?,?, 0)";// "INSERT I INTO smsQ (phone, body) VALUES (" +req.phone+","+req.body+")"; db.mycon.query(sql,[req.body.phone,req.body.body] ,function (err, result) { if(err){ res.send(err); }else { //my code return res.send(result); } }); }); router.get("/getSMS", function (req, res) { var sql ="SELECT body, phone, id FROM smsQ WHERE sentFlag = 0 HAVING min(timeStamp)"; //sent == 1 db.mycon.query(sql, function (err, result) { if(err){ res.send(err); }else { //my code return res.send(result); } }); }); router.get("/sentSMS", function (req, res) { var sql ="UPDATE smsQ SET sentFlag = 1 WHERE ID = ?"; db.mycon.query(sql, [req.query.id],function (err, result) { if(err){ res.send(err); }else { //my code return res.send(result); } }); }); module.exports = router;
//CREATE TABLE smsQ(ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY, sentFlag SMALLINT, timeStamp TIMESTAMP, phone VARCHAR(10), body TEXT); //
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started