Introduce proper HandlerFactory and reduce dependencies of RequestWorker
Этот коммит содержится в:
@@ -18,6 +18,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "handlerfactory.h"
|
||||
#include "handler.h"
|
||||
#include "handlerdefault.h"
|
||||
@@ -31,75 +32,49 @@ SOFTWARE.
|
||||
#include "handlercategory.h"
|
||||
#include "handlerhistory.h"
|
||||
#include "handlerpagedelete.h"
|
||||
class Factory
|
||||
|
||||
std::unique_ptr<Handler> HandlerFactory::createHandler(const std::string &action, Session &userSession)
|
||||
{
|
||||
Template &templ;
|
||||
Database &db;
|
||||
Session &userSession;
|
||||
UrlProvider &urlProvider;
|
||||
ICache &cache;
|
||||
HandlerConfig &handlerConfig;
|
||||
|
||||
public:
|
||||
Factory(HandlerConfig &handlerConfig, Template &templ, Database &db, Session &usersession, UrlProvider &urlprovider,
|
||||
ICache &cache)
|
||||
: handlerConfig(handlerConfig), templ(templ), db(db), userSession(usersession), urlProvider(urlprovider),
|
||||
cache(cache)
|
||||
{
|
||||
}
|
||||
|
||||
template <class T> inline std::unique_ptr<T> produce()
|
||||
{
|
||||
return std::make_unique<T>(handlerConfig, templ, db, userSession, urlProvider, cache);
|
||||
}
|
||||
};
|
||||
|
||||
std::unique_ptr<Handler> createHandler(const std::string &action, HandlerConfig &handlerConfig, Template &templ,
|
||||
Database &db, Session &usersession, UrlProvider &urlprovider, ICache &cache)
|
||||
{
|
||||
|
||||
Factory producer(handlerConfig, templ, db, usersession, urlprovider, cache);
|
||||
|
||||
if(action == "" || action == "index")
|
||||
{
|
||||
return producer.produce<HandlerDefault>();
|
||||
return produce<HandlerDefault>(userSession);
|
||||
}
|
||||
if(action == "show")
|
||||
{
|
||||
return producer.produce<HandlerPageView>();
|
||||
return produce<HandlerPageView>(userSession);
|
||||
}
|
||||
if(action == "edit")
|
||||
{
|
||||
return producer.produce<HandlerPageEdit>();
|
||||
return produce<HandlerPageEdit>(userSession);
|
||||
}
|
||||
if(action == "login")
|
||||
{
|
||||
return producer.produce<HandlerLogin>();
|
||||
return produce<HandlerLogin>(userSession);
|
||||
}
|
||||
if(action == "search")
|
||||
{
|
||||
return producer.produce<HandlerSearch>();
|
||||
return produce<HandlerSearch>(userSession);
|
||||
}
|
||||
if(action == "delete")
|
||||
{
|
||||
return producer.produce<HandlerPageDelete>();
|
||||
return produce<HandlerPageDelete>(userSession);
|
||||
}
|
||||
if(action == "allpages")
|
||||
{
|
||||
return producer.produce<HandlerAllPages>();
|
||||
return produce<HandlerAllPages>(userSession);
|
||||
}
|
||||
if(action == "allcategories")
|
||||
{
|
||||
return producer.produce<HandlerAllCategories>();
|
||||
return produce<HandlerAllCategories>(userSession);
|
||||
}
|
||||
if(action == "showcat")
|
||||
{
|
||||
return producer.produce<HandlerCategory>();
|
||||
return produce<HandlerCategory>(userSession);
|
||||
}
|
||||
if(action == "recent")
|
||||
{
|
||||
return producer.produce<HandlerHistory>();
|
||||
return produce<HandlerHistory>(userSession);
|
||||
}
|
||||
|
||||
return producer.produce<HandlerInvalidAction>();
|
||||
return produce<HandlerInvalidAction>(userSession);
|
||||
}
|
||||
|
Ссылка в новой задаче
Block a user