From 2851dc87beb789c0fba7f74e2149c3f558d6501d Mon Sep 17 00:00:00 2001 From: Fatur Muhammad Date: Wed, 17 Apr 2024 01:57:44 +0700 Subject: [PATCH] fix operator --- src/interfaces/response.hpp | 2 +- src/module/cart/services/cart_service.cpp | 5 +---- src/module/cart/services/cart_service.hpp | 2 +- .../category/services/category_service.cpp | 13 ++++------- .../category/services/category_service.hpp | 3 +-- .../product/services/product_service.cpp | 22 ++++++------------- .../product/services/product_service.hpp | 2 +- 7 files changed, 16 insertions(+), 33 deletions(-) diff --git a/src/interfaces/response.hpp b/src/interfaces/response.hpp index 764fe9d..e12558f 100644 --- a/src/interfaces/response.hpp +++ b/src/interfaces/response.hpp @@ -47,7 +47,7 @@ namespace gaboot } template - typename std::enable_if>::value, void>::type + typename std::enable_if::value, void>::type operator=(const U& args) { m_response = args; m_data = m_response.to_json(); } diff --git a/src/module/cart/services/cart_service.cpp b/src/module/cart/services/cart_service.cpp index 092ed0f..34e65e5 100644 --- a/src/module/cart/services/cart_service.cpp +++ b/src/module/cart/services/cart_service.cpp @@ -75,10 +75,7 @@ namespace gaboot return HttpResponse::newHttpJsonResponse(m_response.to_json()); } - std::ranges::for_each(carts.begin(), carts.end(), [this](Carts const& cart) { - CartsResponse c = cart; - m_response.m_data.append(c.to_json()); - }); + m_response = carts; m_response.m_message = "Success retreive carts data"; m_response.m_success = true; diff --git a/src/module/cart/services/cart_service.hpp b/src/module/cart/services/cart_service.hpp index c066158..a268bd1 100644 --- a/src/module/cart/services/cart_service.hpp +++ b/src/module/cart/services/cart_service.hpp @@ -47,6 +47,6 @@ namespace gaboot } private: cache_handler m_cache_cart; - response_data m_response; + response_data m_response; }; } \ No newline at end of file diff --git a/src/module/category/services/category_service.cpp b/src/module/category/services/category_service.cpp index 6655846..444931a 100644 --- a/src/module/category/services/category_service.cpp +++ b/src/module/category/services/category_service.cpp @@ -86,10 +86,7 @@ namespace gaboot Json::Value data(Json::arrayValue); - std::ranges::for_each(categories.begin(), categories.end(), [this](Categories const& category) { - m_category_response = category; - m_response.m_data.append(m_category_response.to_json()); - }); + m_response = categories; const size_t lastPage = (categories.size() / (limit + (categories.size() % limit))) == 0 ? 0 : 1; @@ -111,15 +108,13 @@ namespace gaboot this->load_cache(); - const auto category = m_cache_category.find(id); - - if (!category) throw NotFoundException("Unable retrieve category detail"); + CategoryResponse category = m_cache_category.find(id); - m_category_response = category; + if (!&category) throw NotFoundException("Unable retrieve category detail"); m_response.m_message = "Success retrieve category data"; m_response.m_success = true; - m_response.m_data = m_category_response.to_json(); + m_response.m_data = category.to_json(); return HttpResponse::newHttpJsonResponse(m_response.to_json()); } EXCEPT_CLAUSE diff --git a/src/module/category/services/category_service.hpp b/src/module/category/services/category_service.hpp index eb64426..6efea9e 100644 --- a/src/module/category/services/category_service.hpp +++ b/src/module/category/services/category_service.hpp @@ -49,10 +49,9 @@ namespace gaboot } } private: - response_data m_response; + response_data m_response; std::string m_error; Json::Value m_data; cache_handler m_cache_category; - CategoryResponse m_category_response; }; } \ No newline at end of file diff --git a/src/module/product/services/product_service.cpp b/src/module/product/services/product_service.cpp index 89d8898..c73618b 100644 --- a/src/module/product/services/product_service.cpp +++ b/src/module/product/services/product_service.cpp @@ -35,10 +35,7 @@ namespace gaboot return HttpResponse::newHttpJsonResponse(m_response.to_json()); } - std::ranges::for_each(products.begin(), products.end(), [this](MasterProducts const& product) { - m_product_response = product; - m_response << m_product_response; - }); + m_response = products; const size_t lastPage = (products.size() / (limit + (products.size() % limit))) == 0 ? 0 : 1; @@ -120,11 +117,13 @@ namespace gaboot this->load_cache(); - m_product_response = m_cache_product.find(id); + ProductResponse product = m_cache_product.find(id); + + m_response = product; m_response.m_message = "Success retrieve products data"; m_response.m_success = true; - m_response = m_product_response; + m_response.m_data = product.to_json(); return HttpResponse::newHttpJsonResponse(m_response.to_json()); } EXCEPT_CLAUSE @@ -247,10 +246,7 @@ namespace gaboot throw NotFoundException("Product which related to that category not found"); } - std::ranges::for_each(products.begin(), products.end(), [this](MasterProducts const& product) { - m_product_response = product; - m_response << m_product_response; - }); + m_response = products; const size_t lastPage = (products.size() / (limit + (products.size() % limit))) == 0 ? 0 : 1; @@ -272,11 +268,7 @@ namespace gaboot const size_t page = pageParam.empty() && !util::is_numeric(pageParam) ? 0 : stoull(pageParam) - 1; const auto products = db().findAll(); - std::ranges::for_each(products.begin(), products.end(), [this](MasterProducts product) { - m_product_response = product; - m_product_response.push(product.getProduct_images(DATABASE_CLIENT)); - m_response << m_product_response; - }); + m_response = products; const size_t lastPage = (products.size() / (limit + (products.size() % limit))) == 0 ? 0 : 1; diff --git a/src/module/product/services/product_service.hpp b/src/module/product/services/product_service.hpp index 1f90287..0089d42 100644 --- a/src/module/product/services/product_service.hpp +++ b/src/module/product/services/product_service.hpp @@ -50,7 +50,7 @@ namespace gaboot } private: cache_handler m_cache_product; - response_data m_response; + response_data m_response; std::string m_error; Json::Value m_data; Json::Value m_data_image;