Skip to content

Commit

Permalink
Merge pull request #45 from qicosmos/update_feather
Browse files Browse the repository at this point in the history
  • Loading branch information
qicosmos authored Feb 10, 2024
2 parents 0b277c2 + 200cc6a commit 58be3fa
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 91 deletions.
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
message(STATUS "CXX Standard: ${CMAKE_CXX_STANDARD}")

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -std=c++20")
SET(ENABLE_MYSQL ON)

SET(ENABLE_PG OFF)
SET(ENABLE_SQLITE3 OFF)

Expand Down Expand Up @@ -82,8 +84,8 @@ if (ENABLE_MYSQL)
endif()

if (ENABLE_SQLITE3)
target_link_libraries(${PROJECT_NAME} sqlite3)
target_include_directories(${PROJECT_NAME} PRIVATE ormpp)
target_link_libraries(feather sqlite3 -ldl)
target_include_directories(feather PRIVATE ormpp)
endif()

if (ENABLE_PG)
Expand Down
8 changes: 8 additions & 0 deletions feather.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
#include "iguana/json_writer.hpp"
#include "ormpp/connection_pool.hpp"
#include "ormpp/dbng.hpp"
#ifdef ORMPP_ENABLE_MYSQL
#include "ormpp/mysql.hpp"
#endif
#ifdef ORMPP_ENABLE_SQLITE3
#include "ormpp/sqlite.hpp"
#endif
#ifdef ORMPP_ENABLE_PG
#include "ormpp/postgresql.hpp"
#endif
#include "util.hpp"
#endif // FEATHER_FEATHER_H
139 changes: 66 additions & 73 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,18 @@ void init(const feather_cfg& cfg) {
nanolog::Logger::initialize(nanolog::GuaranteedLogger(), cfg.log_path,
cfg.log_name, cfg.roll_file_size);

#ifdef ORMPP_ENABLE_MYSQL
dao_t<dbng<mysql>>::init(cfg.db_conn_num, cfg.db_ip.data(),
cfg.user_name.data(), cfg.pwd.data(),
cfg.db_name.data(), cfg.timeout);
#endif
#ifdef ORMPP_ENABLE_SQLITE3
#endif
#ifdef ORMPP_ENABLE_PG
dao_t<dbng<posgresql>>::init(cfg.db_conn_num, cfg.db_ip.data(),
cfg.user_name.data(), cfg.pwd.data(),
cfg.db_name.data(), cfg.timeout);
#endif

Dao dao;
ormpp_auto_key key{SID(cncppcon2018_user::id)};
Expand Down Expand Up @@ -65,111 +74,95 @@ int main() {

purecpp_controller purecpp_ctl;
server.set_http_handler<GET, POST>(
"/login_page", &purecpp_controller::login_page, &purecpp_ctl);
"/login_page", &purecpp_controller::login_page, purecpp_ctl);
server.set_http_handler<GET, POST>("/login", &purecpp_controller::login,
&purecpp_ctl,
{std::make_shared<check_login_input>()});
purecpp_ctl, check_login_input{});
server.set_http_handler<GET, POST>(
"/sign_up_page", &purecpp_controller::sign_up_page, &purecpp_ctl);
"/sign_up_page", &purecpp_controller::sign_up_page, purecpp_ctl);
server.set_http_handler<GET, POST>("/sign_up", &purecpp_controller::sign_up,
purecpp_ctl, check_sign_out_input{});
server.set_http_handler<GET, POST>("/member_edit_page",
&purecpp_controller::member_edit_page,
purecpp_ctl, check_login{});
server.set_http_handler<GET, POST>(
"/sign_up", &purecpp_controller::sign_up, &purecpp_ctl,
{std::make_shared<check_sign_out_input>()});
server.set_http_handler<GET, POST>(
"/member_edit_page", &purecpp_controller::member_edit_page, &purecpp_ctl,
{std::make_shared<check_login>()});
server.set_http_handler<GET, POST>(
"/member_edit", &purecpp_controller::member_edit, &purecpp_ctl,
{std::make_shared<check_login>(),
std::make_shared<check_member_edit_input>()});
"/member_edit", &purecpp_controller::member_edit, purecpp_ctl,
check_login{}, check_member_edit_input{});
server.set_http_handler<GET, POST>("/quit", &purecpp_controller::quit,
&purecpp_ctl,
{std::make_shared<check_login>()});
purecpp_ctl, check_login{});

