first commit
This commit is contained in:
28
test/qxBlogRestApi/qt/rcc/documents/cert_qxorm_ca.pem
Normal file
28
test/qxBlogRestApi/qt/rcc/documents/cert_qxorm_ca.pem
Normal file
@@ -0,0 +1,28 @@
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIEyjCCA7KgAwIBAgIJAOwBaVFFv3nHMA0GCSqGSIb3DQEBCwUAMIGeMQswCQYD
|
||||
VQQGEwJGUjEUMBIGA1UECBMLTW9udHBlbGxpZXIxFDASBgNVBAcTC0JhaWxsYXJn
|
||||
dWVzMQ4wDAYDVQQKEwVReE9ybTEhMB8GA1UECxMYUXhPcm0gYW5kIFF4RW50aXR5
|
||||
RWRpdG9yMQ4wDAYDVQQDEwVReE9ybTEgMB4GCSqGSIb3DQEJARYRY29udGFjdEBx
|
||||
eG9ybS5jb20wHhcNMTkwMzA5MTMxNTU2WhcNMjQwMzA3MTMxNTU2WjCBnjELMAkG
|
||||
A1UEBhMCRlIxFDASBgNVBAgTC01vbnRwZWxsaWVyMRQwEgYDVQQHEwtCYWlsbGFy
|
||||
Z3VlczEOMAwGA1UEChMFUXhPcm0xITAfBgNVBAsTGFF4T3JtIGFuZCBReEVudGl0
|
||||
eUVkaXRvcjEOMAwGA1UEAxMFUXhPcm0xIDAeBgkqhkiG9w0BCQEWEWNvbnRhY3RA
|
||||
cXhvcm0uY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4AJ2A+3Q
|
||||
3CrVM7ptfaXczoHPP4Nvedr+bYRqGzvgrK83nmdtIVDZBAUFLBaVqs4ry3RPsFat
|
||||
YbKcsMynKuefMngUHTpOW2EXvlouiPzFDYM6+VlggiWRUpC9Ofd7h/Gph0ShTpqH
|
||||
4Be20m4+tsai6dk0UO91AGnHyg4QMeGW1EbY+YSv6eX84uKcfNikZNYGGiVc27ru
|
||||
UnQz92e+upnhaFN30NW7eTsnAxDBOr9q0PHEpJbkNk+o4gMPjDt1NOddRk7Cp3f6
|
||||
Uz/+eUO+AzWpZRfSPfQy4+YY7gP3r9rZmLf2AGoRw7aYiTWvObLjPB/SA1Dwaoc2
|
||||
O2xpKJD6MuAYswIDAQABo4IBBzCCAQMwHQYDVR0OBBYEFDCJhMbpmZK21Te5Bgei
|
||||
56xDxXADMIHTBgNVHSMEgcswgciAFDCJhMbpmZK21Te5Bgei56xDxXADoYGkpIGh
|
||||
MIGeMQswCQYDVQQGEwJGUjEUMBIGA1UECBMLTW9udHBlbGxpZXIxFDASBgNVBAcT
|
||||
C0JhaWxsYXJndWVzMQ4wDAYDVQQKEwVReE9ybTEhMB8GA1UECxMYUXhPcm0gYW5k
|
||||
IFF4RW50aXR5RWRpdG9yMQ4wDAYDVQQDEwVReE9ybTEgMB4GCSqGSIb3DQEJARYR
|
||||
Y29udGFjdEBxeG9ybS5jb22CCQDsAWlRRb95xzAMBgNVHRMEBTADAQH/MA0GCSqG
|
||||
SIb3DQEBCwUAA4IBAQBvJCXV+eJ2oSRblCNjB2kGjt99Zx+sKLXXuzMs1a+3Dn34
|
||||
n5h4UIXM7T7VtcU0b5M/ifaaftp7JZZvI1RF5ohFUC2iM826EPbCKiVgUJupWnTr
|
||||
w5cY+Ac3coN4QFHbDvBAY0duuxUar2UmzhDZa6oOPs5ND+nw0YA5GBpjsG0uzsFA
|
||||
ixyPQb24K280mwjxyOvo+/z1Ou6DvGIxriGuwZiJKLInnb6KrV6YRci7aWR0weMn
|
||||
kZVBavtLevzk8h/zPZCaYb9wYhX2sJ5chfQVQHrr3betC0VeOxziKZem7c+oNVB4
|
||||
xTdaOZirtHk7BqJAhEJRXSX6DTXkiFVWohL6LNCf
|
||||
-----END CERTIFICATE-----
|
||||
24
test/qxBlogRestApi/qt/rcc/documents/cert_qxorm_server.crt
Normal file
24
test/qxBlogRestApi/qt/rcc/documents/cert_qxorm_server.crt
Normal file
@@ -0,0 +1,24 @@
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIEEjCCAvqgAwIBAgIJALC9lov7amDkMA0GCSqGSIb3DQEBCwUAMIGeMQswCQYD
|
||||
VQQGEwJGUjEUMBIGA1UECBMLTW9udHBlbGxpZXIxFDASBgNVBAcTC0JhaWxsYXJn
|
||||
dWVzMQ4wDAYDVQQKEwVReE9ybTEhMB8GA1UECxMYUXhPcm0gYW5kIFF4RW50aXR5
|
||||
RWRpdG9yMQ4wDAYDVQQDEwVReE9ybTEgMB4GCSqGSIb3DQEJARYRY29udGFjdEBx
|
||||
eG9ybS5jb20wHhcNMTkwMzA5MTMyMTE4WhcNMjQwMzA3MTMyMTE4WjCBnjELMAkG
|
||||
A1UEBhMCRlIxFDASBgNVBAgTC01vbnRwZWxsaWVyMRQwEgYDVQQHEwtCYWlsbGFy
|
||||
Z3VlczEOMAwGA1UEChMFUXhPcm0xITAfBgNVBAsTGFF4T3JtIGFuZCBReEVudGl0
|
||||
eUVkaXRvcjEOMAwGA1UEAxMFUXhPcm0xIDAeBgkqhkiG9w0BCQEWEWNvbnRhY3RA
|
||||
cXhvcm0uY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA5gXL5XXa
|
||||
aFW0LYspMhGpZpFzhGGMbwbm/+lpV1VZH7qoPBaMaxioO62vJFGthersbcWoIq6g
|
||||
XuiclP63i0iPe0J5lzXic973posoNw0yCPQiIFpwSd2fNW7tq9mDahzDiAUbI9U3
|
||||
R7wgdirAzsQmumJ4j2Dnfdal4modEjnQKtH7AF5U9fNAdBayvG4p4iPg2AXzUkhR
|
||||
iyfIpIMct/5d6vjPQEewO1HYocMYp2K4P65XOtJ9AHE+0543ualvoUGmtG+x+CWg
|
||||
/g8uidGHhgWL1AfsHFrXZaP5B1Y3xhcN3tJNDg6emHs5SEcbhp2W2CkdpDn/nqX3
|
||||
NbQJobkeM7d4RQIDAQABo1EwTzAfBgNVHSMEGDAWgBQwiYTG6ZmSttU3uQYHoues
|
||||
Q8VwAzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIE8DAUBgNVHREEDTALgglxeG9ybS5j
|
||||
b20wDQYJKoZIhvcNAQELBQADggEBAFY5aWMu2g7D63IigrtXPiFGsnkOSZn5p95z
|
||||
Q2xacbGdq//NeWrkuzUkaYH6z9rdtVWe93kmU/pT6neT6ttVAjmfvzzgm6IRF4PT
|
||||
xnKKGfyV+woorSuQlSxYogHtgOCHw7FSSgykqYVLQkPeAEWzwOrTpBAWsWYqKFLO
|
||||
oBAo7XYdfxXg0zM5kuvDk3vKHH0Rc25o5QpD4BCEqxaSN/p3dSPGtM3AwSqDLyEI
|
||||
vDQNiTR5slqxTAv1nKd1CuZSAES+ceHmt6q04ESnwRz7pCMOF6N5iAvRHkbIR2DY
|
||||
vsmWZwhTmCbHWUhS0b8GMoL+MPIbB3n2jq4rbeRo0vPx+ZUHkk0=
|
||||
-----END CERTIFICATE-----
|
||||
27
test/qxBlogRestApi/qt/rcc/documents/cert_qxorm_server.key
Normal file
27
test/qxBlogRestApi/qt/rcc/documents/cert_qxorm_server.key
Normal file
@@ -0,0 +1,27 @@
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
MIIEogIBAAKCAQEA5gXL5XXaaFW0LYspMhGpZpFzhGGMbwbm/+lpV1VZH7qoPBaM
|
||||
axioO62vJFGthersbcWoIq6gXuiclP63i0iPe0J5lzXic973posoNw0yCPQiIFpw
|
||||
Sd2fNW7tq9mDahzDiAUbI9U3R7wgdirAzsQmumJ4j2Dnfdal4modEjnQKtH7AF5U
|
||||
9fNAdBayvG4p4iPg2AXzUkhRiyfIpIMct/5d6vjPQEewO1HYocMYp2K4P65XOtJ9
|
||||
AHE+0543ualvoUGmtG+x+CWg/g8uidGHhgWL1AfsHFrXZaP5B1Y3xhcN3tJNDg6e
|
||||
mHs5SEcbhp2W2CkdpDn/nqX3NbQJobkeM7d4RQIDAQABAoIBABmoH9wSTzBADv7d
|
||||
fNTW33xPUQE9GDryHCYDVPqmzHAbk9RP942ijHFLqDN24NIFKCX+XAiyTbUIYR7F
|
||||
Ypeomkh3W7SgEAg4oIr1DqFFWYViJcRSEiBLFg0RuHToqB3X439yglp219mqhDxp
|
||||
/GOTwXYcsbHcbzW8EXi1uVRlGnEMELLf5FeJS0ZfavogcC+zUqrvIemMs9ltkktM
|
||||
I6ABje3WxsJgOafb1uleUr9y04Fgf9CWt76FdPJucl2dBjj+kzxs9JnQw5cYC0v4
|
||||
ISK/lbnddbLaqeZ52ebEH70LAc+4uSAYEEfoodEt1STIxCAGOH7gepcJLt0PQkO5
|
||||
x4TJJqkCgYEA/PLhwy9v1AR/zAZ/JSJe5ahgMbQZy7Yt4fYWq3+yKTWO8DcTO2oL
|
||||
ik2J05xZO3J2723ZeD3VEI7U/U9e7cxrW8CyxM3N2khj6kWglrSFQXWK7AaMpcDQ
|
||||
pE8+G8Vb/1mwJSIh+CdiVlx0HaKLF0tyGTcEQlM/Fi+YQdYJUTjNKVsCgYEA6Mwe
|
||||
HIv4yLENtq2wdgAnhBt7j91oQfUlMjmmZ2i5is9xseOg4PU5LmsDi01hfuVPdTXg
|
||||
JHIFVLmiv2vIhEg8nVr4xou437giHNUyO5dpcMVWSG00N6ChuomEGFHh1FxH4N8Q
|
||||
tUqc2nPtGxOQMKfg9CN+HEmEykCEucDCP3o59t8CgYBfYxAz1M2s/E1dGQ4VaNK0
|
||||
dDxiQfKAWaEP1wdRgQQkeif++iXsf97+NqNFA2669j1XqOsbZuXUKqizJZ08u5u4
|
||||
rAA+KwX3zNiw3bTjYAvoVXUf8JBVaVLEw4U+X7yDnMTKHAcHV4LD4nV/P26ISFEs
|
||||
pQycHlxp92TJXveAg5UKhQKBgFmsjwjWDj5YnXy6CVhbFN25rG4tjoShxvNC68u3
|
||||
tok3AYfRtF4TeDReOp5Fb4HvGR2AZFgFp/IMFBoCjdoO7XJ74YqxtcRP7KwIn/H+
|
||||
kDpFecgqcMvgz4vIfx7TI9emuHVx18DN/f/UWghtD8T+VhQVO/Xvh/xUwAvBqdHD
|
||||
5mInAoGARe2+SN/zZiAdjCULMpAcrwKkqbniKemeg90yFsfusWe0Sm60W4y+7x+U
|
||||
BFFV9cqRd/vcNo/s5K+JMgLlGngEDgeAokvXwdkQeX4Loy9eHaFriraxZEAhDNCE
|
||||
CGN/Ek40PNfnk5KmD5UXg2+NAYRpsILkLJytBHajiGAoSxScTsM=
|
||||
-----END RSA PRIVATE KEY-----
|
||||
2
test/qxBlogRestApi/qt/rcc/documents/jquery.js
vendored
Normal file
2
test/qxBlogRestApi/qt/rcc/documents/jquery.js
vendored
Normal file
File diff suppressed because one or more lines are too long
BIN
test/qxBlogRestApi/qt/rcc/documents/logo_qxorm_and_qxee.png
Normal file
BIN
test/qxBlogRestApi/qt/rcc/documents/logo_qxorm_and_qxee.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 52 KiB |
446
test/qxBlogRestApi/qt/rcc/documents/test_http_server.html
Normal file
446
test/qxBlogRestApi/qt/rcc/documents/test_http_server.html
Normal file
@@ -0,0 +1,446 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
||||
<title>QxOrm HTTP Server - qxBlogRestApi project</title>
|
||||
<script type="text/javascript" src="jquery.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Welcome to QxOrm HTTP Server - qxBlogRestApi example project</h1>
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td align="center" style="padding-right: 15px; background-color: #e6f9ff;">
|
||||
<label><b><font color="blue">JSON request</font></b></label>
|
||||
</td>
|
||||
<td align="center" style="padding-right: 15px; background-color: #e6f9ff;">
|
||||
<label style="background-color: #e6f9ff;"><b><font color="blue">JSON response</font></b></label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="top" style="padding-right: 15px">
|
||||
<textarea id="txtRequest" rows="10" cols="80" wrap="off" style="width: 100%; background-color: #f9f9fb;"></textarea>
|
||||
</td>
|
||||
<td rowspan="3" valign="top">
|
||||
<textarea id="txtResponse" rows="35" cols="80" wrap="off" style="width: 100%; background-color: #f9f9fb;"></textarea>
|
||||
<br/><br/><a href="https://www.qxorm.com/" target="_blank"><img src="logo_qxorm_and_qxee.png" alt="QxOrm, QxEntityEditor"></a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding-right: 15px">
|
||||
<input id="btnSendRequest" type="button" value="Send JSON request" style="width: 100%; height: 40px; color: blue; font-weight: bold; font-size: 16px;">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding-right: 15px">
|
||||
<br/><label><i><font color="blue">Here are some request examples :</font></i></label><br/>
|
||||
<select id="lstRequestExample" size="25" style="width: 100%;">
|
||||
<option id="get_meta_data"> - get project meta-data (all classes)</option>
|
||||
<option id="fetch_all_blogs"> - fetch all blogs (as list)</option>
|
||||
<option id="fetch_all_blogs_as_collection"> - fetch all blogs (as collection key/value)</option>
|
||||
<option id="fetch_all_blogs_with_relationships"> - fetch all blogs with relationships (several levels)</option>
|
||||
<option id="fetch_all_blogs_with_relationships_output_format"> - fetch all blogs with relationships (several levels) and define output format</option>
|
||||
<option id="fetch_blog_by_id"> - fetch a single blog by id</option>
|
||||
<option id="fetch_blog_by_id_columns"> - fetch some columns of a single blog by id</option>
|
||||
<option id="fetch_list_of_blog_by_id"> - fetch list of blogs by id</option>
|
||||
<option id="fetch_list_of_blog_by_id_output_format"> - fetch list of blogs by id and define output format</option>
|
||||
<option id="fetch_authors_by_query"> - fetch authors using a query (only female)</option>
|
||||
<option id="fetch_authors_by_query_with_relationships"> - fetch authors with relationships using a query</option>
|
||||
<option id="fetch_authors_by_query_with_relationships_output_format"> - fetch authors with relationships using a query and define output format</option>
|
||||
<option id="insert_blog"> - insert a blog</option>
|
||||
<option id="insert_list_of_blog"> - insert list of blogs</option>
|
||||
<option id="insert_author"> - insert an author</option>
|
||||
<option id="insert_category"> - insert a category</option>
|
||||
<option id="update_blog"> - update a blog</option>
|
||||
<option id="update_blog_columns"> - update some columns of blog</option>
|
||||
<option id="update_author"> - update an author</option>
|
||||
<option id="update_list_of_author"> - update list of authors</option>
|
||||
<option id="update_category"> - update a category</option>
|
||||
<option id="save_blog"> - save (insert or update) a blog</option>
|
||||
<option id="save_list_of_blog"> - save (insert or update) list of blogs</option>
|
||||
<option id="save_blog_recursive"> - save (insert or update) a blog with relationships (recursively)</option>
|
||||
<option id="save_blog_recursive_insert"> - save (insert optimized) a blog with relationships (recursively)</option>
|
||||
<option id="exist_blog"> - check if a blog id exist</option>
|
||||
<option id="exist_list_of_blog"> - check if list of blogs id exist</option>
|
||||
<option id="exist_author"> - check if an author id exist</option>
|
||||
<option id="validate_blog"> - validate a blog instance</option>
|
||||
<option id="count_all_blog"> - count all blogs</option>
|
||||
<option id="count_author_with_query"> - count authors using a query</option>
|
||||
<option id="count_blog_with_query_and_relationships"> - count blogs using a query and relationships</option>
|
||||
<option id="delete_blog_by_id"> - delete a blog by id</option>
|
||||
<option id="delete_list_of_blog_by_id"> - delete list of blogs by id</option>
|
||||
<option id="delete_author_by_query"> - delete some authors using a query</option>
|
||||
<option id="delete_all_comment"> - delete all comments</option>
|
||||
<option id="call_custom_query"> - call custom database query or stored procedure</option>
|
||||
<option id="call_entity_function"> - call entity static function with signature : static QJsonValue myEntity::myFct(const QJsonValue & request)</option>
|
||||
<option id="several_requests_in_array"> - build several requests in array to send only 1 call to server (executed in a transaction commit/rollback)</option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$("#lstRequestExample").change(function() {
|
||||
var id = $(this).children(":selected").attr("id");
|
||||
var request = buildRequestExample(id);
|
||||
$("#txtRequest").val(JSON.stringify(request, null, 3));
|
||||
$("#txtResponse").val("");
|
||||
});
|
||||
|
||||
$("#btnSendRequest").click(function() {
|
||||
sendRequest($("#txtRequest").val());
|
||||
});
|
||||
|
||||
$('select option:even').css({'background-color': '#e6ffe6'});
|
||||
$('#lstRequestExample option[id="get_meta_data"]').prop("selected", true);
|
||||
var request = buildRequestExample("get_meta_data");
|
||||
$("#txtRequest").val(JSON.stringify(request, null, 3));
|
||||
$("#txtResponse").val("");
|
||||
});
|
||||
|
||||
function sendRequest(request) {
|
||||
$.post("/qx", request, function(data, status, xhr) {
|
||||
$("#txtResponse").val(JSON.stringify(data, null, 3));
|
||||
}, "json").fail(function(error) {
|
||||
alert("An error occurred sending request to QxOrm HTTP server : " + error);
|
||||
});
|
||||
}
|
||||
|
||||
function buildRequestExample(id) {
|
||||
var request = { };
|
||||
request.request_id = createGUID();
|
||||
if (id == "get_meta_data") {
|
||||
request.action = "get_meta_data";
|
||||
request.entity = "*";
|
||||
}
|
||||
else if (id == "fetch_all_blogs") {
|
||||
request.action = "fetch_all";
|
||||
request.entity = "blog";
|
||||
}
|
||||
else if (id == "fetch_all_blogs_as_collection") {
|
||||
request.action = "fetch_all";
|
||||
request.entity = "blog";
|
||||
request.data = [ { key: "", value: "" } ]
|
||||
}
|
||||
else if (id == "fetch_all_blogs_with_relationships") {
|
||||
request.action = "fetch_all";
|
||||
request.entity = "blog";
|
||||
request.relations = [ "*->*" ];
|
||||
}
|
||||
else if (id == "fetch_all_blogs_with_relationships_output_format") {
|
||||
request.action = "fetch_all";
|
||||
request.entity = "blog";
|
||||
request.relations = [ "<blog_alias> { blog_text }", "author_id <author_alias> { name, birthdate }", "list_comment <list_comment_alias> { comment_text } -> blog_id <blog_alias_2> -> * <..._my_alias_suffix>" ];
|
||||
request.output_format = [ "{ blog_text }", "author_id { name, birthdate }", "list_comment { comment_text } -> blog_id -> *" ];
|
||||
}
|
||||
else if (id == "fetch_blog_by_id") {
|
||||
request.action = "fetch_by_id";
|
||||
request.entity = "blog";
|
||||
request.data = { blog_id: 1 };
|
||||
}
|
||||
else if (id == "fetch_blog_by_id_columns") {
|
||||
request.action = "fetch_by_id";
|
||||
request.entity = "blog";
|
||||
request.data = { blog_id: 1 };
|
||||
request.columns = [ "blog_text", "date_creation" ];
|
||||
}
|
||||
else if (id == "fetch_list_of_blog_by_id") {
|
||||
request.action = "fetch_by_id";
|
||||
request.entity = "blog";
|
||||
request.data = [ { blog_id: 1 }, { blog_id: 2 }, { blog_id: 3 } ];
|
||||
}
|
||||
else if (id == "fetch_list_of_blog_by_id_output_format") {
|
||||
request.action = "fetch_by_id";
|
||||
request.entity = "blog";
|
||||
request.data = [ { blog_id: 1 }, { blog_id: 2 } ];
|
||||
request.relations = [ "{ blog_text }", "author_id <author_alias> { name, birthdate }", "list_comment <list_comment_alias> { comment_text }" ];
|
||||
request.output_format = [ "{ blog_text }", "author_id { name, birthdate }", "list_comment { comment_text }" ];
|
||||
}
|
||||
else if (id == "fetch_authors_by_query") {
|
||||
request.action = "fetch_by_query";
|
||||
request.entity = "author";
|
||||
request.query = {
|
||||
sql: "WHERE author.sex = :sex",
|
||||
params: [ { key: ":sex", value: 1, type: "in" } ]
|
||||
};
|
||||
}
|
||||
else if (id == "fetch_authors_by_query_with_relationships") {
|
||||
request.action = "fetch_by_query";
|
||||
request.entity = "author";
|
||||
request.query = {
|
||||
sql: "WHERE author.sex = :sex",
|
||||
params: [ { key: ":sex", value: 1, type: "in" } ]
|
||||
};
|
||||
request.relations = [ "*" ];
|
||||
}
|
||||
else if (id == "fetch_authors_by_query_with_relationships_output_format") {
|
||||
request.action = "fetch_by_query";
|
||||
request.entity = "author";
|
||||
request.query = {
|
||||
sql: "WHERE author.sex = :sex",
|
||||
params: [ { key: ":sex", value: 1, type: "in" } ]
|
||||
};
|
||||
request.relations = [ "*" ];
|
||||
request.output_format = [ "{ birthdate, name }", "list_blog { blog_text, date_creation }" ];
|
||||
}
|
||||
else if (id == "insert_blog") {
|
||||
request.action = "insert";
|
||||
request.entity = "blog";
|
||||
request.data = {
|
||||
blog_text: "this is a new blog from QxOrm REST API !",
|
||||
date_creation: "2018-01-30T12:42:01",
|
||||
author_id: "author_id_2"
|
||||
};
|
||||
}
|
||||
else if (id == "insert_list_of_blog") {
|
||||
request.action = "insert";
|
||||
request.entity = "blog";
|
||||
request.data = [
|
||||
{
|
||||
blog_text: "new blog from QxOrm REST API !",
|
||||
date_creation: "2018-01-30T12:42:01",
|
||||
author_id: "author_id_2"
|
||||
},
|
||||
{
|
||||
blog_text: "another blog from QxOrm REST API !",
|
||||
date_creation: "2016-06-12T08:33:12",
|
||||
author_id: "author_id_1"
|
||||
}
|
||||
];
|
||||
}
|
||||
else if (id == "insert_author") {
|
||||
request.action = "insert";
|
||||
request.entity = "author";
|
||||
request.data = {
|
||||
author_id: "author_id_from_rest_api",
|
||||
birthdate: "1978-05-11",
|
||||
name: "new author created by QxOrm REST API",
|
||||
sex: 1
|
||||
};
|
||||
}
|
||||
else if (id == "insert_category") {
|
||||
request.action = "insert";
|
||||
request.entity = "category";
|
||||
request.data = {
|
||||
description: "category from REST API",
|
||||
name: "new_category"
|
||||
};
|
||||
}
|
||||
else if (id == "update_blog") {
|
||||
request.action = "update";
|
||||
request.entity = "blog";
|
||||
request.data = {
|
||||
blog_id: 1,
|
||||
blog_text: "modify blog from QxOrm REST API",
|
||||
date_creation: "2013-11-25T09:56:33",
|
||||
author_id: "author_id_1"
|
||||
};
|
||||
}
|
||||
else if (id == "update_blog_columns") {
|
||||
request.action = "update";
|
||||
request.entity = "blog";
|
||||
request.data = {
|
||||
blog_id: 2,
|
||||
blog_text: "modify blog from QxOrm REST API",
|
||||
date_creation: "2013-11-25T09:56:33"
|
||||
};
|
||||
request.columns = [ "blog_text", "date_creation" ];
|
||||
}
|
||||
else if (id == "update_author") {
|
||||
request.action = "update";
|
||||
request.entity = "author";
|
||||
request.data = {
|
||||
author_id: "author_id_from_rest_api",
|
||||
birthdate: "1992-11-03",
|
||||
name: "modify author from QxOrm REST API",
|
||||
sex: 0
|
||||
};
|
||||
}
|
||||
else if (id == "update_list_of_author") {
|
||||
request.action = "update";
|
||||
request.entity = "author";
|
||||
request.data = [
|
||||
{
|
||||
author_id: "author_id_from_rest_api",
|
||||
birthdate: "1992-11-03",
|
||||
name: "modify author from QxOrm REST API",
|
||||
sex: 0
|
||||
},
|
||||
{
|
||||
author_id: "author_id_1",
|
||||
birthdate: "1978-12-25",
|
||||
name: "modify another author from QxOrm REST API",
|
||||
sex: 2
|
||||
}
|
||||
];
|
||||
}
|
||||
else if (id == "update_category") {
|
||||
request.action = "update";
|
||||
request.entity = "category";
|
||||
request.data = {
|
||||
category_id: 1,
|
||||
description: "category modified by REST API",
|
||||
name: "modif_category"
|
||||
};
|
||||
}
|
||||
else if (id == "save_blog") {
|
||||
request.action = "save";
|
||||
request.entity = "blog";
|
||||
request.data = {
|
||||
blog_id: 1,
|
||||
blog_text: "modify blog from QxOrm REST API",
|
||||
date_creation: "2013-11-25T09:56:33",
|
||||
author_id: "author_id_1"
|
||||
};
|
||||
}
|
||||
else if (id == "save_list_of_blog") {
|
||||
request.action = "save";
|
||||
request.entity = "blog";
|
||||
request.data = [
|
||||
{
|
||||
blog_id: 1,
|
||||
blog_text: "save blog from QxOrm REST API !",
|
||||
date_creation: "2018-01-30T12:42:01",
|
||||
author_id: "author_id_2"
|
||||
},
|
||||
{
|
||||
blog_text: "save another blog from QxOrm REST API !",
|
||||
date_creation: "2016-06-12T08:33:12",
|
||||
author_id: "author_id_1"
|
||||
}
|
||||
];
|
||||
}
|
||||
else if (id == "save_blog_recursive") {
|
||||
request.action = "save";
|
||||
request.entity = "blog";
|
||||
request.data = {
|
||||
blog_id: 1,
|
||||
blog_text: "save recursive blog from QxOrm REST API",
|
||||
date_creation: "2013-11-25T09:56:33",
|
||||
author_id: {
|
||||
author_id: "author_id_1",
|
||||
birthdate: "1965-07-21",
|
||||
name: "save recursive author from QxOrm REST API",
|
||||
sex: 0
|
||||
}
|
||||
};
|
||||
request.save_mode = "check_insert_or_update";
|
||||
}
|
||||
else if (id == "save_blog_recursive_insert") {
|
||||
request.action = "save";
|
||||
request.entity = "blog";
|
||||
request.data = {
|
||||
blog_text: "save recursive - new blog from QxOrm REST API",
|
||||
date_creation: "2013-11-25T09:56:33",
|
||||
author_id: {
|
||||
author_id: "author_id_save_recursive",
|
||||
birthdate: "1965-07-21",
|
||||
name: "save recursive (insert only) author from QxOrm REST API",
|
||||
sex: 0
|
||||
}
|
||||
};
|
||||
request.save_mode = "insert_only";
|
||||
}
|
||||
else if (id == "exist_blog") {
|
||||
request.action = "exist";
|
||||
request.entity = "blog";
|
||||
request.data = { blog_id: 1 };
|
||||
}
|
||||
else if (id == "exist_list_of_blog") {
|
||||
request.action = "exist";
|
||||
request.entity = "blog";
|
||||
request.data = [ { blog_id: 1 }, { blog_id: 999 }, { blog_id: 3 } ];
|
||||
}
|
||||
else if (id == "exist_author") {
|
||||
request.action = "exist";
|
||||
request.entity = "author";
|
||||
request.data = { author_id: "author_id_2" };
|
||||
}
|
||||
else if (id == "validate_blog") {
|
||||
request.action = "validate";
|
||||
request.entity = "blog";
|
||||
request.data = { blog_id: 9999, blog_text: "" };
|
||||
}
|
||||
else if (id == "count_all_blog") {
|
||||
request.action = "count";
|
||||
request.entity = "blog";
|
||||
}
|
||||
else if (id == "count_author_with_query") {
|
||||
request.action = "count";
|
||||
request.entity = "author";
|
||||
request.query = {
|
||||
sql: "WHERE author.sex = :sex",
|
||||
params: [ { key: ":sex", value: 1 } ]
|
||||
};
|
||||
}
|
||||
else if (id == "count_blog_with_query_and_relationships") {
|
||||
request.action = "count";
|
||||
request.entity = "blog";
|
||||
request.query = {
|
||||
sql: "WHERE author_alias.sex = :sex",
|
||||
params: [ { key: ":sex", value: 1 } ]
|
||||
};
|
||||
request.relations = [ "author_id <author_alias> { sex }" ];
|
||||
}
|
||||
else if (id == "delete_blog_by_id") {
|
||||
request.action = "delete_by_id";
|
||||
request.entity = "blog";
|
||||
request.data = { blog_id: 4 };
|
||||
}
|
||||
else if (id == "delete_list_of_blog_by_id") {
|
||||
request.action = "delete_by_id";
|
||||
request.entity = "blog";
|
||||
request.data = [ { blog_id: 3 }, { blog_id: 2 } ];
|
||||
}
|
||||
else if (id == "delete_author_by_query") {
|
||||
request.action = "delete_by_query";
|
||||
request.entity = "author";
|
||||
request.query = {
|
||||
sql: "WHERE author.sex = :sex",
|
||||
params: [ { key: ":sex", value: 1 } ]
|
||||
};
|
||||
}
|
||||
else if (id == "delete_all_comment") {
|
||||
request.action = "delete_all";
|
||||
request.entity = "comment";
|
||||
}
|
||||
else if (id == "call_custom_query") {
|
||||
request.action = "call_custom_query";
|
||||
request.query = {
|
||||
sql: "INSERT INTO author (author_id, name, birthdate, sex) VALUES (:author_id, :name, :birthdate, :sex)",
|
||||
params: [
|
||||
{ key: ":author_id", value: "author_id_custom_query" },
|
||||
{ key: ":name", value: "new author inserted by custom query" },
|
||||
{ key: ":birthdate", value: "20190215" },
|
||||
{ key: ":sex", value: 2 }
|
||||
]
|
||||
};
|
||||
}
|
||||
else if (id == "call_entity_function") {
|
||||
request.action = "call_entity_function";
|
||||
request.entity = "blog";
|
||||
request.fct = "helloWorld";
|
||||
request.data = { param1: "test", param2: "static fct call" };
|
||||
}
|
||||
else if (id == "several_requests_in_array") {
|
||||
request = [ buildRequestExample("get_meta_data"),
|
||||
buildRequestExample("fetch_all_blogs"),
|
||||
buildRequestExample("exist_blog"),
|
||||
buildRequestExample("call_entity_function") ];
|
||||
}
|
||||
else {
|
||||
request.error = "<unknown request example : " + id + ">";
|
||||
}
|
||||
return request;
|
||||
}
|
||||
|
||||
function createGUID() {
|
||||
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
||||
var r = Math.random() * 16 | 0, v = c == "x" ? r : (r & 0x3 | 0x8);
|
||||
return v.toString(16);
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
40
test/qxBlogRestApi/qt/rcc/documents/test_http_server.qml
Normal file
40
test/qxBlogRestApi/qt/rcc/documents/test_http_server.qml
Normal file
@@ -0,0 +1,40 @@
|
||||
import QtQuick 2.1
|
||||
import QtQuick.Controls 1.0
|
||||
import QtQuick.Controls.Styles 1.0
|
||||
|
||||
Item {
|
||||
width: 500
|
||||
height: 130
|
||||
Column {
|
||||
anchors.fill: parent
|
||||
spacing: 10
|
||||
anchors.leftMargin: 5
|
||||
anchors.rightMargin: 5
|
||||
Label {
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
text: " "
|
||||
}
|
||||
Label {
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
text: "!!! Test QxOrm QxRestApi module from a web page using QxHttpServer module !!!"
|
||||
font.bold: true
|
||||
color: "blue"
|
||||
}
|
||||
Label {
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
text: "Please open your web browser to this URL : http://localhost:9642/files/test_http_server.html"
|
||||
}
|
||||
Label {
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
text: "Note : closing this QML window means stopping QxOrm HTTP server too."
|
||||
}
|
||||
}
|
||||
}
|
||||
39
test/qxBlogRestApi/qt/rcc/documents/test_http_server_qt6.qml
Normal file
39
test/qxBlogRestApi/qt/rcc/documents/test_http_server_qt6.qml
Normal file
@@ -0,0 +1,39 @@
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
|
||||
Item {
|
||||
width: 500
|
||||
height: 130
|
||||
Column {
|
||||
anchors.fill: parent
|
||||
spacing: 10
|
||||
anchors.leftMargin: 5
|
||||
anchors.rightMargin: 5
|
||||
Label {
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
text: " "
|
||||
}
|
||||
Label {
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
text: "!!! Test QxOrm QxRestApi module from a web page using QxHttpServer module !!!"
|
||||
font.bold: true
|
||||
color: "blue"
|
||||
}
|
||||
Label {
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
text: "Please open your web browser to this URL : http://localhost:9642/files/test_http_server.html"
|
||||
}
|
||||
Label {
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
text: "Note : closing this QML window means stopping QxOrm HTTP server too."
|
||||
}
|
||||
}
|
||||
}
|
||||
503
test/qxBlogRestApi/qt/rcc/documents/test_rest_api.qml
Normal file
503
test/qxBlogRestApi/qt/rcc/documents/test_rest_api.qml
Normal file
@@ -0,0 +1,503 @@
|
||||
import QtQuick 2.1
|
||||
import QtQuick.Controls 1.0
|
||||
import QtQuick.Controls.Styles 1.0
|
||||
|
||||
Item {
|
||||
width: 1000
|
||||
height: 700
|
||||
Row {
|
||||
anchors.fill: parent
|
||||
spacing: 10
|
||||
anchors.leftMargin: 5
|
||||
anchors.rightMargin: 5
|
||||
Column {
|
||||
width: ((parent.width - 10) * 0.5)
|
||||
height: (parent.height)
|
||||
spacing: 10
|
||||
Label {
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
text: "JSON Request"
|
||||
font.bold: true
|
||||
color: "blue"
|
||||
}
|
||||
TextArea {
|
||||
id: txtRequest
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
height: (parent.height * 0.4)
|
||||
wrapMode: TextEdit.NoWrap
|
||||
text: ""
|
||||
}
|
||||
Button {
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
text: "Send JSON request"
|
||||
height: 45
|
||||
onClicked: onSendRequest()
|
||||
style: ButtonStyle {
|
||||
label: Text {
|
||||
renderType: Text.NativeRendering
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
text: control.text
|
||||
font.pointSize: 12
|
||||
font.bold: true
|
||||
color: "blue"
|
||||
}
|
||||
}
|
||||
}
|
||||
Label {
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
text: "Here are some request examples :"
|
||||
font.italic: true
|
||||
color: "blue"
|
||||
}
|
||||
ScrollView {
|
||||
width: parent.width
|
||||
height: (parent.height * 0.4)
|
||||
ListView {
|
||||
id: lstRequestExample
|
||||
anchors.fill: parent
|
||||
flickableDirection: Flickable.VerticalFlick
|
||||
boundsBehavior: Flickable.StopAtBounds
|
||||
model: ListModel {
|
||||
id: modelRequestExample
|
||||
ListElement { key: "get_meta_data"; txt: " - get project meta-data (all classes)" }
|
||||
ListElement { key: "fetch_all_blogs"; txt: " - fetch all blogs (as list)" }
|
||||
ListElement { key: "fetch_all_blogs_as_collection"; txt: " - fetch all blogs (as collection key/value)" }
|
||||
ListElement { key: "fetch_all_blogs_with_relationships"; txt: " - fetch all blogs with relationships (several levels)" }
|
||||
ListElement { key: "fetch_all_blogs_with_relationships_output_format"; txt: " - fetch all blogs with relationships (several levels) and define output format" }
|
||||
ListElement { key: "fetch_blog_by_id"; txt: " - fetch a single blog by id" }
|
||||
ListElement { key: "fetch_blog_by_id_columns"; txt: " - fetch some columns of a single blog by id" }
|
||||
ListElement { key: "fetch_list_of_blog_by_id"; txt: " - fetch list of blogs by id" }
|
||||
ListElement { key: "fetch_list_of_blog_by_id_output_format"; txt: " - fetch list of blogs by id and define output format" }
|
||||
ListElement { key: "fetch_authors_by_query"; txt: " - fetch authors using a query (only female)" }
|
||||
ListElement { key: "fetch_authors_by_query_with_relationships"; txt: " - fetch authors with relationships using a query" }
|
||||
ListElement { key: "fetch_authors_by_query_with_relationships_output_format"; txt: " - fetch authors with relationships using a query and define output format" }
|
||||
ListElement { key: "insert_blog"; txt: " - insert a blog" }
|
||||
ListElement { key: "insert_list_of_blog"; txt: " - insert list of blogs" }
|
||||
ListElement { key: "insert_author"; txt: " - insert an author" }
|
||||
ListElement { key: "insert_category"; txt: " - insert a category" }
|
||||
ListElement { key: "update_blog"; txt: " - update a blog" }
|
||||
ListElement { key: "update_blog_columns"; txt: " - update some columns of blog" }
|
||||
ListElement { key: "update_author"; txt: " - update an author" }
|
||||
ListElement { key: "update_list_of_author"; txt: " - update list of authors" }
|
||||
ListElement { key: "update_category"; txt: " - update a category" }
|
||||
ListElement { key: "save_blog"; txt: " - save (insert or update) a blog" }
|
||||
ListElement { key: "save_list_of_blog"; txt: " - save (insert or update) list of blogs" }
|
||||
ListElement { key: "save_blog_recursive"; txt: " - save (insert or update) a blog with relationships (recursively)" }
|
||||
ListElement { key: "save_blog_recursive_insert"; txt: " - save (insert optimized) a blog with relationships (recursively)" }
|
||||
ListElement { key: "exist_blog"; txt: " - check if a blog id exist" }
|
||||
ListElement { key: "exist_list_of_blog"; txt: " - check if list of blogs id exist" }
|
||||
ListElement { key: "exist_author"; txt: " - check if an author id exist" }
|
||||
ListElement { key: "validate_blog"; txt: " - validate a blog instance" }
|
||||
ListElement { key: "count_all_blog"; txt: " - count all blogs" }
|
||||
ListElement { key: "count_author_with_query"; txt: " - count authors using a query" }
|
||||
ListElement { key: "count_blog_with_query_and_relationships"; txt: " - count blogs using a query and relationships" }
|
||||
ListElement { key: "delete_blog_by_id"; txt: " - delete a blog by id" }
|
||||
ListElement { key: "delete_list_of_blog_by_id"; txt: " - delete list of blogs by id" }
|
||||
ListElement { key: "delete_author_by_query"; txt: " - delete some authors using a query" }
|
||||
ListElement { key: "delete_all_comment"; txt: " - delete all comments" }
|
||||
ListElement { key: "call_custom_query"; txt: " - call custom database query or stored procedure" }
|
||||
ListElement { key: "call_entity_function"; txt: " - call entity static function with signature : static QJsonValue myEntity::myFct(const QJsonValue & request)" }
|
||||
ListElement { key: "several_requests_in_array"; txt: " - build several requests in array to send only 1 call to server (executed in a transaction commit/rollback)" }
|
||||
}
|
||||
delegate: Rectangle {
|
||||
width: parent.width
|
||||
height: 20
|
||||
color: ((index == lstRequestExample.currentIndex) ? "lightblue" : (((index % 2) == 0) ? "white" : "papayawhip"))
|
||||
Column { Text { text: txt } }
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
onClicked: lstRequestExample.currentIndex = index
|
||||
}
|
||||
}
|
||||
highlight: Rectangle { color: "lightblue" }
|
||||
onCurrentItemChanged: onRequestExampleSelected(modelRequestExample.get(lstRequestExample.currentIndex))
|
||||
Component.onCompleted : currentIndex = -1
|
||||
focus: true
|
||||
}
|
||||
}
|
||||
}
|
||||
Column {
|
||||
width: ((parent.width - 10) * 0.5)
|
||||
height: (parent.height)
|
||||
spacing: 10
|
||||
Label {
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
text: "JSON Response"
|
||||
font.bold: true
|
||||
color: "blue"
|
||||
}
|
||||
TextArea {
|
||||
id: txtResponse
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
height: (parent.height * 0.9)
|
||||
wrapMode: TextEdit.NoWrap
|
||||
text: ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function onSendRequest() {
|
||||
try {
|
||||
console.log("onSendRequest() called");
|
||||
qxRestApi.clearAll();
|
||||
var response = qxRestApi.processRequest(txtRequest.text);
|
||||
response = JSON.parse(response);
|
||||
txtResponse.text = JSON.stringify(response, null, 3);
|
||||
}
|
||||
catch(exc) {
|
||||
txtResponse.text = "An error occurred processing request : " + exc;
|
||||
}
|
||||
}
|
||||
|
||||
function onRequestExampleSelected(objRequestExample) {
|
||||
txtResponse.text = "";
|
||||
if (! objRequestExample) { return; }
|
||||
console.log("onRequestExampleSelected() : " + objRequestExample.key + " selected");
|
||||
var request = buildRequestExample(objRequestExample);
|
||||
txtRequest.text = JSON.stringify(request, null, 3);
|
||||
}
|
||||
|
||||
function buildRequestExample(objRequestExample) {
|
||||
var request = { };
|
||||
request.request_id = createGUID();
|
||||
if (objRequestExample.key == "get_meta_data") {
|
||||
request.action = "get_meta_data";
|
||||
request.entity = "*";
|
||||
}
|
||||
else if (objRequestExample.key == "fetch_all_blogs") {
|
||||
request.action = "fetch_all";
|
||||
request.entity = "blog";
|
||||
}
|
||||
else if (objRequestExample.key == "fetch_all_blogs_as_collection") {
|
||||
request.action = "fetch_all";
|
||||
request.entity = "blog";
|
||||
request.data = [ { key: "", value: "" } ]
|
||||
}
|
||||
else if (objRequestExample.key == "fetch_all_blogs_with_relationships") {
|
||||
request.action = "fetch_all";
|
||||
request.entity = "blog";
|
||||
request.relations = [ "*->*" ];
|
||||
}
|
||||
else if (objRequestExample.key == "fetch_all_blogs_with_relationships_output_format") {
|
||||
request.action = "fetch_all";
|
||||
request.entity = "blog";
|
||||
request.relations = [ "<blog_alias> { blog_text }", "author_id <author_alias> { name, birthdate }", "list_comment <list_comment_alias> { comment_text } -> blog_id <blog_alias_2> -> * <..._my_alias_suffix>" ];
|
||||
request.output_format = [ "{ blog_text }", "author_id { name, birthdate }", "list_comment { comment_text } -> blog_id -> *" ];
|
||||
}
|
||||
else if (objRequestExample.key == "fetch_blog_by_id") {
|
||||
request.action = "fetch_by_id";
|
||||
request.entity = "blog";
|
||||
request.data = { blog_id: 1 };
|
||||
}
|
||||
else if (objRequestExample.key == "fetch_blog_by_id_columns") {
|
||||
request.action = "fetch_by_id";
|
||||
request.entity = "blog";
|
||||
request.data = { blog_id: 1 };
|
||||
request.columns = [ "blog_text", "date_creation" ];
|
||||
}
|
||||
else if (objRequestExample.key == "fetch_list_of_blog_by_id") {
|
||||
request.action = "fetch_by_id";
|
||||
request.entity = "blog";
|
||||
request.data = [ { blog_id: 1 }, { blog_id: 2 }, { blog_id: 3 } ];
|
||||
}
|
||||
else if (objRequestExample.key == "fetch_list_of_blog_by_id_output_format") {
|
||||
request.action = "fetch_by_id";
|
||||
request.entity = "blog";
|
||||
request.data = [ { blog_id: 1 }, { blog_id: 2 } ];
|
||||
request.relations = [ "{ blog_text }", "author_id <author_alias> { name, birthdate }", "list_comment <list_comment_alias> { comment_text }" ];
|
||||
request.output_format = [ "{ blog_text }", "author_id { name, birthdate }", "list_comment { comment_text }" ];
|
||||
}
|
||||
else if (objRequestExample.key == "fetch_authors_by_query") {
|
||||
request.action = "fetch_by_query";
|
||||
request.entity = "author";
|
||||
request.query = {
|
||||
sql: "WHERE author.sex = :sex",
|
||||
params: [ { key: ":sex", value: 1, type: "in" } ]
|
||||
};
|
||||
}
|
||||
else if (objRequestExample.key == "fetch_authors_by_query_with_relationships") {
|
||||
request.action = "fetch_by_query";
|
||||
request.entity = "author";
|
||||
request.query = {
|
||||
sql: "WHERE author.sex = :sex",
|
||||
params: [ { key: ":sex", value: 1, type: "in" } ]
|
||||
};
|
||||
request.relations = [ "*" ];
|
||||
}
|
||||
else if (objRequestExample.key == "fetch_authors_by_query_with_relationships_output_format") {
|
||||
request.action = "fetch_by_query";
|
||||
request.entity = "author";
|
||||
request.query = {
|
||||
sql: "WHERE author.sex = :sex",
|
||||
params: [ { key: ":sex", value: 1, type: "in" } ]
|
||||
};
|
||||
request.relations = [ "*" ];
|
||||
request.output_format = [ "{ birthdate, name }", "list_blog { blog_text, date_creation }" ];
|
||||
}
|
||||
else if (objRequestExample.key == "insert_blog") {
|
||||
request.action = "insert";
|
||||
request.entity = "blog";
|
||||
request.data = {
|
||||
blog_text: "this is a new blog from QxOrm REST API !",
|
||||
date_creation: "2018-01-30T12:42:01",
|
||||
author_id: "author_id_2"
|
||||
};
|
||||
}
|
||||
else if (objRequestExample.key == "insert_list_of_blog") {
|
||||
request.action = "insert";
|
||||
request.entity = "blog";
|
||||
request.data = [
|
||||
{
|
||||
blog_text: "new blog from QxOrm REST API !",
|
||||
date_creation: "2018-01-30T12:42:01",
|
||||
author_id: "author_id_2"
|
||||
},
|
||||
{
|
||||
blog_text: "another blog from QxOrm REST API !",
|
||||
date_creation: "2016-06-12T08:33:12",
|
||||
author_id: "author_id_1"
|
||||
}
|
||||
];
|
||||
}
|
||||
else if (objRequestExample.key == "insert_author") {
|
||||
request.action = "insert";
|
||||
request.entity = "author";
|
||||
request.data = {
|
||||
author_id: "author_id_from_rest_api",
|
||||
birthdate: "1978-05-11",
|
||||
name: "new author created by QxOrm REST API",
|
||||
sex: 1
|
||||
};
|
||||
}
|
||||
else if (objRequestExample.key == "insert_category") {
|
||||
request.action = "insert";
|
||||
request.entity = "category";
|
||||
request.data = {
|
||||
description: "category from REST API",
|
||||
name: "new_category"
|
||||
};
|
||||
}
|
||||
else if (objRequestExample.key == "update_blog") {
|
||||
request.action = "update";
|
||||
request.entity = "blog";
|
||||
request.data = {
|
||||
blog_id: 1,
|
||||
blog_text: "modify blog from QxOrm REST API",
|
||||
date_creation: "2013-11-25T09:56:33",
|
||||
author_id: "author_id_1"
|
||||
};
|
||||
}
|
||||
else if (objRequestExample.key == "update_blog_columns") {
|
||||
request.action = "update";
|
||||
request.entity = "blog";
|
||||
request.data = {
|
||||
blog_id: 2,
|
||||
blog_text: "modify blog from QxOrm REST API",
|
||||
date_creation: "2013-11-25T09:56:33"
|
||||
};
|
||||
request.columns = [ "blog_text", "date_creation" ];
|
||||
}
|
||||
else if (objRequestExample.key == "update_author") {
|
||||
request.action = "update";
|
||||
request.entity = "author";
|
||||
request.data = {
|
||||
author_id: "author_id_from_rest_api",
|
||||
birthdate: "1992-11-03",
|
||||
name: "modify author from QxOrm REST API",
|
||||
sex: 0
|
||||
};
|
||||
}
|
||||
else if (objRequestExample.key == "update_list_of_author") {
|
||||
request.action = "update";
|
||||
request.entity = "author";
|
||||
request.data = [
|
||||
{
|
||||
author_id: "author_id_from_rest_api",
|
||||
birthdate: "1992-11-03",
|
||||
name: "modify author from QxOrm REST API",
|
||||
sex: 0
|
||||
},
|
||||
{
|
||||
author_id: "author_id_1",
|
||||
birthdate: "1978-12-25",
|
||||
name: "modify another author from QxOrm REST API",
|
||||
sex: 2
|
||||
}
|
||||
];
|
||||
}
|
||||
else if (objRequestExample.key == "update_category") {
|
||||
request.action = "update";
|
||||
request.entity = "category";
|
||||
request.data = {
|
||||
category_id: 1,
|
||||
description: "category modified by REST API",
|
||||
name: "modif_category"
|
||||
};
|
||||
}
|
||||
else if (objRequestExample.key == "save_blog") {
|
||||
request.action = "save";
|
||||
request.entity = "blog";
|
||||
request.data = {
|
||||
blog_id: 1,
|
||||
blog_text: "modify blog from QxOrm REST API",
|
||||
date_creation: "2013-11-25T09:56:33",
|
||||
author_id: "author_id_1"
|
||||
};
|
||||
}
|
||||
else if (objRequestExample.key == "save_list_of_blog") {
|
||||
request.action = "save";
|
||||
request.entity = "blog";
|
||||
request.data = [
|
||||
{
|
||||
blog_id: 1,
|
||||
blog_text: "save blog from QxOrm REST API !",
|
||||
date_creation: "2018-01-30T12:42:01",
|
||||
author_id: "author_id_2"
|
||||
},
|
||||
{
|
||||
blog_text: "save another blog from QxOrm REST API !",
|
||||
date_creation: "2016-06-12T08:33:12",
|
||||
author_id: "author_id_1"
|
||||
}
|
||||
];
|
||||
}
|
||||
else if (objRequestExample.key == "save_blog_recursive") {
|
||||
request.action = "save";
|
||||
request.entity = "blog";
|
||||
request.data = {
|
||||
blog_id: 1,
|
||||
blog_text: "save recursive blog from QxOrm REST API",
|
||||
date_creation: "2013-11-25T09:56:33",
|
||||
author_id: {
|
||||
author_id: "author_id_1",
|
||||
birthdate: "1965-07-21",
|
||||
name: "save recursive author from QxOrm REST API",
|
||||
sex: 0
|
||||
}
|
||||
};
|
||||
request.save_mode = "check_insert_or_update";
|
||||
}
|
||||
else if (objRequestExample.key == "save_blog_recursive_insert") {
|
||||
request.action = "save";
|
||||
request.entity = "blog";
|
||||
request.data = {
|
||||
blog_text: "save recursive - new blog from QxOrm REST API",
|
||||
date_creation: "2013-11-25T09:56:33",
|
||||
author_id: {
|
||||
author_id: "author_id_save_recursive",
|
||||
birthdate: "1965-07-21",
|
||||
name: "save recursive (insert only) author from QxOrm REST API",
|
||||
sex: 0
|
||||
}
|
||||
};
|
||||
request.save_mode = "insert_only";
|
||||
}
|
||||
else if (objRequestExample.key == "exist_blog") {
|
||||
request.action = "exist";
|
||||
request.entity = "blog";
|
||||
request.data = { blog_id: 1 };
|
||||
}
|
||||
else if (objRequestExample.key == "exist_list_of_blog") {
|
||||
request.action = "exist";
|
||||
request.entity = "blog";
|
||||
request.data = [ { blog_id: 1 }, { blog_id: 999 }, { blog_id: 3 } ];
|
||||
}
|
||||
else if (objRequestExample.key == "exist_author") {
|
||||
request.action = "exist";
|
||||
request.entity = "author";
|
||||
request.data = { author_id: "author_id_2" };
|
||||
}
|
||||
else if (objRequestExample.key == "validate_blog") {
|
||||
request.action = "validate";
|
||||
request.entity = "blog";
|
||||
request.data = { blog_id: 9999, blog_text: "" };
|
||||
}
|
||||
else if (objRequestExample.key == "count_all_blog") {
|
||||
request.action = "count";
|
||||
request.entity = "blog";
|
||||
}
|
||||
else if (objRequestExample.key == "count_author_with_query") {
|
||||
request.action = "count";
|
||||
request.entity = "author";
|
||||
request.query = {
|
||||
sql: "WHERE author.sex = :sex",
|
||||
params: [ { key: ":sex", value: 1 } ]
|
||||
};
|
||||
}
|
||||
else if (objRequestExample.key == "count_blog_with_query_and_relationships") {
|
||||
request.action = "count";
|
||||
request.entity = "blog";
|
||||
request.query = {
|
||||
sql: "WHERE author_alias.sex = :sex",
|
||||
params: [ { key: ":sex", value: 1 } ]
|
||||
};
|
||||
request.relations = [ "author_id <author_alias> { sex }" ];
|
||||
}
|
||||
else if (objRequestExample.key == "delete_blog_by_id") {
|
||||
request.action = "delete_by_id";
|
||||
request.entity = "blog";
|
||||
request.data = { blog_id: 4 };
|
||||
}
|
||||
else if (objRequestExample.key == "delete_list_of_blog_by_id") {
|
||||
request.action = "delete_by_id";
|
||||
request.entity = "blog";
|
||||
request.data = [ { blog_id: 3 }, { blog_id: 2 } ];
|
||||
}
|
||||
else if (objRequestExample.key == "delete_author_by_query") {
|
||||
request.action = "delete_by_query";
|
||||
request.entity = "author";
|
||||
request.query = {
|
||||
sql: "WHERE author.sex = :sex",
|
||||
params: [ { key: ":sex", value: 1 } ]
|
||||
};
|
||||
}
|
||||
else if (objRequestExample.key == "delete_all_comment") {
|
||||
request.action = "delete_all";
|
||||
request.entity = "comment";
|
||||
}
|
||||
else if (objRequestExample.key == "call_custom_query") {
|
||||
request.action = "call_custom_query";
|
||||
request.query = {
|
||||
sql: "INSERT INTO author (author_id, name, birthdate, sex) VALUES (:author_id, :name, :birthdate, :sex)",
|
||||
params: [
|
||||
{ key: ":author_id", value: "author_id_custom_query" },
|
||||
{ key: ":name", value: "new author inserted by custom query" },
|
||||
{ key: ":birthdate", value: "20190215" },
|
||||
{ key: ":sex", value: 2 }
|
||||
]
|
||||
};
|
||||
}
|
||||
else if (objRequestExample.key == "call_entity_function") {
|
||||
request.action = "call_entity_function";
|
||||
request.entity = "blog";
|
||||
request.fct = "helloWorld";
|
||||
request.data = { param1: "test", param2: "static fct call" };
|
||||
}
|
||||
else if (objRequestExample.key == "several_requests_in_array") {
|
||||
request = [ buildRequestExample(modelRequestExample.get(0)),
|
||||
buildRequestExample(modelRequestExample.get(1)),
|
||||
buildRequestExample(modelRequestExample.get(2)),
|
||||
buildRequestExample(modelRequestExample.get(3)) ];
|
||||
}
|
||||
else {
|
||||
request.error = "<unknown request example : " + objRequestExample.key + ">";
|
||||
}
|
||||
return request;
|
||||
}
|
||||
|
||||
function createGUID() {
|
||||
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
||||
var r = Math.random() * 16 | 0, v = c == "x" ? r : (r & 0x3 | 0x8);
|
||||
return v.toString(16);
|
||||
});
|
||||
}
|
||||
}
|
||||
513
test/qxBlogRestApi/qt/rcc/documents/test_rest_api_qt6.qml
Normal file
513
test/qxBlogRestApi/qt/rcc/documents/test_rest_api_qt6.qml
Normal file
@@ -0,0 +1,513 @@
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
|
||||
Item {
|
||||
width: 1000
|
||||
height: 700
|
||||
Row {
|
||||
anchors.fill: parent
|
||||
spacing: 10
|
||||
anchors.leftMargin: 5
|
||||
anchors.rightMargin: 5
|
||||
Column {
|
||||
width: ((parent.width - 10) * 0.5)
|
||||
height: (parent.height)
|
||||
spacing: 10
|
||||
Label {
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
text: "JSON Request"
|
||||
font.bold: true
|
||||
color: "blue"
|
||||
}
|
||||
Flickable {
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
height: (parent.height * 0.4)
|
||||
TextArea.flickable: TextArea {
|
||||
id: txtRequest
|
||||
wrapMode: TextEdit.NoWrap
|
||||
text: ""
|
||||
background: Rectangle {
|
||||
border.width: 1
|
||||
}
|
||||
}
|
||||
ScrollBar.vertical: ScrollBar { }
|
||||
ScrollBar.horizontal: ScrollBar { }
|
||||
}
|
||||
Button {
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
height: 45
|
||||
onClicked: onSendRequest()
|
||||
contentItem: Label {
|
||||
renderType: Text.NativeRendering
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
text: "Send JSON request"
|
||||
font.pointSize: 12
|
||||
font.bold: true
|
||||
color: "blue"
|
||||
}
|
||||
}
|
||||
Label {
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
text: "Here are some request examples :"
|
||||
font.italic: true
|
||||
color: "blue"
|
||||
}
|
||||
ScrollView {
|
||||
width: parent.width
|
||||
height: (parent.height * 0.4)
|
||||
ListView {
|
||||
id: lstRequestExample
|
||||
anchors.fill: parent
|
||||
flickableDirection: Flickable.VerticalFlick
|
||||
boundsBehavior: Flickable.StopAtBounds
|
||||
model: ListModel {
|
||||
id: modelRequestExample
|
||||
ListElement { key: "get_meta_data"; txt: " - get project meta-data (all classes)" }
|
||||
ListElement { key: "fetch_all_blogs"; txt: " - fetch all blogs (as list)" }
|
||||
ListElement { key: "fetch_all_blogs_as_collection"; txt: " - fetch all blogs (as collection key/value)" }
|
||||
ListElement { key: "fetch_all_blogs_with_relationships"; txt: " - fetch all blogs with relationships (several levels)" }
|
||||
ListElement { key: "fetch_all_blogs_with_relationships_output_format"; txt: " - fetch all blogs with relationships (several levels) and define output format" }
|
||||
ListElement { key: "fetch_blog_by_id"; txt: " - fetch a single blog by id" }
|
||||
ListElement { key: "fetch_blog_by_id_columns"; txt: " - fetch some columns of a single blog by id" }
|
||||
ListElement { key: "fetch_list_of_blog_by_id"; txt: " - fetch list of blogs by id" }
|
||||
ListElement { key: "fetch_list_of_blog_by_id_output_format"; txt: " - fetch list of blogs by id and define output format" }
|
||||
ListElement { key: "fetch_authors_by_query"; txt: " - fetch authors using a query (only female)" }
|
||||
ListElement { key: "fetch_authors_by_query_with_relationships"; txt: " - fetch authors with relationships using a query" }
|
||||
ListElement { key: "fetch_authors_by_query_with_relationships_output_format"; txt: " - fetch authors with relationships using a query and define output format" }
|
||||
ListElement { key: "insert_blog"; txt: " - insert a blog" }
|
||||
ListElement { key: "insert_list_of_blog"; txt: " - insert list of blogs" }
|
||||
ListElement { key: "insert_author"; txt: " - insert an author" }
|
||||
ListElement { key: "insert_category"; txt: " - insert a category" }
|
||||
ListElement { key: "update_blog"; txt: " - update a blog" }
|
||||
ListElement { key: "update_blog_columns"; txt: " - update some columns of blog" }
|
||||
ListElement { key: "update_author"; txt: " - update an author" }
|
||||
ListElement { key: "update_list_of_author"; txt: " - update list of authors" }
|
||||
ListElement { key: "update_category"; txt: " - update a category" }
|
||||
ListElement { key: "save_blog"; txt: " - save (insert or update) a blog" }
|
||||
ListElement { key: "save_list_of_blog"; txt: " - save (insert or update) list of blogs" }
|
||||
ListElement { key: "save_blog_recursive"; txt: " - save (insert or update) a blog with relationships (recursively)" }
|
||||
ListElement { key: "save_blog_recursive_insert"; txt: " - save (insert optimized) a blog with relationships (recursively)" }
|
||||
ListElement { key: "exist_blog"; txt: " - check if a blog id exist" }
|
||||
ListElement { key: "exist_list_of_blog"; txt: " - check if list of blogs id exist" }
|
||||
ListElement { key: "exist_author"; txt: " - check if an author id exist" }
|
||||
ListElement { key: "validate_blog"; txt: " - validate a blog instance" }
|
||||
ListElement { key: "count_all_blog"; txt: " - count all blogs" }
|
||||
ListElement { key: "count_author_with_query"; txt: " - count authors using a query" }
|
||||
ListElement { key: "count_blog_with_query_and_relationships"; txt: " - count blogs using a query and relationships" }
|
||||
ListElement { key: "delete_blog_by_id"; txt: " - delete a blog by id" }
|
||||
ListElement { key: "delete_list_of_blog_by_id"; txt: " - delete list of blogs by id" }
|
||||
ListElement { key: "delete_author_by_query"; txt: " - delete some authors using a query" }
|
||||
ListElement { key: "delete_all_comment"; txt: " - delete all comments" }
|
||||
ListElement { key: "call_custom_query"; txt: " - call custom database query or stored procedure" }
|
||||
ListElement { key: "call_entity_function"; txt: " - call entity static function with signature : static QJsonValue myEntity::myFct(const QJsonValue & request)" }
|
||||
ListElement { key: "several_requests_in_array"; txt: " - build several requests in array to send only 1 call to server (executed in a transaction commit/rollback)" }
|
||||
}
|
||||
delegate: Rectangle {
|
||||
width: parent.width
|
||||
height: 20
|
||||
color: ((index == lstRequestExample.currentIndex) ? "lightblue" : (((index % 2) == 0) ? "white" : "papayawhip"))
|
||||
Column { Text { text: txt } }
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
onClicked: lstRequestExample.currentIndex = index
|
||||
}
|
||||
}
|
||||
highlight: Rectangle { color: "lightblue" }
|
||||
onCurrentItemChanged: onRequestExampleSelected(modelRequestExample.get(lstRequestExample.currentIndex))
|
||||
Component.onCompleted : currentIndex = -1
|
||||
focus: true
|
||||
}
|
||||
}
|
||||
}
|
||||
Column {
|
||||
width: ((parent.width - 10) * 0.5)
|
||||
height: (parent.height)
|
||||
spacing: 10
|
||||
Label {
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
text: "JSON Response"
|
||||
font.bold: true
|
||||
color: "blue"
|
||||
}
|
||||
Flickable {
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
height: (parent.height * 0.9)
|
||||
TextArea.flickable: TextArea {
|
||||
id: txtResponse
|
||||
wrapMode: TextEdit.NoWrap
|
||||
text: ""
|
||||
background: Rectangle {
|
||||
border.width: 1
|
||||
}
|
||||
}
|
||||
ScrollBar.vertical: ScrollBar { }
|
||||
ScrollBar.horizontal: ScrollBar { }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function onSendRequest() {
|
||||
try {
|
||||
console.log("onSendRequest() called");
|
||||
qxRestApi.clearAll();
|
||||
var response = qxRestApi.processRequest(txtRequest.text);
|
||||
response = JSON.parse(response);
|
||||
txtResponse.text = JSON.stringify(response, null, 3);
|
||||
}
|
||||
catch(exc) {
|
||||
txtResponse.text = "An error occurred processing request : " + exc;
|
||||
}
|
||||
}
|
||||
|
||||
function onRequestExampleSelected(objRequestExample) {
|
||||
txtResponse.text = "";
|
||||
if (! objRequestExample) { return; }
|
||||
console.log("onRequestExampleSelected() : " + objRequestExample.key + " selected");
|
||||
var request = buildRequestExample(objRequestExample);
|
||||
txtRequest.text = JSON.stringify(request, null, 3);
|
||||
}
|
||||
|
||||
function buildRequestExample(objRequestExample) {
|
||||
var request = { };
|
||||
request.request_id = createGUID();
|
||||
if (objRequestExample.key == "get_meta_data") {
|
||||
request.action = "get_meta_data";
|
||||
request.entity = "*";
|
||||
}
|
||||
else if (objRequestExample.key == "fetch_all_blogs") {
|
||||
request.action = "fetch_all";
|
||||
request.entity = "blog";
|
||||
}
|
||||
else if (objRequestExample.key == "fetch_all_blogs_as_collection") {
|
||||
request.action = "fetch_all";
|
||||
request.entity = "blog";
|
||||
request.data = [ { key: "", value: "" } ]
|
||||
}
|
||||
else if (objRequestExample.key == "fetch_all_blogs_with_relationships") {
|
||||
request.action = "fetch_all";
|
||||
request.entity = "blog";
|
||||
request.relations = [ "*->*" ];
|
||||
}
|
||||
else if (objRequestExample.key == "fetch_all_blogs_with_relationships_output_format") {
|
||||
request.action = "fetch_all";
|
||||
request.entity = "blog";
|
||||
request.relations = [ "<blog_alias> { blog_text }", "author_id <author_alias> { name, birthdate }", "list_comment <list_comment_alias> { comment_text } -> blog_id <blog_alias_2> -> * <..._my_alias_suffix>" ];
|
||||
request.output_format = [ "{ blog_text }", "author_id { name, birthdate }", "list_comment { comment_text } -> blog_id -> *" ];
|
||||
}
|
||||
else if (objRequestExample.key == "fetch_blog_by_id") {
|
||||
request.action = "fetch_by_id";
|
||||
request.entity = "blog";
|
||||
request.data = { blog_id: 1 };
|
||||
}
|
||||
else if (objRequestExample.key == "fetch_blog_by_id_columns") {
|
||||
request.action = "fetch_by_id";
|
||||
request.entity = "blog";
|
||||
request.data = { blog_id: 1 };
|
||||
request.columns = [ "blog_text", "date_creation" ];
|
||||
}
|
||||
else if (objRequestExample.key == "fetch_list_of_blog_by_id") {
|
||||
request.action = "fetch_by_id";
|
||||
request.entity = "blog";
|
||||
request.data = [ { blog_id: 1 }, { blog_id: 2 }, { blog_id: 3 } ];
|
||||
}
|
||||
else if (objRequestExample.key == "fetch_list_of_blog_by_id_output_format") {
|
||||
request.action = "fetch_by_id";
|
||||
request.entity = "blog";
|
||||
request.data = [ { blog_id: 1 }, { blog_id: 2 } ];
|
||||
request.relations = [ "{ blog_text }", "author_id <author_alias> { name, birthdate }", "list_comment <list_comment_alias> { comment_text }" ];
|
||||
request.output_format = [ "{ blog_text }", "author_id { name, birthdate }", "list_comment { comment_text }" ];
|
||||
}
|
||||
else if (objRequestExample.key == "fetch_authors_by_query") {
|
||||
request.action = "fetch_by_query";
|
||||
request.entity = "author";
|
||||
request.query = {
|
||||
sql: "WHERE author.sex = :sex",
|
||||
params: [ { key: ":sex", value: 1, type: "in" } ]
|
||||
};
|
||||
}
|
||||
else if (objRequestExample.key == "fetch_authors_by_query_with_relationships") {
|
||||
request.action = "fetch_by_query";
|
||||
request.entity = "author";
|
||||
request.query = {
|
||||
sql: "WHERE author.sex = :sex",
|
||||
params: [ { key: ":sex", value: 1, type: "in" } ]
|
||||
};
|
||||
request.relations = [ "*" ];
|
||||
}
|
||||
else if (objRequestExample.key == "fetch_authors_by_query_with_relationships_output_format") {
|
||||
request.action = "fetch_by_query";
|
||||
request.entity = "author";
|
||||
request.query = {
|
||||
sql: "WHERE author.sex = :sex",
|
||||
params: [ { key: ":sex", value: 1, type: "in" } ]
|
||||
};
|
||||
request.relations = [ "*" ];
|
||||
request.output_format = [ "{ birthdate, name }", "list_blog { blog_text, date_creation }" ];
|
||||
}
|
||||
else if (objRequestExample.key == "insert_blog") {
|
||||
request.action = "insert";
|
||||
request.entity = "blog";
|
||||
request.data = {
|
||||
blog_text: "this is a new blog from QxOrm REST API !",
|
||||
date_creation: "2018-01-30T12:42:01",
|
||||
author_id: "author_id_2"
|
||||
};
|
||||
}
|
||||
else if (objRequestExample.key == "insert_list_of_blog") {
|
||||
request.action = "insert";
|
||||
request.entity = "blog";
|
||||
request.data = [
|
||||
{
|
||||
blog_text: "new blog from QxOrm REST API !",
|
||||
date_creation: "2018-01-30T12:42:01",
|
||||
author_id: "author_id_2"
|
||||
},
|
||||
{
|
||||
blog_text: "another blog from QxOrm REST API !",
|
||||
date_creation: "2016-06-12T08:33:12",
|
||||
author_id: "author_id_1"
|
||||
}
|
||||
];
|
||||
}
|
||||
else if (objRequestExample.key == "insert_author") {
|
||||
request.action = "insert";
|
||||
request.entity = "author";
|
||||
request.data = {
|
||||
author_id: "author_id_from_rest_api",
|
||||
birthdate: "1978-05-11",
|
||||
name: "new author created by QxOrm REST API",
|
||||
sex: 1
|
||||
};
|
||||
}
|
||||
else if (objRequestExample.key == "insert_category") {
|
||||
request.action = "insert";
|
||||
request.entity = "category";
|
||||
request.data = {
|
||||
description: "category from REST API",
|
||||
name: "new_category"
|
||||
};
|
||||
}
|
||||
else if (objRequestExample.key == "update_blog") {
|
||||
request.action = "update";
|
||||
request.entity = "blog";
|
||||
request.data = {
|
||||
blog_id: 1,
|
||||
blog_text: "modify blog from QxOrm REST API",
|
||||
date_creation: "2013-11-25T09:56:33",
|
||||
author_id: "author_id_1"
|
||||
};
|
||||
}
|
||||
else if (objRequestExample.key == "update_blog_columns") {
|
||||
request.action = "update";
|
||||
request.entity = "blog";
|
||||
request.data = {
|
||||
blog_id: 2,
|
||||
blog_text: "modify blog from QxOrm REST API",
|
||||
date_creation: "2013-11-25T09:56:33"
|
||||
};
|
||||
request.columns = [ "blog_text", "date_creation" ];
|
||||
}
|
||||
else if (objRequestExample.key == "update_author") {
|
||||
request.action = "update";
|
||||
request.entity = "author";
|
||||
request.data = {
|
||||
author_id: "author_id_from_rest_api",
|
||||
birthdate: "1992-11-03",
|
||||
name: "modify author from QxOrm REST API",
|
||||
sex: 0
|
||||
};
|
||||
}
|
||||
else if (objRequestExample.key == "update_list_of_author") {
|
||||
request.action = "update";
|
||||
request.entity = "author";
|
||||
request.data = [
|
||||
{
|
||||
author_id: "author_id_from_rest_api",
|
||||
birthdate: "1992-11-03",
|
||||
name: "modify author from QxOrm REST API",
|
||||
sex: 0
|
||||
},
|
||||
{
|
||||
author_id: "author_id_1",
|
||||
birthdate: "1978-12-25",
|
||||
name: "modify another author from QxOrm REST API",
|
||||
sex: 2
|
||||
}
|
||||
];
|
||||
}
|
||||
else if (objRequestExample.key == "update_category") {
|
||||
request.action = "update";
|
||||
request.entity = "category";
|
||||
request.data = {
|
||||
category_id: 1,
|
||||
description: "category modified by REST API",
|
||||
name: "modif_category"
|
||||
};
|
||||
}
|
||||
else if (objRequestExample.key == "save_blog") {
|
||||
request.action = "save";
|
||||
request.entity = "blog";
|
||||
request.data = {
|
||||
blog_id: 1,
|
||||
blog_text: "modify blog from QxOrm REST API",
|
||||
date_creation: "2013-11-25T09:56:33",
|
||||
author_id: "author_id_1"
|
||||
};
|
||||
}
|
||||
else if (objRequestExample.key == "save_list_of_blog") {
|
||||
request.action = "save";
|
||||
request.entity = "blog";
|
||||
request.data = [
|
||||
{
|
||||
blog_id: 1,
|
||||
blog_text: "save blog from QxOrm REST API !",
|
||||
date_creation: "2018-01-30T12:42:01",
|
||||
author_id: "author_id_2"
|
||||
},
|
||||
{
|
||||
blog_text: "save another blog from QxOrm REST API !",
|
||||
date_creation: "2016-06-12T08:33:12",
|
||||
author_id: "author_id_1"
|
||||
}
|
||||
];
|
||||
}
|
||||
else if (objRequestExample.key == "save_blog_recursive") {
|
||||
request.action = "save";
|
||||
request.entity = "blog";
|
||||
request.data = {
|
||||
blog_id: 1,
|
||||
blog_text: "save recursive blog from QxOrm REST API",
|
||||
date_creation: "2013-11-25T09:56:33",
|
||||
author_id: {
|
||||
author_id: "author_id_1",
|
||||
birthdate: "1965-07-21",
|
||||
name: "save recursive author from QxOrm REST API",
|
||||
sex: 0
|
||||
}
|
||||
};
|
||||
request.save_mode = "check_insert_or_update";
|
||||
}
|
||||
else if (objRequestExample.key == "save_blog_recursive_insert") {
|
||||
request.action = "save";
|
||||
request.entity = "blog";
|
||||
request.data = {
|
||||
blog_text: "save recursive - new blog from QxOrm REST API",
|
||||
date_creation: "2013-11-25T09:56:33",
|
||||
author_id: {
|
||||
author_id: "author_id_save_recursive",
|
||||
birthdate: "1965-07-21",
|
||||
name: "save recursive (insert only) author from QxOrm REST API",
|
||||
sex: 0
|
||||
}
|
||||
};
|
||||
request.save_mode = "insert_only";
|
||||
}
|
||||
else if (objRequestExample.key == "exist_blog") {
|
||||
request.action = "exist";
|
||||
request.entity = "blog";
|
||||
request.data = { blog_id: 1 };
|
||||
}
|
||||
else if (objRequestExample.key == "exist_list_of_blog") {
|
||||
request.action = "exist";
|
||||
request.entity = "blog";
|
||||
request.data = [ { blog_id: 1 }, { blog_id: 999 }, { blog_id: 3 } ];
|
||||
}
|
||||
else if (objRequestExample.key == "exist_author") {
|
||||
request.action = "exist";
|
||||
request.entity = "author";
|
||||
request.data = { author_id: "author_id_2" };
|
||||
}
|
||||
else if (objRequestExample.key == "validate_blog") {
|
||||
request.action = "validate";
|
||||
request.entity = "blog";
|
||||
request.data = { blog_id: 9999, blog_text: "" };
|
||||
}
|
||||
else if (objRequestExample.key == "count_all_blog") {
|
||||
request.action = "count";
|
||||
request.entity = "blog";
|
||||
}
|
||||
else if (objRequestExample.key == "count_author_with_query") {
|
||||
request.action = "count";
|
||||
request.entity = "author";
|
||||
request.query = {
|
||||
sql: "WHERE author.sex = :sex",
|
||||
params: [ { key: ":sex", value: 1 } ]
|
||||
};
|
||||
}
|
||||
else if (objRequestExample.key == "count_blog_with_query_and_relationships") {
|
||||
request.action = "count";
|
||||
request.entity = "blog";
|
||||
request.query = {
|
||||
sql: "WHERE author_alias.sex = :sex",
|
||||
params: [ { key: ":sex", value: 1 } ]
|
||||
};
|
||||
request.relations = [ "author_id <author_alias> { sex }" ];
|
||||
}
|
||||
else if (objRequestExample.key == "delete_blog_by_id") {
|
||||
request.action = "delete_by_id";
|
||||
request.entity = "blog";
|
||||
request.data = { blog_id: 4 };
|
||||
}
|
||||
else if (objRequestExample.key == "delete_list_of_blog_by_id") {
|
||||
request.action = "delete_by_id";
|
||||
request.entity = "blog";
|
||||
request.data = [ { blog_id: 3 }, { blog_id: 2 } ];
|
||||
}
|
||||
else if (objRequestExample.key == "delete_author_by_query") {
|
||||
request.action = "delete_by_query";
|
||||
request.entity = "author";
|
||||
request.query = {
|
||||
sql: "WHERE author.sex = :sex",
|
||||
params: [ { key: ":sex", value: 1 } ]
|
||||
};
|
||||
}
|
||||
else if (objRequestExample.key == "delete_all_comment") {
|
||||
request.action = "delete_all";
|
||||
request.entity = "comment";
|
||||
}
|
||||
else if (objRequestExample.key == "call_custom_query") {
|
||||
request.action = "call_custom_query";
|
||||
request.query = {
|
||||
sql: "INSERT INTO author (author_id, name, birthdate, sex) VALUES (:author_id, :name, :birthdate, :sex)",
|
||||
params: [
|
||||
{ key: ":author_id", value: "author_id_custom_query" },
|
||||
{ key: ":name", value: "new author inserted by custom query" },
|
||||
{ key: ":birthdate", value: "20190215" },
|
||||
{ key: ":sex", value: 2 }
|
||||
]
|
||||
};
|
||||
}
|
||||
else if (objRequestExample.key == "call_entity_function") {
|
||||
request.action = "call_entity_function";
|
||||
request.entity = "blog";
|
||||
request.fct = "helloWorld";
|
||||
request.data = { param1: "test", param2: "static fct call" };
|
||||
}
|
||||
else if (objRequestExample.key == "several_requests_in_array") {
|
||||
request = [ buildRequestExample(modelRequestExample.get(0)),
|
||||
buildRequestExample(modelRequestExample.get(1)),
|
||||
buildRequestExample(modelRequestExample.get(2)),
|
||||
buildRequestExample(modelRequestExample.get(3)) ];
|
||||
}
|
||||
else {
|
||||
request.error = "<unknown request example : " + objRequestExample.key + ">";
|
||||
}
|
||||
return request;
|
||||
}
|
||||
|
||||
function createGUID() {
|
||||
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
||||
var r = Math.random() * 16 | 0, v = c == "x" ? r : (r & 0x3 | 0x8);
|
||||
return v.toString(16);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user