Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

каркас сервера posts #5

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open

каркас сервера posts #5

wants to merge 15 commits into from

Conversation

amartery
Copy link
Collaborator

No description provided.

Copy link
Collaborator

@Vinograduss Vinograduss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

часть с постами пока совсем сырая, почти ничего нет

set(CMAKE_CXX_STANDARD 20)

# set(CMAKE_CXX_FLAGS "-g -Wall -lpthread -lgtest -L/usr/local/lib")
set(CMAKE_CXX_FLAGS "-g -Wall -lpthread -lgtest -L/usr/local/lib -lpqxx -lpq")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

попробуй сделать через cmake большую часть флагов, например find_package(PostgreSQL)


add_library(server_posts STATIC
${SRC_DIR}/main.cpp
${SRC_DIR}/database.cpp include/post.h)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

в библиотеке не может быть функции main()

std::vector<Post> get_all_posts();
std::vector<Post> get_user_posts(int user_id);
std::vector<Post> get_posts_for_user(int fuser_id);
Post& get_one_post(int post_id);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

методы, которые не изменяют поведения объекты, должны иметь префикс const
std::vector<Post> get_posts_for_user(int fuser_id) const

// Table Posts_;
pqxx::connection database_;
void do_modifying_request(const std::string& sql_request);
pqxx::result do_select_request(const std::string& sql_request);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

для работы с БД надо создать wrapper, в которые надо инкапсулировать функции

#include <pqxx/pqxx>
#include <map>
#include <iostream>
#include <boost/format.hpp>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

много лишних include в хедере

}
io::io_context& io_context;
tcp::acceptor acceptor;
std::optional<tcp::socket> socket;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

почему socket optional???

accept();
});
}
io::io_context& io_context;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

зачем тут ссылка?

void start() {
write("POSTS server is ready to serve");
write();
read();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

мне не реализация этой функции

}
} else {
response << "404";
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

слишком большая вложенность, вложенность больше 3-х плохо читается

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants