| 46 | }; |
| 47 | |
| 48 | bool TypeQueryHandler::HandleRequest( |
| 49 | const WaitGroup::Ptr&, |
| 50 | const HttpApiRequest& request, |
| 51 | HttpApiResponse& response, |
| 52 | boost::asio::yield_context& yc |
| 53 | ) |
| 54 | { |
| 55 | namespace http = boost::beast::http; |
| 56 | |
| 57 | auto url = request.Url(); |
| 58 | auto user = request.User(); |
| 59 | auto params = request.Params(); |
| 60 | |
| 61 | if (url->GetPath().size() > 3) |
| 62 | return false; |
| 63 | |
| 64 | if (request.method() != http::verb::get) |
| 65 | return false; |
| 66 | |
| 67 | QueryDescription qd; |
| 68 | qd.Types.insert("Type"); |
| 69 | qd.Permission = "types"; |
| 70 | qd.Provider = new TypeTargetProvider(); |
| 71 | |
| 72 | if (params->Contains("type")) |
| 73 | params->Set("name", params->Get("type")); |
| 74 | |
| 75 | params->Set("type", "Type"); |
| 76 | |
| 77 | if (url->GetPath().size() >= 3) |
| 78 | params->Set("name", url->GetPath()[2]); |
| 79 | |
| 80 | std::vector<Value> objs; |
| 81 | |
| 82 | try { |
| 83 | objs = FilterUtility::GetFilterTargets(qd, params, user); |
| 84 | } catch (const MissingPermissionError& ex) { |
| 85 | HttpUtility::SendJsonError(response, params, 403, ex.what()); |
| 86 | return true; |
| 87 | } catch (const std::exception& ex) { |
| 88 | HttpUtility::SendJsonError(response, params, 404, |
| 89 | "No objects found.", |
| 90 | DiagnosticInformation(ex)); |
| 91 | return true; |
| 92 | } |
| 93 | |
| 94 | auto generatorFunc = [](const Type::Ptr& obj) -> Value { |
| 95 | Dictionary::Ptr result = new Dictionary(); |
| 96 | Dictionary::Ptr resultAttrs = new Dictionary(); |
| 97 | result->Set("name", obj->GetName()); |
| 98 | result->Set("plural_name", obj->GetPluralName()); |
| 99 | if (obj->GetBaseType()) |
| 100 | result->Set("base", obj->GetBaseType()->GetName()); |
| 101 | result->Set("abstract", obj->IsAbstract()); |
| 102 | result->Set("fields", resultAttrs); |
| 103 | |
| 104 | Dictionary::Ptr prototype = dynamic_pointer_cast<Dictionary>(obj->GetPrototype()); |
| 105 | Array::Ptr prototypeKeys = new Array(); |
nothing calls this directly
no test coverage detected