Update lobby via PATCH request

This commit is contained in:
Kex 2025-04-20 22:09:54 +02:00
parent 527610d599
commit 57c332b0de
3 changed files with 17 additions and 2 deletions

View file

@ -114,7 +114,7 @@ Common::WebResult RoomJson::Update() {
return Common::WebResult{Common::WebResult::Code::LibError, "Room is not registered"}; return Common::WebResult{Common::WebResult::Code::LibError, "Room is not registered"};
} }
nlohmann::json json{{"players", room.members}}; nlohmann::json json{{"players", room.members}};
return client.PostJson(fmt::format("/lobby/{}", room_id), json.dump(), false); return client.PatchJson(fmt::format("/lobby/{}", room_id), json.dump(), false);
} }
Common::WebResult RoomJson::Register() { Common::WebResult RoomJson::Register() {

View file

@ -32,7 +32,7 @@ struct Client::Impl {
} }
} }
/// A generic function handles POST, GET and DELETE request together /// A generic function handles POST, PATCH, GET and DELETE request together
Common::WebResult GenericRequest(const std::string& method, const std::string& path, Common::WebResult GenericRequest(const std::string& method, const std::string& path,
const std::string& data, bool allow_anonymous, const std::string& data, bool allow_anonymous,
const std::string& accept) { const std::string& accept) {
@ -183,6 +183,11 @@ Common::WebResult Client::DeleteJson(const std::string& path, const std::string&
return impl->GenericRequest("DELETE", path, data, allow_anonymous, "application/json"); return impl->GenericRequest("DELETE", path, data, allow_anonymous, "application/json");
} }
Common::WebResult Client::PatchJson(const std::string& path, const std::string& data,
bool allow_anonymous) {
return impl->GenericRequest("PATCH", path, data, allow_anonymous, "application/json");
}
Common::WebResult Client::GetPlain(const std::string& path, bool allow_anonymous) { Common::WebResult Client::GetPlain(const std::string& path, bool allow_anonymous) {
return impl->GenericRequest("GET", path, "", allow_anonymous, "text/plain"); return impl->GenericRequest("GET", path, "", allow_anonymous, "text/plain");
} }

View file

@ -46,6 +46,16 @@ public:
Common::WebResult DeleteJson(const std::string& path, const std::string& data, Common::WebResult DeleteJson(const std::string& path, const std::string& data,
bool allow_anonymous); bool allow_anonymous);
/**
* Patches JSON to the specified path.
* @param path the URL segment after the host address.
* @param data String of JSON data to use for the body of the PATCH request.
* @param allow_anonymous If true, allow anonymous unauthenticated requests.
* @return the result of the request.
*/
Common::WebResult PatchJson(const std::string& path, const std::string& data,
bool allow_anonymous);
/** /**
* Gets a plain string from the specified path. * Gets a plain string from the specified path.
* @param path the URL segment after the host address. * @param path the URL segment after the host address.