userDao: Implement list()
这个提交包含在:
@@ -23,6 +23,7 @@ SOFTWARE.
|
||||
#include <memory>
|
||||
#include <cstring>
|
||||
#include "userdaosqlite.h"
|
||||
#include "sqlitequeryoption.h"
|
||||
|
||||
UserDaoSqlite::UserDaoSqlite()
|
||||
{
|
||||
@@ -82,6 +83,39 @@ std::optional<User> UserDaoSqlite::find(int id)
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<User> UserDaoSqlite::list(QueryOption o)
|
||||
{
|
||||
std::vector<User> result;
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
std::string queryOption = SqliteQueryOption(o).setOrderByColumn("username").setPrependWhere(true).build();
|
||||
std::string query = "SELECT username, password, salt, permissions, enabled FROM user " + queryOption;
|
||||
|
||||
*db << query >>
|
||||
[&](std::string username, std::vector<char> pw, std::vector<char> salt, int permisisons, bool enabled)
|
||||
{
|
||||
User tmp;
|
||||
tmp.login = username;
|
||||
tmp.password = pw;
|
||||
tmp.salt = salt;
|
||||
tmp.permissions = Permissions{permisisons};
|
||||
tmp.enabled = enabled;
|
||||
result.push_back(tmp);
|
||||
};
|
||||
}
|
||||
catch(const sqlite::errors::no_rows &e)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
catch(sqlite::sqlite_exception &e)
|
||||
{
|
||||
throwFrom(e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void UserDaoSqlite::deleteUser(std::string username)
|
||||
{
|
||||
// What to do with the contributions of the user?
|
||||
|
在新工单中引用
屏蔽一个用户