diff --git a/libresapi/src/api/IdentityHandler.cpp b/libresapi/src/api/IdentityHandler.cpp index 1b298467d..420d310a5 100644 --- a/libresapi/src/api/IdentityHandler.cpp +++ b/libresapi/src/api/IdentityHandler.cpp @@ -148,6 +148,7 @@ IdentityHandler::IdentityHandler(StateTokenServer *sts, RsNotify *notify, RsIden addResourceHandler("get_identity_details", this, &IdentityHandler::handleGetIdentityDetails); addResourceHandler("set_ban_node", this, &IdentityHandler::handleSetBanNode); + addResourceHandler("set_opinion", this, &IdentityHandler::handleSetOpinion); } IdentityHandler::~IdentityHandler() @@ -487,6 +488,36 @@ void IdentityHandler::handleSetBanNode(Request& req, Response& resp) resp.setOk(); } +void IdentityHandler::handleSetOpinion(Request& req, Response& resp) +{ + std::string gxs_id; + req.mStream << makeKeyValueReference("gxs_id", gxs_id); + RsGxsId gxsId(gxs_id); + + int own_opinion; + req.mStream << makeKeyValueReference("own_opinion", own_opinion); + + RsReputations::Opinion opinion; + switch(own_opinion) + { + case 0: + opinion = RsReputations::OPINION_NEGATIVE; + break; + case 1: opinion = + RsReputations::OPINION_NEUTRAL; + break; + case 2: + opinion = RsReputations::OPINION_POSITIVE; + break; + default: + resp.setFail(); + return; + } + rsReputations->setOwnOpinion(gxsId, opinion); + + resp.setOk(); +} + ResponseTask* IdentityHandler::handleOwn(Request & /* req */, Response &resp) { StateToken state; diff --git a/libresapi/src/api/IdentityHandler.h b/libresapi/src/api/IdentityHandler.h index 3824d483d..bac61f574 100644 --- a/libresapi/src/api/IdentityHandler.h +++ b/libresapi/src/api/IdentityHandler.h @@ -32,6 +32,7 @@ private: void handleGetIdentityDetails(Request& req, Response& resp); void handleSetBanNode(Request& req, Response& resp); + void handleSetOpinion(Request& req, Response& resp); ResponseTask *handleOwn(Request& req, Response& resp); ResponseTask *handleCreateIdentity(Request& req, Response& resp);