Skip to content

Commit 1969273

Browse files
committed
const all the things as many as possible
1 parent bcf6644 commit 1969273

File tree

7 files changed

+13
-14
lines changed

7 files changed

+13
-14
lines changed

rest/controller/MeterReadingController.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class MeterReadingController {
4040
MeterReadingController(ElectricityReadingService &electricityReadingService, MeterReadingService &meterReadingService)
4141
: electricityReadingService_(electricityReadingService), meterReadingService_(meterReadingService) {}
4242

43-
http::response<http::string_body> Read(const http::request<http::string_body> &req, const std::vector<std::string> &queries) {
43+
http::response<http::string_body> Read(const http::request<http::string_body> &req, const std::vector<std::string> &queries) const {
4444
const auto &meterId = queries[0];
4545
auto readings = electricityReadingService_.GetReading(meterId);
4646

@@ -78,7 +78,7 @@ class MeterReadingController {
7878
ElectricityReadingService &electricityReadingService_;
7979
MeterReadingService &meterReadingService_;
8080
bool IsMeterReadingsValid(const nlohmann::basic_json<> &smartMeterId,
81-
const nlohmann::basic_json<> &electricityReadings) {
81+
const nlohmann::basic_json<> &electricityReadings) const {
8282
if (smartMeterId.type() == nlohmann::json::value_t::null || electricityReadings.empty()) {
8383
return false;
8484
}

rest/controller/PricePlanComparatorController.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class PricePlanComparatorController {
1919
PricePlanComparatorController(PricePlanService &pricePlanService) : pricePlanService_(pricePlanService) {}
2020

2121
http::response<http::string_body> Compare(const http::request<http::string_body> &req,
22-
const std::vector<std::string> &queries) {
22+
const std::vector<std::string> &queries) const {
2323
const auto &meterId = queries[0];
2424
auto costs = pricePlanService_.getConsumptionCostOfElectricityReadingsForEachPricePlan(meterId);
2525

@@ -42,7 +42,7 @@ class PricePlanComparatorController {
4242
}
4343

4444
http::response<http::string_body> Recommend(const http::request<http::string_body> &req,
45-
const std::vector<std::string> &queries) {
45+
const std::vector<std::string> &queries) const {
4646
const auto &meterId = queries[0];
4747
std::optional<int> maybeLimit;
4848
if (queries.size() > 2){

rest/domain/MeterReadings.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ class MeterReadings {
1313
MeterReadings(std::string smartMeterId, std::list<ElectricityReading> electricityReadings)
1414
: smartMeterId_(smartMeterId), electricityReadings_(electricityReadings){};
1515

16-
std::list<ElectricityReading> getElectricityReadings() { return electricityReadings_; }
16+
std::list<ElectricityReading> getElectricityReadings() const { return electricityReadings_; }
1717

18-
std::string getSmartMeterId() { return smartMeterId_; }
18+
std::string getSmartMeterId() const { return smartMeterId_; }
1919

2020
private:
2121
std::list<ElectricityReading> electricityReadings_;

rest/router.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace http = beast::http;
1313
class router {
1414
public:
1515
template <class Body = http::string_body>
16-
auto handler() {
16+
auto handler() const {
1717
return [&](const http::request<Body> &req) -> http::response<http::string_body> {
1818
const auto uri = req.target();
1919
for (auto &[path, handler] : handlers_) {
@@ -38,7 +38,7 @@ class router {
3838

3939
private:
4040
template <class Body, class Allocator>
41-
auto make_not_found(const http::request<Body, http::basic_fields<Allocator>> &req, beast::string_view target) {
41+
static auto make_not_found(const http::request<Body, http::basic_fields<Allocator>> &req, beast::string_view target) {
4242
http::response<http::string_body> res{http::status::not_found, req.version()};
4343
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
4444
res.set(http::field::content_type, "text/html");

rest/service/ElectricityReadingService.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class ElectricityReadingService {
1313
ElectricityReadingService(std::unordered_map<std::string, std::vector<ElectricityReading>> &meterAssociatedReadings)
1414
: meterAssociatedReadings_(meterAssociatedReadings) {}
1515

16-
std::optional<std::vector<ElectricityReading>> GetReading(const std::string &meterId) {
16+
std::optional<std::vector<ElectricityReading>> GetReading(const std::string &meterId) const {
1717
auto found = meterAssociatedReadings_.find(meterId);
1818
if (found != meterAssociatedReadings_.end()) {
1919
return found->second;

rest/service/MeterReadingService.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
class MeterReadingService {
2020
public:
21-
std::optional<std::vector<ElectricityReading>> getReadings(const std::string &smartMeterId) {
21+
std::optional<std::vector<ElectricityReading>> getReadings(const std::string &smartMeterId) const {
2222
std::shared_lock<std::shared_mutex> lock(mtx_);
2323
if (meterAssociatedReadings_.find(smartMeterId) == meterAssociatedReadings_.end()) {
2424
return {};

rest/service/PricePlanService.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class PricePlanService {
1616
public:
1717
using time_point_type = std::chrono::time_point<std::chrono::system_clock>;
1818

19-
std::optional<std::map<std::string, int>> getConsumptionCostOfElectricityReadingsForEachPricePlan(std::string smartMeterId) {
19+
std::optional<std::map<std::string, int>> getConsumptionCostOfElectricityReadingsForEachPricePlan(const std::string &smartMeterId) const {
2020
std::optional<std::vector<ElectricityReading>> electricityReadings = meterReadingService_.getReadings(smartMeterId);
2121
if (!electricityReadings.has_value()) {
2222
return {};
@@ -37,11 +37,10 @@ class PricePlanService {
3737
const std::vector<PricePlan> &pricePlans_;
3838
MeterReadingService &meterReadingService_;
3939

40-
static auto calculateTimeElapsed(std::vector<ElectricityReading> electricityReadings) {
40+
static auto calculateTimeElapsed(const std::vector<ElectricityReading> &electricityReadings) {
4141
ElectricityReading first = *electricityReadings.begin();
4242
ElectricityReading last = *electricityReadings.begin();
43-
std::vector<ElectricityReading>::iterator it;
44-
for (it = electricityReadings.begin(); it != electricityReadings.end(); it++) {
43+
for (auto it = electricityReadings.begin(); it != electricityReadings.end(); it++) {
4544
if (it->getTime() < first.getTime()) {
4645
first = *it;
4746
}

0 commit comments

Comments
 (0)