Все еще запрашиваем все записи из БД...
This commit is contained in:
@@ -14,6 +14,8 @@
|
||||
#include <odb/database.hxx>
|
||||
#include <odb/query.hxx>
|
||||
|
||||
#include <redkit-gen-modules/json_serializer.h>
|
||||
|
||||
RestApiServer::RestApiServer(odb::database& db, QObject* parent) :
|
||||
QTcpServer(parent), m_db(db) {}
|
||||
|
||||
@@ -61,9 +63,56 @@ QByteArray RestApiServer::processRequest(const QString& request)
|
||||
{
|
||||
QString author = request.section(' ', 1, 1).section('/', 3, 3).replace("%20", " ");
|
||||
|
||||
qWarning() << "THIS";
|
||||
quint64 ageReq = author.toInt();
|
||||
|
||||
qWarning() << "THIS" << author << ageReq;
|
||||
|
||||
// if (dbConn.query_one<SDB_T>(odb::query<SDB_T>::object == m_objectId, sett))
|
||||
// odb::result<Book_S> res(m_db.query<Book_S>(odb::query<Book_S>::author-> == author));
|
||||
|
||||
// {
|
||||
|
||||
QStringList nameParts = author.split(' ');
|
||||
QString firstName = nameParts.size() > 0 ? nameParts[0] : "";
|
||||
QString lastName = nameParts.size() > 1 ? nameParts[1] : "";
|
||||
|
||||
qWarning()
|
||||
<< "author:" << author << "\n"
|
||||
<< "firstName:" << firstName << "\n"
|
||||
<< "lastName:" << lastName << "\n";
|
||||
|
||||
// Result result(m_db.query<Book_S>(
|
||||
// (Query::author->m_first + " " + Query::author->m_last == authorName) ||
|
||||
// (Query::author->m_first.like("%" + firstName + "%") &&
|
||||
// Query::author->m_last.like("%" + lastName + "%"))
|
||||
// ));
|
||||
|
||||
odb::transaction t(m_db.begin());
|
||||
odb::result<Book_S> res(m_db.query<Book_S>());
|
||||
|
||||
auto books = m_db.query<Book_S>();
|
||||
|
||||
// using Query = odb::query<Author_S>;
|
||||
// auto authors = m_db.query<Author_S>(Query::id == 2);
|
||||
|
||||
auto authors = m_db.query<Author_S>();
|
||||
|
||||
for (auto book : books)
|
||||
qWarning() << book.name() << book.author()->full_name();
|
||||
|
||||
for (auto author : authors)
|
||||
qWarning() << author.full_name() << author.age();
|
||||
|
||||
// std::vector<SH<Book_S>> books(result.begin(), result.end());
|
||||
|
||||
t.commit();
|
||||
// return books;
|
||||
// }
|
||||
|
||||
// for (auto book : books)
|
||||
// qWarning() << book.author()->full_name();
|
||||
|
||||
// qWarning() << books;
|
||||
|
||||
// QList<BookRecord> results = books.getBooksByAuthor(author);
|
||||
|
||||
QByteArray jsonResponse = "{ \"books\": [";
|
||||
@@ -121,8 +170,8 @@ QByteArray RestApiServer::processRequest(const QString& request)
|
||||
|
||||
QJsonObject j;
|
||||
j["id"] = QString::number(author.id());
|
||||
j["first"] = author.first();
|
||||
j["last"] = author.last();
|
||||
j["first"] = author.firstName();
|
||||
j["last"] = author.lastName();
|
||||
j["age"] = author.age();
|
||||
jArray.push_back(j);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user