0xc3 1 month ago
parent
commit
96e8a7cecb

+ 35 - 1
src/saura/cmd/sandbox/sandbox.cpp

@@ -155,6 +155,33 @@ struct SandboxApp : AppBase {
         ImGui::EndTabItem();
       }
 
+      if (ImGui::BeginTabItem("Заявки")) {
+        ImGui::EndTabItem();
+      }
+
+      if (ImGui::BeginTabItem("Ремонты")) {
+        ImGuiTableFlags flags =
+            ImGuiTableFlags_Resizable | ImGuiTableFlags_Borders |
+            ImGuiTableFlags_SizingStretchProp | ImGuiTableFlags_ScrollY;
+
+        if (ImGui::BeginTable("UserDataTable", 6, flags)) {
+          ImGui::TableSetupColumn("#");
+          ImGui::TableSetupColumn("Клиент");
+          ImGui::TableSetupColumn("Статус");
+          ImGui::TableSetupColumn("Устройство");
+          ImGui::TableSetupColumn(""); // Edit
+          ImGui::TableSetupColumn(""); // Delete
+          ImGui::TableHeadersRow();
+
+          ImGui::EndTable();
+        }
+        ImGui::EndTabItem();
+      }
+
+      if (ImGui::BeginTabItem("Продажи")) {
+        ImGui::EndTabItem();
+      }
+
       if (ImGui::BeginTabItem("Клиенты")) {
         ImGuiTableFlags flags =
             ImGuiTableFlags_Resizable | ImGuiTableFlags_Borders |
@@ -254,7 +281,13 @@ struct SandboxApp : AppBase {
 
             ImGui::TableNextColumn();
             ImGui::PushID(fmt::format("{}Delete", idx).c_str());
-            ImGui::Button("Delete");
+            if (ImGui::Button("Delete")) {
+              if (server_api_ctx->send_delete(fmt::format("http://api.localhost:8090/v1/example/client?id={}", client.id))) {
+                if (idx < clients.size()) {
+                  clients.erase(clients.begin() + idx);
+                }
+              }
+            }
             ImGui::PopID();
           }
 
@@ -349,6 +382,7 @@ struct SandboxApp : AppBase {
         ImGui::Text("Hello");
         ImGui::EndTabItem();
       }
+
       ImGui::EndTabBar();
     }
 

+ 9 - 2
src/saura/cmd/sandbox/server/server.cpp

@@ -33,6 +33,14 @@ void ServerAPI::run() {
   }
 }
 
+bool ServerAPI::send_delete(std::string url) {
+  auto res = cpr::Delete(cpr::Url(url), cpr::Timeout(1000));
+  if (res.status_code == 200) {
+      return true;
+  }
+  return false;
+}
+
 std::vector<ClientInfo> ServerAPI::fetch_clients(uint32_t limit,
                                                  uint32_t offset) {
 
@@ -68,8 +76,7 @@ std::vector<ClientInfo> ServerAPI::fetch_clients(uint32_t limit,
   return clients;
 }
 
-std::vector<UserInfo> ServerAPI::fetch_users(uint32_t limit,
-                                                 uint32_t offset) {
+std::vector<UserInfo> ServerAPI::fetch_users(uint32_t limit, uint32_t offset) {
 
   std::vector<UserInfo> users;
 

+ 2 - 0
src/saura/cmd/sandbox/server/server.hpp

@@ -17,6 +17,8 @@ public:
 
   void run();
 
+  bool send_delete(std::string url);
+
   std::vector<ClientInfo> fetch_clients(uint32_t limit, uint32_t offset);
   std::vector<UserInfo> fetch_users(uint32_t limit, uint32_t offset);
 };