diff --git a/examples/chatserver/apihandler.cpp b/examples/chatserver/apihandler.cpp index cd6ba8b..2f352d6 100644 --- a/examples/chatserver/apihandler.cpp +++ b/examples/chatserver/apihandler.cpp @@ -22,26 +22,14 @@ #include "apihandler.h" -QVariantMap ApiHandler::postMessage(const QVariantMap ¶ms) -{ - // Ensure that a valid message was supplied - if(!params.contains("message")) { - return QVariantMap(); - } - - // Add the new message to the list - mMessages.append(params.value("message").toString()); - return QVariantMap(); -} - -QVariantMap ApiHandler::getMessages(const QVariantMap ¶ms) +QVariantMap ApiHandler::get_messages(const QVariantMap &query) { // Ensure an index was supplied - if(!params.contains("index")) { + if(!query.contains("index")) { return QVariantMap(); } - int index = params.value("index").toInt(); + int index = query.value("index").toInt(); QVariantList messages; // Construct a list of all messages with an index higher than the one @@ -61,3 +49,16 @@ QVariantMap ApiHandler::getMessages(const QVariantMap ¶ms) data.insert("messages", messages); return data; } + + +QVariantMap ApiHandler::post_newMessage(const QVariantMap &query, const QVariantMap ¶ms) +{ + // Ensure that a valid message was supplied + if(!params.contains("message")) { + return QVariantMap(); + } + + // Add the new message to the list + mMessages.append(params.value("message").toString()); + return QVariantMap(); +} diff --git a/examples/chatserver/apihandler.h b/examples/chatserver/apihandler.h index 373d6c6..d179c5a 100644 --- a/examples/chatserver/apihandler.h +++ b/examples/chatserver/apihandler.h @@ -33,8 +33,8 @@ class ApiHandler : public QObjectHandler public Q_SLOTS: - QVariantMap postMessage(const QVariantMap ¶ms); - QVariantMap getMessages(const QVariantMap ¶ms); + QVariantMap get_messages(const QVariantMap &query); + QVariantMap post_newMessage(const QVariantMap &query, const QVariantMap ¶ms); private: diff --git a/examples/chatserver/static/js/chat.js b/examples/chatserver/static/js/chat.js index cd1c84e..a5abd84 100644 --- a/examples/chatserver/static/js/chat.js +++ b/examples/chatserver/static/js/chat.js @@ -7,9 +7,8 @@ $(function() { // Retrieve all messages after the specified index function update() { $.ajax({ - type: 'POST', - url: '/api/getMessages', - data: JSON.stringify({index: index}), + url: '/api/messages', + data: {index: index}, contentType: 'application/json', complete: function() { window.setTimeout(update, 2000); @@ -34,7 +33,7 @@ $(function() { if(e.which == 13) { $.ajax({ type: 'POST', - url: '/api/postMessage', + url: '/api/newMessage', data: JSON.stringify({message: $(this).val()}), contentType: 'application/json' });