server.set_http_handler<GET, POST>(
"/course_page", &purecpp_controller::course_page, &purecpp_ctl);
server.set_http_handler<GET, POST>(
"/book_course", &purecpp_controller::book_course, &purecpp_ctl,
{std::make_shared<check_join_cncppcon2018>()});
"/course_page", &purecpp_controller::course_page, purecpp_ctl);
server.set_http_handler<GET, POST>("/book_course",
&purecpp_controller::book_course,
purecpp_ctl, check_join_cncppcon2018{});

server.set_http_handler<GET, POST>("/cncppcon_page2019",
&purecpp_controller::cncppcon_page2019,
&purecpp_ctl);
purecpp_ctl);
server.set_http_handler<GET, POST>("/cncppcon_page2019/dash",
&purecpp_controller::cncppcon_page2019,
&purecpp_ctl);
purecpp_ctl);
server.set_http_handler<GET, POST>("/cncppcon_page2019/apply/lecturer",
&purecpp_controller::cncppcon_page2019,
&purecpp_ctl);
purecpp_ctl);
server.set_http_handler<GET, POST>(
"/api/enrol/speaker", &purecpp_controller::enrol_speakers, &purecpp_ctl);
"/api/enrol/speaker", &purecpp_controller::enrol_speakers, purecpp_ctl);

server.set_http_handler<GET, POST>(
"/cncppcon_query_page2018", &purecpp_controller::cncppcon_query_page2018,
&purecpp_ctl);
server.set_http_handler<GET, POST>(
"/join_cncppcon2018", &purecpp_controller::join_cncppcon2018,
&purecpp_ctl, {std::make_shared<check_join_cncppcon2018>()});
server.set_http_handler<GET, POST>(
"/query_cncppcon2018", &purecpp_controller::query_cncppcon2018,
&purecpp_ctl, {std::make_shared<check_query_cncppcon2018>()});
purecpp_ctl);
server.set_http_handler<GET, POST>("/join_cncppcon2018",
&purecpp_controller::join_cncppcon2018,
purecpp_ctl, check_join_cncppcon2018{});
server.set_http_handler<GET, POST>("/query_cncppcon2018",
&purecpp_controller::query_cncppcon2018,
purecpp_ctl, check_query_cncppcon2018{});
server.set_http_handler<GET, POST>("/register_user_group",
&purecpp_controller::register_user_group,
&purecpp_ctl);
server.set_http_handler<GET, POST>(
"/join_user_group", &purecpp_controller::join_user_group, &purecpp_ctl,
{std::make_shared<check_join_cncppcon2018>()});

server.set_http_handler<GET>("/", &purecpp_controller::home, &purecpp_ctl,
{std::make_shared<check_start_end_input>()});
server.set_http_handler<GET>("/home", &purecpp_controller::home, &purecpp_ctl,
{std::make_shared<check_start_end_input>()});
purecpp_ctl);
server.set_http_handler<GET, POST>("/join_user_group",
&purecpp_controller::join_user_group,
purecpp_ctl, check_join_cncppcon2018{});

server.set_http_handler<GET>("/", &purecpp_controller::home, purecpp_ctl,
check_start_end_input{});
server.set_http_handler<GET>("/home", &purecpp_controller::home, purecpp_ctl,
check_start_end_input{});
server.set_http_handler<GET, POST>("/detail", &purecpp_controller::detail,
&purecpp_ctl,
{std::make_shared<check_detail_input>()});
purecpp_ctl, check_detail_input{});
server.set_http_handler<GET>("/category", &purecpp_controller::category,
&purecpp_ctl,
{std::make_shared<check_category_input>()});
purecpp_ctl, check_category_input{});
server.set_http_handler<GET, POST>("/search", &purecpp_controller::search,
&purecpp_ctl,
{std::make_shared<check_search_input>()});
purecpp_ctl, check_search_input{});

