forked from matth-x/MicroOcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCancelReservation.cpp
More file actions
45 lines (37 loc) · 1.25 KB
/
Copy pathCancelReservation.cpp
File metadata and controls
45 lines (37 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// matth-x/ArduinoOcpp
// Copyright Matthias Akstaller 2019 - 2023
// MIT License
#include <ArduinoOcpp/Operations/CancelReservation.h>
#include <ArduinoOcpp/Model/Model.h>
#include <ArduinoOcpp/Model/Reservation/ReservationService.h>
#include <ArduinoOcpp/Debug.h>
using ArduinoOcpp::Ocpp16::CancelReservation;
CancelReservation::CancelReservation(Model& model) : model(model) {
}
const char* CancelReservation::getOperationType(){
return "CancelReservation";
}
void CancelReservation::processReq(JsonObject payload) {
if (!payload.containsKey("reservationId")) {
errorCode = "FormationViolation";
return;
}
if (model.getReservationService()) {
if (auto reservation = model.getReservationService()->getReservationById(payload["reservationId"])) {
found = true;
reservation->clear();
}
} else {
errorCode = "InternalError";
}
}
std::unique_ptr<DynamicJsonDocument> CancelReservation::createConf(){
auto doc = std::unique_ptr<DynamicJsonDocument>(new DynamicJsonDocument(JSON_OBJECT_SIZE(1)));
JsonObject payload = doc->to<JsonObject>();
if (found) {
payload["status"] = "Accepted";
} else {
payload["status"] = "Rejected";
}
return doc;
}