更完
This commit is contained in:
@@ -34,6 +34,20 @@ struct Mode_Base {
|
||||
struct Config : Runtime_Base, Mode_Base {
|
||||
std::string name{"default"};
|
||||
};
|
||||
|
||||
class Runtime_Control final {
|
||||
public:
|
||||
Runtime_Control() = default;
|
||||
Runtime_Control(const Runtime_Control&) = delete;
|
||||
Runtime_Control& operator=(const Runtime_Control&) = delete;
|
||||
|
||||
[[nodiscard]] int setting() const noexcept { return setting_; }
|
||||
void apply_setting(int value) noexcept { setting_ = value; }
|
||||
|
||||
private:
|
||||
int setting_{3};
|
||||
};
|
||||
|
||||
}
|
||||
namespace adminive {
|
||||
template <>
|
||||
@@ -263,6 +277,21 @@ struct Type_Descriptor<adapter_test::Config> {
|
||||
}
|
||||
};
|
||||
template <>
|
||||
struct Type_Descriptor<adapter_test::Runtime_Control> {
|
||||
static auto get() {
|
||||
auto accessor = structive::trusted_callable_accessor<adapter_test::Runtime_Control>(
|
||||
[](const adapter_test::Runtime_Control& value) { return value.setting(); },
|
||||
[](adapter_test::Runtime_Control& target, int value) {
|
||||
target.apply_setting(value);
|
||||
});
|
||||
return adminive::object<adapter_test::Runtime_Control>(
|
||||
"runtime_control", "Runtime Control",
|
||||
adminive::field("setting", "Setting", std::move(accessor))
|
||||
.editable()
|
||||
.unsynchronized());
|
||||
}
|
||||
};
|
||||
template <>
|
||||
struct Type_View_Descriptor<adapter_test::Config> {
|
||||
static Table_View table() {
|
||||
using T = adapter_test::Config;
|
||||
@@ -295,6 +324,16 @@ int main() {
|
||||
const Json encoded = adminive::to_json<Json>(config);
|
||||
ADMINIVE_CHECK((adminive::json_get<Json, int>(adminive::Json_Adapter<Json>::at(encoded, "worker_count")) == 12));
|
||||
ADMINIVE_CHECK((adminive::json_get<Json, std::string>(adminive::Json_Adapter<Json>::at(encoded, "mode")) == "secondary"));
|
||||
adapter_test::Runtime_Control runtime_control;
|
||||
const Json runtime_encoded = adminive::to_json<Json>(runtime_control);
|
||||
ADMINIVE_CHECK((adminive::json_get<Json, int>(
|
||||
adminive::Json_Adapter<Json>::at(runtime_encoded, "setting")) == 3));
|
||||
Json runtime_patch = adminive::json_object<Json>();
|
||||
adminive::json_set(runtime_patch, "setting", 17);
|
||||
const auto runtime_result =
|
||||
adminive::apply_frontend_patch<Json>(runtime_control, runtime_patch);
|
||||
ADMINIVE_CHECK(runtime_result.success);
|
||||
ADMINIVE_CHECK(runtime_control.setting() == 17);
|
||||
adminive::Collection_Service<Config, Json, adminive::No_Lock> collection("/configs", {Config{}});
|
||||
const auto list = collection.list_response();
|
||||
ADMINIVE_CHECK(list.status == 200);
|
||||
|
||||
Reference in New Issue
Block a user