server.set_http_handler<POST>("/comment", &purecpp_controller::comment,
&purecpp_ctl,
{std::make_shared<check_login>(),
std::make_shared<check_comment_input>()});
purecpp_ctl, check_login{},
check_comment_input{});
server.set_http_handler<GET, POST>(
"/remove_comment", &purecpp_controller::remove_comment, &purecpp_ctl,
{std::make_shared<check_login>(),
std::make_shared<check_remove_comment_input>()});
"/remove_comment", &purecpp_controller::remove_comment, purecpp_ctl,
check_login{}, check_remove_comment_input{});

server.set_http_handler<GET, POST>(
"/add_post_page", &purecpp_controller::add_post_page, &purecpp_ctl,
{std::make_shared<check_login>()});
server.set_http_handler<GET, POST>("/add_post_page",
&purecpp_controller::add_post_page,
purecpp_ctl, check_login{});
server.set_http_handler<GET, POST>("/add_post", &purecpp_controller::add_post,
&purecpp_ctl,
{std::make_shared<check_login>()});
purecpp_ctl, check_login{});
server.set_http_handler<GET, POST>(
"/remove_post", &purecpp_controller::remove_post, &purecpp_ctl,
{std::make_shared<check_login>(),
std::make_shared<check_edit_post_input>()});
"/remove_post", &purecpp_controller::remove_post, purecpp_ctl,
check_login{}, check_edit_post_input{});
server.set_http_handler<GET, POST>(
"/edit_post_page", &purecpp_controller::edit_post_page, &purecpp_ctl,
{std::make_shared<check_login>(),
std::make_shared<check_edit_post_input>()});
"/edit_post_page", &purecpp_controller::edit_post_page, purecpp_ctl,
check_login{}, check_edit_post_input{});
server.set_http_handler<GET, POST>(
"/edit_post", &purecpp_controller::edit_post, &purecpp_ctl,
{std::make_shared<check_login>()});
"/edit_post", &purecpp_controller::edit_post, purecpp_ctl, check_login{});
server.set_http_handler<GET, POST>(
"/pass_post", &purecpp_controller::pass_post, &purecpp_ctl,
{std::make_shared<check_login>(),
std::make_shared<check_edit_post_input>()});
"/pass_post", &purecpp_controller::pass_post, purecpp_ctl, check_login{},
check_edit_post_input{});
server.set_http_handler<GET, POST>("/my_post", &purecpp_controller::my_post,
purecpp_ctl, check_login{},
check_start_end_input{});
server.set_http_handler<GET, POST>(
"/my_post", &purecpp_controller::my_post, &purecpp_ctl,
{std::make_shared<check_login>(),
std::make_shared<check_start_end_input>()});
server.set_http_handler<GET, POST>("/upload_file",
&purecpp_controller::upload, &purecpp_ctl,
{std::make_shared<check_login>()});
"/upload_file", &purecpp_controller::upload, purecpp_ctl, check_login{});

server.sync_start();

Expand Down
2 changes: 1 addition & 1 deletion ormpp
8 changes: 8 additions & 0 deletions purecpp_controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,15 @@ using namespace ormpp;
using namespace cinatra;

