Skip to content

Commit

Permalink
fix operator
Browse files Browse the repository at this point in the history
  • Loading branch information
skript023 committed Apr 16, 2024
1 parent 6ba7de0 commit 2851dc8
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/interfaces/response.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace gaboot
}

template<typename U>
typename std::enable_if<!std::is_same<U, std::vector<typename U::value_type>>::value, void>::type
typename std::enable_if<std::is_same<U, T>::value, void>::type
operator=(const U& args) {
m_response = args; m_data = m_response.to_json();
}
Expand Down
5 changes: 1 addition & 4 deletions src/module/cart/services/cart_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/module/cart/services/cart_service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ namespace gaboot
}
private:
cache_handler<Carts> m_cache_cart;
response_data m_response;
response_data<CartsResponse> m_response;
};
}
13 changes: 4 additions & 9 deletions src/module/category/services/category_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/module/category/services/category_service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,9 @@ namespace gaboot
}
}
private:
response_data m_response;
response_data<CategoryResponse> m_response;
std::string m_error;
Json::Value m_data;
cache_handler<Categories> m_cache_category;
CategoryResponse m_category_response;
};
}
22 changes: 7 additions & 15 deletions src/module/product/services/product_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand All @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/module/product/services/product_service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace gaboot
}
private:
cache_handler<MasterProducts> m_cache_product;
response_data m_response;
response_data<ProductResponse> m_response;
std::string m_error;
Json::Value m_data;
Json::Value m_data_image;
Expand Down

0 comments on commit 2851dc8

Please sign in to comment.