diff --git a/client/internal/core/include/Core.h b/client/internal/core/include/Core.h index 31d3ceec1a28f45ee60db81243b900768a9b7b2d..a981e96832b473cb1f9612d3b2c443df1d86382f 100644 --- a/client/internal/core/include/Core.h +++ b/client/internal/core/include/Core.h @@ -14,7 +14,7 @@ public: static std::vector getAllTasks(); - static Solution submitSolution(const int& task_id, const std::string& filename, const std::string& path_to_file); + static std::pair submitSolution(const int& task_id, const std::string& filename, const std::string& path_to_file); static unsigned int createTask(const std::string& name, const std::string &desc, const double& threshold); diff --git a/client/internal/core/src/Core.cpp b/client/internal/core/src/Core.cpp index 3f8acb6383f4b68bb3560d65e5c978e32bd1c506..aff4b3948a4c67923ffd028212ca536ac56908ca 100644 --- a/client/internal/core/src/Core.cpp +++ b/client/internal/core/src/Core.cpp @@ -5,7 +5,7 @@ #include "HttpClientManager.h" const std::string CLIENT_IP = "0.0.0.0"; -const std::string CLIENT_PORT = "8080"; +const std::string CLIENT_PORT = "8081"; HttpClientManager client(CLIENT_IP, CLIENT_PORT); std::size_t Core::user_id = -1; @@ -30,7 +30,7 @@ std::vector Core::getAllTasks() { return client.getAllTasks(); } -Solution Core::submitSolution(const int &task_id, const std::string& filename, const std::string &path_to_file) { +std::pair Core::submitSolution(const int &task_id, const std::string& filename, const std::string &path_to_file) { return client.submitSolution(user_id, task_id, filename, path_to_file); } diff --git a/client/internal/entities/include/Solution.h b/client/internal/entities/include/Solution.h index 4cf7061a36531ecf61daf2c070eed8a569958042..9de053725b1bb673ca41096d59a018b9ea629c06 100644 --- a/client/internal/entities/include/Solution.h +++ b/client/internal/entities/include/Solution.h @@ -8,4 +8,8 @@ struct Solution { size_t id; std::string source; std::string result; + struct Codes { + std::string original; + std::string current; + }; }; \ No newline at end of file diff --git a/client/internal/gui/include/SolutionsWindow.h b/client/internal/gui/include/SolutionsWindow.h index 3107c18d87dc5c0a8a58b5f3198ac51b2f2b810c..df2f09db91bb0346b03a4d15a0f7d0bea3370b9c 100644 --- a/client/internal/gui/include/SolutionsWindow.h +++ b/client/internal/gui/include/SolutionsWindow.h @@ -39,6 +39,12 @@ private: QPushButton* sendButton = nullptr; QTextEdit* result = nullptr; QPushButton* backButton = nullptr; + QWidget* solutionWidget = nullptr; + QGridLayout* solutionLayout = nullptr; + QLabel* originalLabel = nullptr; + QTextEdit* original = nullptr; + QLabel* currentLabel = nullptr; + QTextEdit* current = nullptr; void setupUi(QMainWindow *UserWindow); }; diff --git a/client/internal/gui/src/SolutionsWindow.cpp b/client/internal/gui/src/SolutionsWindow.cpp index af3d1f47efc3bbca4bca002dceb26071d4b8d9ab..ce1adb971fce8a2a3a1c66faeb4eea9343d9b702 100644 --- a/client/internal/gui/src/SolutionsWindow.cpp +++ b/client/internal/gui/src/SolutionsWindow.cpp @@ -34,19 +34,37 @@ void SolutionsWindow::setupUi(QMainWindow *SolutionsWindow) { taskLayout->addWidget(taskDescription); - filename = new QLabel(this); + filename = new QLabel(SolutionsWindow); - chooseFileButton = new QPushButton(this); + chooseFileButton = new QPushButton(SolutionsWindow); chooseFileButton->setText(QString::fromUtf8("Выберите файл")); - sendButton = new QPushButton(this); + sendButton = new QPushButton(SolutionsWindow); sendButton->setText(QString::fromUtf8("Отправить")); - result = new QTextEdit(this); + result = new QTextEdit(SolutionsWindow); result->setReadOnly(true); result->setText(QString::fromUtf8("Отправьте для принятия решения")); - backButton = new QPushButton(this); + solutionWidget = new QWidget(SolutionsWindow); + solutionLayout = new QGridLayout(solutionWidget); + + originalLabel = new QLabel(solutionWidget); + originalLabel->setText(QString::fromUtf8("Оригинальное решение")); + original = new QTextEdit(solutionWidget); + original->setReadOnly(true); + + currentLabel = new QLabel(solutionWidget); + currentLabel->setText(QString::fromUtf8("Ваше решение")); + current = new QTextEdit(solutionWidget); + current->setReadOnly(true); + + solutionLayout->addWidget(currentLabel, 0, 0); + solutionLayout->addWidget(originalLabel, 0, 1); + solutionLayout->addWidget(current, 1, 0); + solutionLayout->addWidget(original, 1, 1); + + backButton = new QPushButton(SolutionsWindow); backButton->setText(QString::fromUtf8("Назад")); verticalLayout->addWidget(taskBox); @@ -54,6 +72,7 @@ void SolutionsWindow::setupUi(QMainWindow *SolutionsWindow) { verticalLayout->addWidget(chooseFileButton); verticalLayout->addWidget(sendButton); verticalLayout->addWidget(result); + verticalLayout->addWidget(solutionWidget); verticalLayout->addWidget(backButton); SolutionsWindow->setCentralWidget(centralwidget); @@ -75,8 +94,12 @@ void SolutionsWindow::on_sendButton_clicked() { QMessageBox::warning(this, "Ошибка отправки", "Файл должен быть указан"); return; } - Solution sol = Core::submitSolution(task.id, filename->text().toUtf8().constData(), path_to_file); + Solution sol; + Solution::Codes codes; + std::tie(sol, codes) = Core::submitSolution(task.id, filename->text().toUtf8().constData(), path_to_file); result->setText(QString::fromStdString(sol.result)); + original->setText(QString::fromUtf8(codes.original)); + current->setText(QString::fromUtf8(codes.current)); } diff --git a/client/internal/httpClient/include/HttpClientManager.h b/client/internal/httpClient/include/HttpClientManager.h index 2d15f7f36a4491a9f978d2102cde0158cf020d0a..be95a33d103cb6bdc420026b05ac2a1190eed188 100644 --- a/client/internal/httpClient/include/HttpClientManager.h +++ b/client/internal/httpClient/include/HttpClientManager.h @@ -19,7 +19,7 @@ public: std::pair loginUser(const std::string &login, const std::string &password); std::pair registerUser(const std::string &login, const std::string &username, const std::string &password); - Solution submitSolution(const int& user_id, const int &task_id, const std::string& filename, + std::pair submitSolution(const int& user_id, const int &task_id, const std::string& filename, const std::string &path_to_solution); unsigned int getAllSolutionsForTask(const int& user_id, const int& task_id); std::vector getAllTasks(); diff --git a/client/internal/httpClient/include/Serializer.h b/client/internal/httpClient/include/Serializer.h index ba742f25d78499aa473e5a4dc516ed5f2cea5ab9..a63ffd3f8b763d170b889b1cc80f962f7d3e3d26 100644 --- a/client/internal/httpClient/include/Serializer.h +++ b/client/internal/httpClient/include/Serializer.h @@ -17,6 +17,7 @@ public: User deserialUserData(std::string_view body); Solution deserialSolutionData(std::string_view body); + std::pair deserialNewSolutionData(std::string_view body); std::vector deserialAllTasks(std::string_view body); }; diff --git a/client/internal/httpClient/src/HttpClientManager.cpp b/client/internal/httpClient/src/HttpClientManager.cpp index a8831c0e0ffd1ab4c0acf7db21cdd29a405fdd37..2f1908747ec56c6519f6f30707b65b7b109a8299 100644 --- a/client/internal/httpClient/src/HttpClientManager.cpp +++ b/client/internal/httpClient/src/HttpClientManager.cpp @@ -43,7 +43,7 @@ std::pair HttpClientManager::registerUser(const std::string &log return {status, user}; } -Solution HttpClientManager::submitSolution(const int &user_id, const int &task_id, const std::string& filename, +std::pair HttpClientManager::submitSolution(const int &user_id, const int &task_id, const std::string& filename, const std::string &path_to_sound) { std::string body = serializer->serialSolutionData(user_id, task_id, filename, path_to_sound); http::response res = client->makeGetRequest("/solution/submit", body); @@ -54,8 +54,10 @@ Solution HttpClientManager::submitSolution(const int &user_id, const int &task_i auto* cbuf = boost::asio::buffer_cast(seq); res_body.append(cbuf, boost::asio::buffer_size(seq)); } - Solution sol = serializer->deserialSolutionData(res_body); - return sol; + Solution sol; + Solution::Codes codes; + std::tie(sol, codes) = serializer->deserialNewSolutionData(res_body); + return {sol, codes}; } unsigned int HttpClientManager::getAllSolutionsForTask(const int &user_id, const int &task_id) { diff --git a/client/internal/httpClient/src/Serializer.cpp b/client/internal/httpClient/src/Serializer.cpp index c2d803d4afb44f56685f46006f621504a6cda73a..c4a505ebc9b141ceaaef9788f17aca49f2b02e86 100644 --- a/client/internal/httpClient/src/Serializer.cpp +++ b/client/internal/httpClient/src/Serializer.cpp @@ -82,6 +82,23 @@ Solution Serializer::deserialSolutionData(std::string_view body) { return res; } +std::pair Serializer::deserialNewSolutionData(std::string_view body) { + std::stringstream ss; + ss << body; + boost::property_tree::ptree json; + boost::property_tree::read_json(ss, json); + Solution sol = { + json.get("sol_id"), + json.get("source"), + json.get("result"), + }; + Solution::Codes codes = { + json.get("original"), + json.get("your_code"), + }; + return {sol, codes}; +} + std::string Serializer::serialNewTaskData(std::string_view name, std::string_view desc, double threshold) { boost::property_tree::ptree json; json.put("name", name); diff --git a/server/internal/httpServer/include/Serializer.h b/server/internal/httpServer/include/Serializer.h index 9790ac5d06e23043f8907771307d82ef75eda168..35ab279322674d9d8a33890b379c088da5b9df40 100644 --- a/server/internal/httpServer/include/Serializer.h +++ b/server/internal/httpServer/include/Serializer.h @@ -22,6 +22,7 @@ class Serializer { std::string serialAllTasks(const std::vector& tasks); std::string serialUserData(const User& user); std::string serialSolution(const Solution& sol); + std::string serialNewSolution(const Solution& sol, const Solution::Codes& codes); std::string serialTask(const Task& task); }; diff --git a/server/internal/httpServer/src/Serializer.cpp b/server/internal/httpServer/src/Serializer.cpp index 72085bc2a8abab6a3b58d3f6e6d6021aec3d5cac..dda60b1d29f7a33581fc4f3e3c1cc9b01388046f 100644 --- a/server/internal/httpServer/src/Serializer.cpp +++ b/server/internal/httpServer/src/Serializer.cpp @@ -116,6 +116,18 @@ std::string Serializer::serialSolution(const Solution &sol) { return out.str(); } +std::string Serializer::serialNewSolution(const Solution &sol, const Solution::Codes& codes) { + boost::property_tree::ptree json; + json.put("sol_id", sol.getId()); + json.put("source", sol.getSource()); + json.put("result", sol.getResult()); + json.put("your_code", codes.current); + json.put("original", codes.original); + std::stringstream out; + boost::property_tree::write_json(out, json); + return out.str(); +} + std::string Serializer::serialTask(const Task &task) { boost::property_tree::ptree json; json.put("name", task.getName()); diff --git a/server/internal/httpServer/src/SolutionManager.cpp b/server/internal/httpServer/src/SolutionManager.cpp index 3bd96df48345c8b1841794495ace0ca09ce665b2..3a6a1f56fb4932d1b67dc3d3f5c42143c9cdeb9a 100644 --- a/server/internal/httpServer/src/SolutionManager.cpp +++ b/server/internal/httpServer/src/SolutionManager.cpp @@ -24,13 +24,14 @@ http::message_generator SolutionManager::createSolution(http::requestcreateSolution(user_id, task_id, filename, filedata).first; + Solution sol; + Solution::Codes codes; + std::tie(sol, codes) = solutionService->createSolution(user_id, task_id, filename, filedata); http::response res{http::status::ok, req.version()}; res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::content_type, "text/plain"); res.keep_alive(req.keep_alive()); - res.body() = serializer->serialSolution(sol); - res.prepare_payload(); + res.body() = serializer->serialNewSolution(sol, codes); return res; } catch (const std::exception& e) { return getInternalServerError(req, e.what());