namespace feather {
#ifdef ORMPP_ENABLE_MYSQL
using Dao = dao_t<dbng<mysql>>;
#endif
#ifdef ORMPP_ENABLE_SQLITE3
using Dao = dao_t<dbng<sqlite>>;
#endif
#ifdef ORMPP_ENABLE_PG
using Dao = dao_t<dbng<postgresql>>;
#endif
class purecpp_controller {
public:
purecpp_controller() {
Expand Down
28 changes: 14 additions & 14 deletions validate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ bool len_more_than(T... args) {
return r;
}

struct check_login : public base_aspect {
struct check_login {
bool before(request& req, response& res) {
auto v = get_user_info(req);
if (v.empty() || v[0].empty()) {
Expand All @@ -42,7 +42,7 @@ struct check_login : public base_aspect {
}
};

struct check_comment_input : public base_aspect {
struct check_comment_input {
bool before(request& req, response& res) {
auto post_id = req.get_query_value("post_id");
if (!is_integer(post_id)) {
Expand Down Expand Up @@ -84,13 +84,13 @@ inline bool check_integers(request& req, response& res, T... key) {
return r;
}

struct check_remove_comment_input : public base_aspect {
struct check_remove_comment_input {
bool before(request& req, response& res) {
return check_integers(req, res, "id", "post_id");
}
};

struct check_detail_input : public base_aspect {
struct check_detail_input {
bool before(request& req, response& res) {
return check_integer(req, res, "id");
}
Expand All @@ -112,7 +112,7 @@ inline bool set_start_end(request& req, response& res, std::string& s,
return true;
}

struct check_category_input : public base_aspect {
struct check_category_input {
bool before(request& req, response& res) {
std::string s = "0";
std::string lens = "10";
Expand All @@ -130,7 +130,7 @@ struct check_category_input : public base_aspect {
}
};

struct check_search_input : public base_aspect {
struct check_search_input {
bool before(request& req, response& res) {
std::string s = "0";
std::string lens = "10";
Expand Down Expand Up @@ -160,7 +160,7 @@ struct check_search_input : public base_aspect {
}
};

struct check_start_end_input : public base_aspect {
struct check_start_end_input {
bool before(request& req, response& res) {
std::string s = "0";
std::string lens = "10";
Expand Down Expand Up @@ -196,7 +196,7 @@ inline bool check_input(response& res, T... args) {
return r;
}

struct check_login_input : public base_aspect {
struct check_login_input {
bool before(request& req, response& res) {
auto user_name = req.get_query_value("user_name");
auto password = req.get_query_value("password");
Expand All @@ -215,7 +215,7 @@ struct check_login_input : public base_aspect {
}
};

struct check_sign_out_input : public base_aspect {
struct check_sign_out_input {
bool before(request& req, response& res) {
auto user_name = req.get_query_value("user_name");
auto email = req.get_query_value("email");
Expand Down Expand Up @@ -247,7 +247,7 @@ struct check_sign_out_input : public base_aspect {
}
};

struct check_book_course : public base_aspect {
struct check_book_course {
bool before(request& req, response& res) {
// std::string result;
// for (size_t i = 0; i < req.get_form_url_map().size(); i++) {
Expand All @@ -270,7 +270,7 @@ struct check_book_course : public base_aspect {
}
};

struct check_join_cncppcon2018 : public base_aspect {
struct check_join_cncppcon2018 {
bool before(request& req, response& res) {
auto user_name = req.get_query_value("user_name");
auto email = req.get_query_value("user_email");
Expand Down Expand Up @@ -310,7 +310,7 @@ struct check_join_cncppcon2018 : public base_aspect {
}
};

struct check_query_cncppcon2018 : public base_aspect {
struct check_query_cncppcon2018 {
bool before(request& req, response& res) {
auto phone = req.get_query_value("user_phone");
auto answer = req.get_query_value("user_answer");
Expand All @@ -337,7 +337,7 @@ struct check_query_cncppcon2018 : public base_aspect {
}
};

struct check_member_edit_input : public base_aspect {
struct check_member_edit_input {
bool before(request& req, response& res) {
auto old_password = req.get_query_value("old_password");
auto new_pwd = req.get_query_value("new_password");
Expand All @@ -361,7 +361,7 @@ struct check_member_edit_input : public base_aspect {
}
};

struct check_edit_post_input : public base_aspect {
struct check_edit_post_input {
bool before(request& req, response& res) {
if (!check_integer(req, res, "id")) {
return false;
Expand Down

0 comments on commit 58be3fa

Please sign in to comment.