Database: PageDao/CategoryDao: Return 'Page' object, not pagename string
Este cometimento está contido em:
@ -5,7 +5,7 @@
|
||||
#include <optional>
|
||||
#include "queryoption.h"
|
||||
#include "../category.h"
|
||||
|
||||
#include "../page.h"
|
||||
class CategoryDao
|
||||
{
|
||||
public:
|
||||
@ -14,7 +14,7 @@ class CategoryDao
|
||||
virtual std::vector<std::string> fetchList(QueryOption o) = 0;
|
||||
virtual std::optional<Category> find(std::string name) = 0;
|
||||
virtual void deleteCategory(std::string name) = 0;
|
||||
virtual std::vector<std::string> fetchMembers(std::string name, QueryOption o) = 0;
|
||||
virtual std::vector<Page> fetchMembers(std::string name, QueryOption o) = 0;
|
||||
};
|
||||
|
||||
#endif // CATEGORYDAO_H
|
||||
|
@ -94,9 +94,10 @@ std::vector<std::string> CategoryDaoSqlite::fetchList(QueryOption o)
|
||||
}
|
||||
return result;
|
||||
}
|
||||
std::vector<std::string> CategoryDaoSqlite::fetchMembers(std::string name, QueryOption o)
|
||||
|
||||
std::vector<Page> CategoryDaoSqlite::fetchMembers(std::string name, QueryOption o)
|
||||
{
|
||||
std::vector<std::string> result;
|
||||
std::vector<Page> result;
|
||||
|
||||
SqliteQueryOption queryOption{o};
|
||||
std::string queryoptions =
|
||||
@ -104,11 +105,18 @@ std::vector<std::string> CategoryDaoSqlite::fetchMembers(std::string name, Query
|
||||
|
||||
try
|
||||
{
|
||||
auto query = *db << "SELECT page.name AS name FROM categorymember INNER JOIN page ON page.id = "
|
||||
auto query = *db << "SELECT page.id, page.name AS name, page.title, page.lastrevision, page.visible FROM categorymember INNER JOIN page ON page.id = "
|
||||
"categorymember.page WHERE category = (SELECT id FROM category WHERE name = ? ) AND " +
|
||||
queryoptions
|
||||
<< name;
|
||||
query >> [&](std::string p) { result.push_back(p); };
|
||||
query >> [&](unsigned int id, std::string name, std::string title, unsigned int lastrevision, bool visible) {
|
||||
Page p;
|
||||
p.name = name;
|
||||
p.pageid = id;
|
||||
p.title = title;
|
||||
p.current_revision = lastrevision;
|
||||
p.listed = visible;
|
||||
result.push_back(p); };
|
||||
}
|
||||
catch(const sqlite::exceptions::no_rows &e)
|
||||
{
|
||||
|
@ -3,12 +3,13 @@
|
||||
|
||||
#include "categorydao.h"
|
||||
#include "sqlitedao.h"
|
||||
#include "../page.h"
|
||||
class CategoryDaoSqlite : public CategoryDao, protected SqliteDao
|
||||
{
|
||||
public:
|
||||
CategoryDaoSqlite();
|
||||
std::vector<std::string> fetchList(QueryOption o) override;
|
||||
std::vector<std::string> fetchMembers(std::string name, QueryOption o) override;
|
||||
std::vector<Page> fetchMembers(std::string name, QueryOption o) override;
|
||||
void save(const Category &c) override;
|
||||
void deleteCategory(std::string name) override;
|
||||
std::optional<Category> find(std::string name) override;
|
||||
|
@ -15,7 +15,7 @@ class PageDao
|
||||
virtual std::optional<Page> find(std::string name) = 0;
|
||||
virtual std::optional<Page> findByTitle(std::string title) = 0;
|
||||
virtual std::optional<Page> find(unsigned int id) = 0;
|
||||
virtual std::vector<std::string> getPageList(QueryOption option) = 0;
|
||||
virtual std::vector<Page> getPageList(QueryOption option) = 0;
|
||||
virtual std::vector<std::string> fetchCategories(std::string pagename, QueryOption option) = 0;
|
||||
virtual void deletePage(std::string page) = 0;
|
||||
virtual void save(const Page &page) = 0;
|
||||
|
@ -127,21 +127,28 @@ void PageDaoSqlite::save(const Page &page)
|
||||
throwFrom(e);
|
||||
}
|
||||
}
|
||||
std::vector<std::string> PageDaoSqlite::getPageList(QueryOption option)
|
||||
|
||||
std::vector<Page> PageDaoSqlite::getPageList(QueryOption option)
|
||||
{
|
||||
std::vector<std::string> result;
|
||||
std::vector<Page> result;
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
std::string queryOption = SqliteQueryOption(option)
|
||||
.setOrderByColumn("lower(name)")
|
||||
.setVisibleColumnName("visible")
|
||||
.setPrependWhere(true)
|
||||
.build();
|
||||
std::string query = "SELECT name FROM page " + queryOption;
|
||||
std::string query = "SELECT id, name, title, lastrevision, visible FROM page " + queryOption;
|
||||
*db << query >> [&](unsigned int pageid, std::string name, std::string title,unsigned int current_revision, bool visible ) {
|
||||
|
||||
*db << query >> [&](std::string name) { result.push_back(name); };
|
||||
Page tmp;
|
||||
tmp.pageid = pageid;
|
||||
tmp.name = name;
|
||||
tmp.title = title;
|
||||
tmp.current_revision = current_revision;
|
||||
tmp.listed = visible;
|
||||
result.push_back(tmp); };
|
||||
}
|
||||
catch(const sqlite::errors::no_rows &e)
|
||||
{
|
||||
|
@ -22,7 +22,7 @@ class PageDaoSqlite : public PageDao, protected SqliteDao
|
||||
std::optional<Page> find(std::string name) override;
|
||||
std::optional<Page> findByTitle(std::string title) override;
|
||||
std::optional<Page> find(unsigned int id) override;
|
||||
std::vector<std::string> getPageList(QueryOption option) override;
|
||||
std::vector<Page> getPageList(QueryOption option) override;
|
||||
std::vector<std::string> fetchCategories(std::string pagename, QueryOption option) override;
|
||||
using SqliteDao::SqliteDao;
|
||||
int fetchPageId(std::string pagename);
|
||||
|
Criar uma nova questão referindo esta
Bloquear um utilizador