-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
292 changed files
with
15,785 additions
and
1,252 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
ADD_SUBDIRECTORY(net) | ||
ADD_SUBDIRECTORY(net) | ||
ADD_SUBDIRECTORY(http) | ||
ADD_SUBDIRECTORY(demo) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
SET(NET_LIBRARIES) | ||
|
||
IF(WIN32) | ||
MESSAGE(STATUS "Appending Windows Socket libs: wsock32 ws2_32") | ||
LIST(APPEND NET_LIBRARIES wsock32 ws2_32) | ||
ENDIF() | ||
|
||
SET (DEMO_SOURCES | ||
main.cpp | ||
services/auth_service.cpp | ||
services/auth_service.hpp | ||
models/credential.hpp | ||
models/user.hpp | ||
pages/movie_page.cpp | ||
pages/movie_page.hpp | ||
models/movie.hpp | ||
models/person.hpp | ||
services/movie_service.cpp | ||
services/movie_service.hpp pages/main_page.cpp pages/main_page.hpp) | ||
|
||
ADD_EXECUTABLE(demo ${DEMO_SOURCES}) | ||
|
||
add_custom_command(TARGET demo PRE_BUILD | ||
COMMAND ${CMAKE_COMMAND} -E copy_directory | ||
${CMAKE_SOURCE_DIR}/examples/demo/web/ $<TARGET_FILE_DIR:demo>/web) | ||
|
||
add_custom_command(TARGET demo PRE_BUILD | ||
COMMAND ${CMAKE_COMMAND} -E copy_directory | ||
${CMAKE_SOURCE_DIR}/examples/demo/templates/ $<TARGET_FILE_DIR:demo>/templates) | ||
|
||
TARGET_LINK_LIBRARIES(demo | ||
matador-utils | ||
matador-logger | ||
matador-sql | ||
matador-object | ||
matador-orm | ||
matador-net | ||
matador-http | ||
${CMAKE_DL_LIBS} | ||
${CMAKE_THREAD_LIBS_INIT} | ||
${NET_LIBRARIES} | ||
${SQLITE3_LIBRARY} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#include "services/movie_service.hpp" | ||
#include "pages/movie_page.hpp" | ||
#include "pages/main_page.hpp" | ||
|
||
#include "models/person.hpp" | ||
#include "models/movie.hpp" | ||
|
||
#include "matador/logger/log_manager.hpp" | ||
|
||
#include "matador/orm/persistence.hpp" | ||
#include "matador/orm/session.hpp" | ||
|
||
#include "matador/http/http_server.hpp" | ||
#include "matador/http/request.hpp" | ||
#include "matador/http/static_file_service.hpp" | ||
|
||
using namespace matador; | ||
|
||
int main(int /*argc*/, char* /*argv*/[]) | ||
{ | ||
// setup application logging | ||
matador::add_log_sink(matador::create_file_sink("log/server.log")); | ||
matador::add_log_sink(matador::create_stdout_sink()); | ||
|
||
// setup database | ||
matador::persistence p("sqlite://moviedb.sqlite"); | ||
p.enable_log(); | ||
|
||
|
||
p.attach<person>("person"); | ||
p.attach<movie>("movie"); | ||
|
||
p.create(); | ||
|
||
// load entities | ||
session s(p); | ||
s.load(); | ||
|
||
// initialize network stack | ||
net::init(); | ||
|
||
// create server | ||
http::server server(19082, "web"); | ||
server.add_routing_middleware(); | ||
|
||
// add routes | ||
http::serve_static_files_at("/css/*.*", server); | ||
http::serve_static_files_at("/js/*.*", server); | ||
http::serve_static_files_at("/fonts/*.*", server); | ||
|
||
main_page mainpage(server, p); | ||
movie_page moviepage(server, p); | ||
movie_service mservice(server, p); | ||
|
||
// start server | ||
server.run(); | ||
|
||
// cleanup network stack | ||
net::cleanup(); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#ifndef MATADOR_CREDENTIAL_HPP | ||
#define MATADOR_CREDENTIAL_HPP | ||
|
||
struct credential | ||
{ | ||
std::string username {}; | ||
std::string password {}; | ||
|
||
template < class S > | ||
void serialize(S &serializer) | ||
{ | ||
serializer.serialize("username", username); | ||
serializer.serialize("password", password); | ||
} | ||
}; | ||
|
||
#endif //MATADOR_CREDENTIAL_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#ifndef MATADOR_MOVIE_HPP | ||
#define MATADOR_MOVIE_HPP | ||
|
||
#include "matador/utils/identifier.hpp" | ||
#include "matador/utils/cascade_type.hpp" | ||
|
||
#include "matador/object/has_many.hpp" | ||
|
||
#include <string> | ||
#include <utility> | ||
|
||
#include "person.hpp" | ||
|
||
struct movie | ||
{ | ||
enum e_genre { | ||
ACTION, | ||
ROMANCE, | ||
COMEDY, | ||
SCIENCE_FICTION, | ||
HORROR, | ||
THRILLER | ||
}; | ||
|
||
movie() = default; | ||
movie(std::string t, unsigned short y, const matador::object_ptr<person>& dir) | ||
: title(std::move(t)), year(y), director(dir) | ||
{} | ||
|
||
matador::identifier<unsigned long> id; | ||
std::string title; | ||
matador::has_many<e_genre> genres; | ||
unsigned short year {}; | ||
matador::has_many<person> actors; | ||
matador::has_one<person> director; | ||
|
||
template < class Serializer > | ||
void serialize(Serializer &serializer) | ||
{ | ||
serializer.serialize("id", id); | ||
serializer.serialize("title", title); | ||
//serializer.serialize("genres", genres, "movie_id", "genre", matador::cascade_type::ALL); | ||
serializer.serialize("year", year); | ||
serializer.serialize("actors", actors, "movie_id", "actor_id", matador::cascade_type::NONE); | ||
serializer.serialize("director", director, matador::cascade_type::NONE); | ||
} | ||
}; | ||
#endif //MATADOR_MOVIE_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#ifndef MATADOR_PERSON_HPP | ||
#define MATADOR_PERSON_HPP | ||
|
||
#include <utility> | ||
|
||
#include "matador/utils/identifier.hpp" | ||
#include "matador/utils/date.hpp" | ||
|
||
struct person | ||
{ | ||
matador::identifier<unsigned long> id; | ||
std::string name; | ||
matador::date birthday; | ||
|
||
person() = default; | ||
person(std::string n, matador::date bd) | ||
: name(std::move(n)), birthday(std::move(bd)) | ||
{} | ||
|
||
template < class Serializer > | ||
void serialize(Serializer &serializer) | ||
{ | ||
serializer.serialize("id", id); | ||
serializer.serialize("name", name); | ||
serializer.serialize("birthday", birthday); | ||
} | ||
}; | ||
|
||
|
||
#endif //MATADOR_PERSON_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#ifndef MATADOR_USER_HPP | ||
#define MATADOR_USER_HPP | ||
|
||
|
||
struct user | ||
{ | ||
long id {}; | ||
std::string username {}; | ||
std::string password {}; | ||
std::string first_name {}; | ||
std::string last_name {}; | ||
|
||
template < class S > | ||
void serialize(S &serializer) | ||
{ | ||
serializer.serialize("id", id); | ||
serializer.serialize("username", username); | ||
serializer.serialize("password", password); | ||
serializer.serialize("first_name", first_name); | ||
serializer.serialize("last_name", last_name); | ||
} | ||
}; | ||
|
||
|
||
#endif //MATADOR_USER_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include "main_page.hpp" | ||
|
||
#include "matador/http/http_server.hpp" | ||
#include "matador/http/template_engine.hpp" | ||
|
||
#include "matador/logger/log_manager.hpp" | ||
|
||
using namespace matador; | ||
using namespace matador::http; | ||
|
||
main_page::main_page(matador::http::server &s, matador::persistence &p) | ||
: log_(matador::create_logger("MainPage")) | ||
, persistence_(p) | ||
{ | ||
file f("../templates/main.matador", "r"); | ||
auto tmpl = read_as_text(f); | ||
f.close(); | ||
|
||
index_template_ = template_engine::build(tmpl); | ||
|
||
s.on_get("/", [this](const request &req) { | ||
return view(req); | ||
}); | ||
} | ||
|
||
matador::http::response main_page::view(const matador::http::request &p) | ||
{ | ||
json data; | ||
data["title"] = "Movies"; | ||
|
||
return response::ok(template_engine::render(index_template_, data), mime_types::TYPE_TEXT_HTML); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#ifndef MATADOR_MAIN_PAGE_HPP | ||
#define MATADOR_MAIN_PAGE_HPP | ||
|
||
#include "matador/http/response.hpp" | ||
|
||
#include "matador/logger/logger.hpp" | ||
|
||
namespace matador { | ||
class persistence; | ||
namespace http { | ||
namespace detail { | ||
class template_part; | ||
} | ||
class server; | ||
class request; | ||
} | ||
} | ||
|
||
class main_page | ||
{ | ||
public: | ||
main_page(matador::http::server &s, matador::persistence &p); | ||
|
||
matador::http::response view(const matador::http::request &p); | ||
|
||
private: | ||
matador::logger log_; | ||
|
||
matador::persistence& persistence_; | ||
|
||
std::shared_ptr<matador::http::detail::template_part> index_template_; | ||
}; | ||
|
||
|
||
#endif //MATADOR_MAIN_PAGE_HPP |
Oops, something went wrong.