2018-11-03 17:12:20 +01:00
|
|
|
#ifndef HANDLER_H
|
|
|
|
#define HANDLER_H
|
2022-03-27 08:36:25 +02:00
|
|
|
#include <memory>
|
2019-09-29 20:27:53 +02:00
|
|
|
#include "../config.h"
|
2018-11-03 17:12:20 +01:00
|
|
|
#include "../response.h"
|
|
|
|
#include "../request.h"
|
|
|
|
#include "../template.h"
|
|
|
|
#include "../database/database.h"
|
|
|
|
#include "../urlprovider.h"
|
|
|
|
#include "../database/queryoption.h"
|
|
|
|
#include "../logger.h"
|
|
|
|
#include "../cache/icache.h"
|
2022-03-27 08:36:25 +02:00
|
|
|
#include "../dynamic/dynamiccontent.h"
|
|
|
|
|
2018-11-03 17:12:20 +01:00
|
|
|
class Handler
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
ICache *cache;
|
|
|
|
Template *templ;
|
|
|
|
Database *database;
|
|
|
|
Session *userSession;
|
|
|
|
UrlProvider *urlProvider;
|
2019-09-29 20:27:53 +02:00
|
|
|
HandlerConfig *handlersConfig;
|
2018-11-03 17:12:20 +01:00
|
|
|
|
2019-05-03 15:59:29 +02:00
|
|
|
// TODO: may not to find a better place for this method
|
|
|
|
Permissions effectivePermissions(std::string page);
|
2020-12-31 16:15:36 +01:00
|
|
|
QueryOption queryOption(const Request &r, SORT_ORDER defaultSort = ASCENDING) const;
|
2018-11-03 17:12:20 +01:00
|
|
|
|
|
|
|
public:
|
2019-09-29 20:27:53 +02:00
|
|
|
Handler(HandlerConfig &handlersConfig, Template &templ, Database &db, Session &userSession, UrlProvider &provider,
|
|
|
|
ICache &cache)
|
2018-11-03 17:12:20 +01:00
|
|
|
{
|
2019-09-29 20:27:53 +02:00
|
|
|
this->handlersConfig = &handlersConfig;
|
2018-11-03 17:12:20 +01:00
|
|
|
this->templ = &templ;
|
|
|
|
this->database = &db;
|
|
|
|
this->userSession = &userSession;
|
|
|
|
this->urlProvider = &provider;
|
|
|
|
this->cache = &cache;
|
|
|
|
}
|
2019-05-03 15:59:29 +02:00
|
|
|
|
|
|
|
virtual Response handle(const Request &r);
|
2021-10-25 17:56:37 +02:00
|
|
|
virtual Response handleRequest([[maybe_unused]] const Request &r)
|
2019-05-03 15:59:29 +02:00
|
|
|
{
|
|
|
|
return this->errorResponse("Invalid action", "This action is not implemented yet");
|
|
|
|
}
|
|
|
|
|
2021-10-25 17:56:37 +02:00
|
|
|
virtual bool canAccess([[maybe_unused]] const Permissions &perms)
|
2019-05-03 15:59:29 +02:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
virtual std::string accessErrorMessage()
|
|
|
|
{
|
|
|
|
return "No permission for this action";
|
|
|
|
}
|
2018-11-03 17:12:20 +01:00
|
|
|
void setGeneralVars(TemplatePage &page);
|
|
|
|
virtual ~Handler()
|
|
|
|
{
|
|
|
|
}
|
2022-03-27 08:36:25 +02:00
|
|
|
|
|
|
|
template <class T> inline std::shared_ptr<T> createDynamic()
|
|
|
|
{
|
|
|
|
return std::make_shared<T>(*this->templ, *this->database, *this->urlProvider);
|
|
|
|
}
|
|
|
|
|
2018-11-03 17:12:20 +01:00
|
|
|
Response errorResponse(std::string errortitle, std::string errormessage, int status = 200);
|
2019-09-29 21:34:53 +02:00
|
|
|
std::string createPageTitle(std::string append);
|
2018-11-03 17:12:20 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // HANDLER_H
|