Skeleton for internalapi response completed
This commit is contained in:
parent
45a1662eae
commit
5a07cadd4a
@ -160,6 +160,12 @@ struct CAWebChat {
|
||||
"backend_logic/when_api_getuserinfo.cpp",
|
||||
"backend_logic/when_api_getmessageinfo.cpp",
|
||||
"backend_logic/when_api_getmessageneighbours.cpp",
|
||||
"backend_logic/when_api_sendmessage.cpp",
|
||||
"backend_logic/when_api_deletemessage.cpp",
|
||||
"backend_logic/when_api_addmembertochat.cpp",
|
||||
"backend_logic/when_api_removememberfromchat.cpp",
|
||||
"backend_logic/when_api_createchat.cpp",
|
||||
"backend_logic/when_api_removechat.cpp",
|
||||
};
|
||||
for (std::string& u: T.units)
|
||||
u = "web_chat/iu9_ca_web_chat_lib/" + u;
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "client_server_interact.h"
|
||||
#include <engine_engine_number_9/http_structures/cookies.h>
|
||||
#include <functional>
|
||||
|
||||
namespace iu9cawebchat {
|
||||
void initial_extraction_of_all_the_useful_info_from_cookies(
|
||||
@ -33,46 +34,62 @@ namespace iu9cawebchat {
|
||||
|
||||
/* ========================= API =========================*/
|
||||
|
||||
|
||||
std::string when_internalapi_pollevents(WorkerGuestData& wgd,
|
||||
const een9::ClientRequest& req, int64_t uid) {
|
||||
std::string when_internalapi(WorkerGuestData& wgd, const een9::ClientRequest& req, int64_t uid,
|
||||
const std::function<json::JSON(SqliteConnection&, int64_t, const json::JSON&)>& F) {
|
||||
const json::JSON& Sent = json::parse_str_flawless(req.body);
|
||||
std::string result = json::generate_str(internalapi_pollEvents(*wgd.db, uid, Sent), json::print_pretty);
|
||||
std::string result = json::generate_str(F(*wgd.db, uid, Sent), json::print_pretty);
|
||||
return een9::form_http_server_response_200("text/json", result);
|
||||
}
|
||||
|
||||
std::string when_internalapi_getchatlist(WorkerGuestData& wgd,
|
||||
const een9::ClientRequest& req, int64_t uid) {
|
||||
const json::JSON& Sent = json::parse_str_flawless(req.body);
|
||||
std::string result = json::generate_str(internalapi_getChatList(*wgd.db, uid), json::print_pretty);
|
||||
return een9::form_http_server_response_200("text/json", result);
|
||||
std::string when_internalapi_pollevents(WorkerGuestData& wgd, const een9::ClientRequest& req, int64_t uid) {
|
||||
return when_internalapi(wgd, req, uid, internalapi_pollEvents);
|
||||
}
|
||||
|
||||
std::string when_internalapi_getchatinfo(WorkerGuestData& wgd,
|
||||
const een9::ClientRequest& req, int64_t uid) {
|
||||
const json::JSON& Sent = json::parse_str_flawless(req.body);
|
||||
std::string result = json::generate_str(internalapi_getChatInfo(*wgd.db, uid, Sent), json::print_pretty);
|
||||
return een9::form_http_server_response_200("text/json", result);
|
||||
std::string when_internalapi_getchatlist(WorkerGuestData& wgd, const een9::ClientRequest& req, int64_t uid) {
|
||||
return when_internalapi(wgd, req, uid, internalapi_getChatList);
|
||||
}
|
||||
|
||||
std::string when_internalapi_getchatmemberlist(WorkerGuestData& wgd,
|
||||
const een9::ClientRequest& req, int64_t uid) {
|
||||
const json::JSON& Sent = json::parse_str_flawless(req.body);
|
||||
std::string result = json::generate_str(internalapi_getChatMemberList(*wgd.db, uid, Sent), json::print_pretty);
|
||||
return een9::form_http_server_response_200("text/json", result);
|
||||
std::string when_internalapi_getchatinfo(WorkerGuestData& wgd, const een9::ClientRequest& req, int64_t uid) {
|
||||
return when_internalapi(wgd, req, uid, internalapi_getChatInfo);
|
||||
}
|
||||
|
||||
std::string when_internalapi_getuserinfo(WorkerGuestData& wgd,
|
||||
const een9::ClientRequest& req, int64_t uid) {
|
||||
const json::JSON& Sent = json::parse_str_flawless(req.body);
|
||||
std::string result = json::generate_str(internalapi_getUserInfo(*wgd.db, uid, Sent), json::print_pretty);
|
||||
return een9::form_http_server_response_200("text/json", result);
|
||||
std::string when_internalapi_getchatmemberlist(WorkerGuestData& wgd, const een9::ClientRequest& req, int64_t uid) {
|
||||
return when_internalapi(wgd, req, uid, internalapi_getChatMemberList);
|
||||
}
|
||||
|
||||
std::string when_internalapi_getmessageinfo(WorkerGuestData& wgd,
|
||||
const een9::ClientRequest& req, int64_t uid) {
|
||||
const json::JSON& Sent = json::parse_str_flawless(req.body);
|
||||
std::string result = json::generate_str(internalapi_getMessageInfo(*wgd.db, uid, Sent), json::print_pretty);
|
||||
return een9::form_http_server_response_200("text/json", result);
|
||||
std::string when_internalapi_getuserinfo(WorkerGuestData& wgd, const een9::ClientRequest& req, int64_t uid) {
|
||||
return when_internalapi(wgd, req, uid, internalapi_getUserInfo);
|
||||
}
|
||||
}
|
||||
|
||||
std::string when_internalapi_getmessageinfo(WorkerGuestData& wgd, const een9::ClientRequest& req, int64_t uid) {
|
||||
return when_internalapi(wgd, req, uid, internalapi_getMessageInfo);
|
||||
}
|
||||
|
||||
std::string when_internalapi_getmessageneighbours(WorkerGuestData &wgd, const een9::ClientRequest &req, int64_t uid) {
|
||||
return when_internalapi(wgd, req, uid, internalapi_getMessageNeighbours);
|
||||
}
|
||||
|
||||
std::string when_internalapi_sendmessage(WorkerGuestData &wgd, const een9::ClientRequest &req, int64_t uid) {
|
||||
return when_internalapi(wgd, req, uid, internalapi_sendMessage);
|
||||
}
|
||||
|
||||
std::string when_internalapi_deletemessage(WorkerGuestData &wgd, const een9::ClientRequest &req, int64_t uid) {
|
||||
return when_internalapi(wgd, req, uid, internalapi_deleteMessage);
|
||||
}
|
||||
|
||||
std::string when_internalapi_addmembertochat(WorkerGuestData &wgd, const een9::ClientRequest &req, int64_t uid) {
|
||||
return when_internalapi(wgd, req, uid, internalapi_addMemberToChat);
|
||||
}
|
||||
|
||||
std::string when_internalapi_removememberfromchat(WorkerGuestData &wgd, const een9::ClientRequest &req, int64_t uid) {
|
||||
return when_internalapi(wgd, req, uid, internalapi_removeMemberFromChat);
|
||||
}
|
||||
|
||||
std::string when_internalapi_createchat(WorkerGuestData &wgd, const een9::ClientRequest &req, int64_t uid) {
|
||||
return when_internalapi(wgd, req, uid, internalapi_createChat);
|
||||
}
|
||||
|
||||
std::string when_internalapi_removechat(WorkerGuestData &wgd, const een9::ClientRequest &req, int64_t uid) {
|
||||
return when_internalapi(wgd, req, uid, internalapi_removeChat);
|
||||
}
|
||||
}
|
||||
|
@ -48,23 +48,31 @@ namespace iu9cawebchat {
|
||||
|
||||
/* ======================== API ============================== */
|
||||
|
||||
std::string when_internalapi_pollevents(WorkerGuestData& wgd,
|
||||
const een9::ClientRequest& req, int64_t uid);
|
||||
std::string when_internalapi_pollevents(WorkerGuestData& wgd, const een9::ClientRequest& req, int64_t uid);
|
||||
|
||||
std::string when_internalapi_getchatlist(WorkerGuestData& wgd,
|
||||
const een9::ClientRequest& req, int64_t uid);
|
||||
std::string when_internalapi_getchatlist(WorkerGuestData& wgd, const een9::ClientRequest& req, int64_t uid);
|
||||
|
||||
std::string when_internalapi_getchatinfo(WorkerGuestData& wgd,
|
||||
const een9::ClientRequest& req, int64_t uid);
|
||||
std::string when_internalapi_getchatinfo(WorkerGuestData& wgd, const een9::ClientRequest& req, int64_t uid);
|
||||
|
||||
std::string when_internalapi_getchatmemberlist(WorkerGuestData& wgd,
|
||||
const een9::ClientRequest& req, int64_t uid);
|
||||
std::string when_internalapi_getchatmemberlist(WorkerGuestData& wgd, const een9::ClientRequest& req, int64_t uid);
|
||||
|
||||
std::string when_internalapi_getuserinfo(WorkerGuestData& wgd,
|
||||
const een9::ClientRequest& req, int64_t uid);
|
||||
std::string when_internalapi_getuserinfo(WorkerGuestData& wgd, const een9::ClientRequest& req, int64_t uid);
|
||||
|
||||
std::string when_internalapi_getmessageinfo(WorkerGuestData& wgd,
|
||||
const een9::ClientRequest& req, int64_t uid);
|
||||
std::string when_internalapi_getmessageinfo(WorkerGuestData& wgd, const een9::ClientRequest& req, int64_t uid);
|
||||
|
||||
std::string when_internalapi_getmessageneighbours(WorkerGuestData& wgd, const een9::ClientRequest& req, int64_t uid);
|
||||
|
||||
std::string when_internalapi_sendmessage(WorkerGuestData &wgd, const een9::ClientRequest &req, int64_t uid);
|
||||
|
||||
std::string when_internalapi_deletemessage(WorkerGuestData &wgd, const een9::ClientRequest &req, int64_t uid);
|
||||
|
||||
std::string when_internalapi_addmembertochat(WorkerGuestData &wgd, const een9::ClientRequest &req, int64_t uid);
|
||||
|
||||
std::string when_internalapi_removememberfromchat(WorkerGuestData &wgd, const een9::ClientRequest &req, int64_t uid);
|
||||
|
||||
std::string when_internalapi_createchat(WorkerGuestData &wgd, const een9::ClientRequest &req, int64_t uid);
|
||||
|
||||
std::string when_internalapi_removechat(WorkerGuestData &wgd, const een9::ClientRequest &req, int64_t uid);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -48,13 +48,19 @@ namespace iu9cawebchat {
|
||||
|
||||
/* ============================= API ====================================*/
|
||||
json::JSON internalapi_pollEvents(SqliteConnection& conn, int64_t uid, const json::JSON& Sent);
|
||||
json::JSON internalapi_getChatList(SqliteConnection& conn, int64_t uid);
|
||||
json::JSON internalapi_getChatList(SqliteConnection& conn, int64_t uid, const json::JSON& Sent);
|
||||
json::JSON internalapi_getChatInfo(SqliteConnection& conn, int64_t uid, const json::JSON& Sent);
|
||||
json::JSON internalapi_getChatMemberList(SqliteConnection& conn, int64_t uid, const json::JSON& Sent);
|
||||
json::JSON internalapi_getUserInfo(SqliteConnection& conn, int64_t uid, const json::JSON& Sent);
|
||||
json::JSON internalapi_getMessageInfo(SqliteConnection& conn, int64_t uid, const json::JSON& Sent);
|
||||
json::JSON internalapi_getMessageNeighbours(SqliteConnection& conn, int64_t uid, const json::JSON& Sent);
|
||||
// todo: complete the list
|
||||
// todo: write implementations of those new cool interfaces
|
||||
json::JSON internalapi_sendMessage(SqliteConnection& conn, int64_t uid, const json::JSON& Sent);
|
||||
json::JSON internalapi_deleteMessage(SqliteConnection& conn, int64_t uid, const json::JSON& Sent);
|
||||
json::JSON internalapi_addMemberToChat(SqliteConnection& conn, int64_t uid, const json::JSON& Sent);
|
||||
json::JSON internalapi_removeMemberFromChat(SqliteConnection& conn, int64_t uid, const json::JSON& Sent);
|
||||
json::JSON internalapi_createChat(SqliteConnection& conn, int64_t uid, const json::JSON& Sent);
|
||||
json::JSON internalapi_removeChat(SqliteConnection& conn, int64_t uid, const json::JSON& Sent);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -0,0 +1,15 @@
|
||||
#include "server_data_interact.h"
|
||||
#include <engine_engine_number_9/baza_throw.h>
|
||||
|
||||
namespace iu9cawebchat {
|
||||
json::JSON internalapi_addMemberToChat(SqliteConnection& conn, int64_t uid, const json::JSON& Sent) {
|
||||
int64_t chatId = Sent["chatId"].g().asInteger().get_int();
|
||||
int64_t my_role_here = get_role_of_user_in_chat(conn, uid, chatId);
|
||||
if (my_role_here == user_chat_role_deleted)
|
||||
een9_THROW("Unauthorized user tries to access internalapi_getChatInfo");
|
||||
json::JSON Recv;
|
||||
Recv["status"] = json::JSON(0l);
|
||||
// todo: WRITE THIS MORBID THING
|
||||
return Recv;
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
#include "server_data_interact.h"
|
||||
#include <engine_engine_number_9/baza_throw.h>
|
||||
|
||||
namespace iu9cawebchat {
|
||||
json::JSON internalapi_createChat(SqliteConnection& conn, int64_t uid, const json::JSON& Sent) {
|
||||
json::JSON Recv;
|
||||
Recv["status"] = json::JSON(0l);
|
||||
// todo: WRITE THIS MORBID THING
|
||||
return Recv;
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
#include "server_data_interact.h"
|
||||
#include <engine_engine_number_9/baza_throw.h>
|
||||
|
||||
namespace iu9cawebchat {
|
||||
json::JSON internalapi_deleteMessage(SqliteConnection& conn, int64_t uid, const json::JSON& Sent) {
|
||||
int64_t chatId = Sent["chatId"].g().asInteger().get_int();
|
||||
int64_t my_role_here = get_role_of_user_in_chat(conn, uid, chatId);
|
||||
if (my_role_here == user_chat_role_deleted)
|
||||
een9_THROW("Unauthorized user tries to access internalapi_getChatInfo");
|
||||
json::JSON Recv;
|
||||
Recv["status"] = json::JSON(0l);
|
||||
// todo: WRITE THIS MORBID THING
|
||||
return Recv;
|
||||
}
|
||||
}
|
@ -2,7 +2,7 @@
|
||||
#include <engine_engine_number_9/baza_throw.h>
|
||||
|
||||
namespace iu9cawebchat {
|
||||
json::JSON internalapi_getChatList(SqliteConnection& conn, int64_t uid) {
|
||||
json::JSON internalapi_getChatList(SqliteConnection& conn, int64_t uid, const json::JSON& Sent) {
|
||||
json::JSON Recv;
|
||||
Recv["status"] = json::JSON(0l);
|
||||
Recv["chats"] = json::JSON(json::array);
|
||||
|
@ -0,0 +1,11 @@
|
||||
#include "server_data_interact.h"
|
||||
#include <engine_engine_number_9/baza_throw.h>
|
||||
|
||||
namespace iu9cawebchat {
|
||||
json::JSON internalapi_removeChat(SqliteConnection& conn, int64_t uid, const json::JSON& Sent) {
|
||||
json::JSON Recv;
|
||||
Recv["status"] = json::JSON(0l);
|
||||
// todo: WRITE THIS MORBID THING
|
||||
return Recv;
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
#include "server_data_interact.h"
|
||||
#include <engine_engine_number_9/baza_throw.h>
|
||||
|
||||
namespace iu9cawebchat {
|
||||
json::JSON internalapi_removeMemberFromChat(SqliteConnection& conn, int64_t uid, const json::JSON& Sent) {
|
||||
int64_t chatId = Sent["chatId"].g().asInteger().get_int();
|
||||
int64_t my_role_here = get_role_of_user_in_chat(conn, uid, chatId);
|
||||
if (my_role_here == user_chat_role_deleted)
|
||||
een9_THROW("Unauthorized user tries to access internalapi_getChatInfo");
|
||||
json::JSON Recv;
|
||||
Recv["status"] = json::JSON(0l);
|
||||
// todo: WRITE THIS MORBID THING
|
||||
return Recv;
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
#include "server_data_interact.h"
|
||||
#include <engine_engine_number_9/baza_throw.h>
|
||||
|
||||
namespace iu9cawebchat {
|
||||
json::JSON internalapi_sendMessage(SqliteConnection& conn, int64_t uid, const json::JSON& Sent) {
|
||||
int64_t chatId = Sent["chatId"].g().asInteger().get_int();
|
||||
int64_t my_role_here = get_role_of_user_in_chat(conn, uid, chatId);
|
||||
if (my_role_here == user_chat_role_deleted)
|
||||
een9_THROW("Unauthorized user tries to access internalapi_getChatInfo");
|
||||
json::JSON Recv;
|
||||
Recv["status"] = json::JSON(0l);
|
||||
// todo: WRITE THIS MORBID THING
|
||||
return Recv;
|
||||
}
|
||||
}
|
@ -96,10 +96,27 @@ namespace iu9cawebchat {
|
||||
if (req.uri_path == "/internalapi/getMessageInfo") {
|
||||
return when_internalapi_getmessageinfo(wgd, req, logged_in_user);
|
||||
}
|
||||
// if (req.uri_path == "/internalapi/getMessageNeighbours") {
|
||||
// return when
|
||||
// }
|
||||
// todo: write all the other interfaces
|
||||
if (req.uri_path == "/internalapi/getMessageNeighbours") {
|
||||
return when_internalapi_getmessageneighbours(wgd, req, logged_in_user);
|
||||
}
|
||||
if (req.uri_path == "/internalapi/sendMessage") {
|
||||
return when_internalapi_sendmessage(wgd, req, logged_in_user);
|
||||
}
|
||||
if (req.uri_path == "/internalapi/deleteMessage") {
|
||||
return when_internalapi_deletemessage(wgd, req, logged_in_user);
|
||||
}
|
||||
if (req.uri_path == "/internalapi/addMemberToChat") {
|
||||
return when_internalapi_addmembertochat(wgd, req, logged_in_user);
|
||||
}
|
||||
if (req.uri_path == "/internalapi/removeMemberFromChat") {
|
||||
return when_internalapi_removememberfromchat(wgd, req, logged_in_user);
|
||||
}
|
||||
if (req.uri_path == "/internalapi/createChat") {
|
||||
return when_internalapi_createchat(wgd, req, logged_in_user);
|
||||
}
|
||||
if (req.uri_path == "/internalapi/removeChat") {
|
||||
return when_internalapi_removechat(wgd, req, logged_in_user);
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
guard_.rollback = true;
|
||||
throw;
|
||||
|
Loading…
Reference in New Issue
Block a user