mirror of
https://github.com/arcan1s/queued.git
synced 2025-07-20 17:19:56 +00:00
Pretty result usage, try to split Core class to several
This commit is contained in:
@ -28,8 +28,7 @@ QVariantHash QueuedTcpServerResponseHelperAuth::auth(const QVariantHash &_data)
|
||||
auto res = QueuedCoreAdaptor::auth(_data["user"].toString(),
|
||||
_data["password"].toString());
|
||||
|
||||
Result::match(
|
||||
res,
|
||||
res.match(
|
||||
[&output](const QString &val) {
|
||||
output = {{"code", 200}, {"token", val}};
|
||||
},
|
||||
@ -51,8 +50,8 @@ bool QueuedTcpServerResponseHelperAuth::tryAuth(const QString &_token)
|
||||
auto res = QueuedCoreAdaptor::auth(_token);
|
||||
|
||||
bool ret = true;
|
||||
Result::match(res, [&ret](const bool val) { ret = val; },
|
||||
[&ret](const QueuedError &err) { ret = false; });
|
||||
res.match([&ret](const bool val) { ret = val; },
|
||||
[&ret](const QueuedError &err) { ret = false; });
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -27,13 +27,13 @@ QueuedTcpServerResponseHelperOption::getOption(const QString &_option)
|
||||
auto res = QueuedCoreAdaptor::getOption(_option);
|
||||
|
||||
QVariantHash output;
|
||||
Result::match(res,
|
||||
[&output](const QVariant &val) {
|
||||
output = {{"code", 200}, {"token", val}};
|
||||
},
|
||||
[&output](const QueuedError &) {
|
||||
output = {{"code", 404}, {"message", "Option not found"}};
|
||||
});
|
||||
res.match(
|
||||
[&output](const QVariant &val) {
|
||||
output = {{"code", 200}, {"token", val}};
|
||||
},
|
||||
[&output](const QueuedError &) {
|
||||
output = {{"code", 404}, {"message", "Option not found"}};
|
||||
});
|
||||
|
||||
return output;
|
||||
}
|
||||
@ -51,8 +51,7 @@ QVariantHash QueuedTcpServerResponseHelperOption::setOption(
|
||||
= QueuedCoreAdaptor::sendOptionEdit(_option, _value["value"], _token);
|
||||
|
||||
QVariantHash output;
|
||||
Result::match(
|
||||
res,
|
||||
res.match(
|
||||
[&output](const QVariant &) {
|
||||
output = {{"code", 200}};
|
||||
},
|
||||
|
@ -36,8 +36,7 @@ QVariantHash QueuedTcpServerResponseHelperPermissions::addPermission(
|
||||
= QueuedCoreAdaptor::sendUserPermissionAdd(_id, permission, _token);
|
||||
|
||||
QVariantHash output;
|
||||
Result::match(
|
||||
res,
|
||||
res.match(
|
||||
[&output](const QVariant &) {
|
||||
output = {{"code", 200}};
|
||||
},
|
||||
@ -66,8 +65,7 @@ QVariantHash QueuedTcpServerResponseHelperPermissions::removePermission(
|
||||
= QueuedCoreAdaptor::sendUserPermissionRemove(_id, permission, _token);
|
||||
|
||||
QVariantHash output;
|
||||
Result::match(
|
||||
res,
|
||||
res.match(
|
||||
[&output](const QVariant &) {
|
||||
output = {{"code", 200}};
|
||||
},
|
||||
|
@ -28,8 +28,7 @@ QueuedTcpServerResponseHelperPlugins::addPlugin(const QString &_name,
|
||||
auto res = QueuedCoreAdaptor::sendPluginAdd(_name, _token);
|
||||
|
||||
QVariantHash output;
|
||||
Result::match(
|
||||
res,
|
||||
res.match(
|
||||
[&output](const bool) {
|
||||
output = {{"code", 200}};
|
||||
},
|
||||
@ -47,8 +46,7 @@ QVariantHash QueuedTcpServerResponseHelperPlugins::listPlugins()
|
||||
= QueuedCoreAdaptor::getOption(QueuedConfig::QueuedSettings::Plugins);
|
||||
|
||||
QVariantHash output;
|
||||
Result::match(
|
||||
res,
|
||||
res.match(
|
||||
[&output](const QVariant &val) {
|
||||
output = {{"code", 200}, {"plugins", val.toStringList()}};
|
||||
},
|
||||
@ -69,8 +67,7 @@ QueuedTcpServerResponseHelperPlugins::removePlugin(const QString &_name,
|
||||
auto res = QueuedCoreAdaptor::sendPluginRemove(_name, _token);
|
||||
|
||||
QVariantHash output;
|
||||
Result::match(
|
||||
res,
|
||||
res.match(
|
||||
[&output](const bool) {
|
||||
output = {{"code", 200}};
|
||||
},
|
||||
|
@ -30,8 +30,7 @@ QVariantHash QueuedTcpServerResponseHelperTask::addOrEditTask(
|
||||
if (_id > 0) {
|
||||
// edit existing task
|
||||
auto res = QueuedCoreAdaptor::sendTaskEdit(_id, defs, _token);
|
||||
Result::match(
|
||||
res,
|
||||
res.match(
|
||||
[&output](const bool val) {
|
||||
output = {{"code", val ? 200 : 500}};
|
||||
},
|
||||
@ -41,8 +40,7 @@ QVariantHash QueuedTcpServerResponseHelperTask::addOrEditTask(
|
||||
} else {
|
||||
// add new task
|
||||
auto res = QueuedCoreAdaptor::sendTaskAdd(defs, _token);
|
||||
Result::match(
|
||||
res,
|
||||
res.match(
|
||||
[&output](const long long val) {
|
||||
output = {{"code", val ? 200 : 500}, {"id", val}};
|
||||
},
|
||||
@ -98,16 +96,14 @@ QueuedTcpServerResponseHelperTask::getTask(const long long _id,
|
||||
QVariantHash output = {{"code", 200}};
|
||||
if (property.isEmpty()) {
|
||||
auto res = QueuedCoreAdaptor::getTask(_id);
|
||||
Result::match(
|
||||
res,
|
||||
res.match(
|
||||
[&output](const QVariantHash &val) { output["properties"] = val; },
|
||||
[&output](const QueuedError &err) {
|
||||
output = {{"code", 500}, {"message", err.message().c_str()}};
|
||||
});
|
||||
} else {
|
||||
auto res = QueuedCoreAdaptor::getTask(_id, property);
|
||||
Result::match(
|
||||
res,
|
||||
res.match(
|
||||
[&output, &property](const QVariant &val) {
|
||||
output["properties"] = {{property, val}};
|
||||
},
|
||||
@ -136,8 +132,7 @@ QueuedTcpServerResponseHelperTask::getTasks(const QVariantHash &_data,
|
||||
// some conversion magic
|
||||
QVariantList outputReport;
|
||||
auto res = QueuedCoreAdaptor::getTasks(userId, start, stop, _token);
|
||||
Result::match(
|
||||
res,
|
||||
res.match(
|
||||
[&output, &outputReport](const QList<QVariantHash> &val) {
|
||||
for (auto &user : val)
|
||||
outputReport += user;
|
||||
@ -160,8 +155,7 @@ QueuedTcpServerResponseHelperTask::startOrStopTask(const long long _id,
|
||||
auto res = QueuedCoreAdaptor::getTask(_id);
|
||||
|
||||
QVariantHash output;
|
||||
Result::match(
|
||||
res,
|
||||
res.match(
|
||||
[&output, &_id, &_token](const QVariantHash &val) {
|
||||
if (val["startTime"].toString().isEmpty()
|
||||
|| !val["endTime"].toString().isEmpty())
|
||||
@ -185,8 +179,7 @@ QVariantHash QueuedTcpServerResponseHelperTask::startTask(const long long _id,
|
||||
auto res = QueuedCoreAdaptor::sendTaskStart(_id, _token);
|
||||
|
||||
QVariantHash output;
|
||||
Result::match(
|
||||
res,
|
||||
res.match(
|
||||
[&output](const bool val) {
|
||||
output = {{"code", val ? 200 : 500}};
|
||||
},
|
||||
@ -206,8 +199,7 @@ QVariantHash QueuedTcpServerResponseHelperTask::stopTask(const long long _id,
|
||||
auto res = QueuedCoreAdaptor::sendTaskStop(_id, _token);
|
||||
|
||||
QVariantHash output;
|
||||
Result::match(
|
||||
res,
|
||||
res.match(
|
||||
[&output](const bool val) {
|
||||
output = {{"code", val ? 200 : 500}};
|
||||
},
|
||||
|
@ -27,8 +27,8 @@ QVariantHash QueuedTcpServerResponseHelperUser::addOrEditUser(
|
||||
// try define if user exists first
|
||||
auto userIdRes = QueuedCoreAdaptor::getUserId(_user);
|
||||
long long userId = -1;
|
||||
Result::match(userIdRes, [&userId](const long long val) { userId = val; },
|
||||
[&userId](const QueuedError &) {});
|
||||
userIdRes.match([&userId](const long long val) { userId = val; },
|
||||
[&userId](const QueuedError &) {});
|
||||
|
||||
auto defs = getDefinitions(_data);
|
||||
defs.name = _user;
|
||||
@ -37,8 +37,7 @@ QVariantHash QueuedTcpServerResponseHelperUser::addOrEditUser(
|
||||
if (userId > 0) {
|
||||
// edit existing user
|
||||
auto res = QueuedCoreAdaptor::sendUserEdit(userId, defs, _token);
|
||||
Result::match(
|
||||
res,
|
||||
res.match(
|
||||
[&output](const bool val) {
|
||||
output = {{"code", val ? 200 : 500}};
|
||||
},
|
||||
@ -48,8 +47,7 @@ QVariantHash QueuedTcpServerResponseHelperUser::addOrEditUser(
|
||||
} else {
|
||||
// add new user
|
||||
auto res = QueuedCoreAdaptor::sendUserAdd(defs, _token);
|
||||
Result::match(
|
||||
res,
|
||||
res.match(
|
||||
[&output](const long long val) {
|
||||
output = {{"code", val ? 200 : 500}, {"id", val}};
|
||||
},
|
||||
@ -69,10 +67,10 @@ QueuedTcpServerResponseHelperUser::getDefinitions(const QVariantHash &_data)
|
||||
|
||||
QueuedUser::QueuedUserDefinitions defs;
|
||||
defs.email = _data["email"].toString();
|
||||
auto res = QueuedCoreAdaptor::sendPasswordHash(_data["password"].toString());
|
||||
Result::match(
|
||||
res, [&defs](const QString &val) { defs.password = val; },
|
||||
[](const QueuedError &) {});
|
||||
auto res
|
||||
= QueuedCoreAdaptor::sendPasswordHash(_data["password"].toString());
|
||||
res.match([&defs](const QString &val) { defs.password = val; },
|
||||
[](const QueuedError &) {});
|
||||
defs.permissions = _data["permissions"].toUInt();
|
||||
// limits
|
||||
QueuedLimits::Limits limits;
|
||||
@ -102,8 +100,7 @@ QueuedTcpServerResponseHelperUser::getReport(const QVariantHash &_data,
|
||||
// some conversion magic
|
||||
QVariantList outputReport;
|
||||
auto res = QueuedCoreAdaptor::getPerformance(start, stop, _token);
|
||||
Result::match(
|
||||
res,
|
||||
res.match(
|
||||
[&output, &outputReport](const QList<QVariantHash> &val) {
|
||||
for (auto &user : val)
|
||||
outputReport += user;
|
||||
@ -125,8 +122,8 @@ QueuedTcpServerResponseHelperUser::getUser(const QString &_user,
|
||||
|
||||
auto userIdRes = QueuedCoreAdaptor::getUserId(_user);
|
||||
long long userId = -1;
|
||||
Result::match(userIdRes, [&userId](const long long val) { userId = val; },
|
||||
[](const QueuedError &) {});
|
||||
userIdRes.match([&userId](const long long val) { userId = val; },
|
||||
[](const QueuedError &) {});
|
||||
if (userId == -1)
|
||||
return {{"code", 500}};
|
||||
|
||||
@ -135,16 +132,14 @@ QueuedTcpServerResponseHelperUser::getUser(const QString &_user,
|
||||
QVariantHash output = {{"code", 200}};
|
||||
if (property.isEmpty()) {
|
||||
auto res = QueuedCoreAdaptor::getUser(userId);
|
||||
Result::match(
|
||||
res,
|
||||
res.match(
|
||||
[&output](const QVariantHash &val) { output["properties"] = val; },
|
||||
[&output](const QueuedError &err) {
|
||||
output = {{"code", 500}, {"message", err.message().c_str()}};
|
||||
});
|
||||
} else {
|
||||
auto res = QueuedCoreAdaptor::getUser(userId, property);
|
||||
Result::match(
|
||||
res,
|
||||
res.match(
|
||||
[&output, &property](const QVariant &val) {
|
||||
output["properties"] = {{property, val}};
|
||||
},
|
||||
@ -172,8 +167,7 @@ QueuedTcpServerResponseHelperUser::getUsers(const QVariantHash &_data,
|
||||
// some conversion magic
|
||||
QVariantList outputReport;
|
||||
auto res = QueuedCoreAdaptor::getUsers(lastLogin, permission, _token);
|
||||
Result::match(
|
||||
res,
|
||||
res.match(
|
||||
[&output, &outputReport](const QList<QVariantHash> &val) {
|
||||
for (auto &user : val)
|
||||
outputReport += user;
|
||||
|
Reference in New Issue
Block a user