first commit
This commit is contained in:
76
test/qxBlogRestApi/CMakeLists.txt
Normal file
76
test/qxBlogRestApi/CMakeLists.txt
Normal file
@@ -0,0 +1,76 @@
|
||||
cmake_minimum_required(VERSION 3.1)
|
||||
|
||||
project(qxBlogRestApi LANGUAGES CXX)
|
||||
|
||||
include(../../QxOrm.cmake)
|
||||
|
||||
if(NOT _QX_NO_JSON)
|
||||
|
||||
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Sql Gui Widgets Quick Qml REQUIRED)
|
||||
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||
set(CMAKE_DEBUG_POSTFIX "d")
|
||||
|
||||
set(HEADERS
|
||||
./include/precompiled.h
|
||||
./include/export.h
|
||||
./include/author.h
|
||||
./include/blog.h
|
||||
./include/category.h
|
||||
./include/comment.h
|
||||
)
|
||||
|
||||
set(SRCS
|
||||
./src/author.cpp
|
||||
./src/blog.cpp
|
||||
./src/category.cpp
|
||||
./src/comment.cpp
|
||||
./src/main.cpp
|
||||
)
|
||||
|
||||
set(QRCS
|
||||
./qt/rcc/qxBlogRestApi.qrc
|
||||
)
|
||||
|
||||
if(COMMAND qt_add_resources)
|
||||
qt_add_resources(QRCS_HDRS ${QRCS})
|
||||
else() # (COMMAND qt_add_resources)
|
||||
qt5_add_resources(QRCS_HDRS ${QRCS})
|
||||
endif() # (COMMAND qt_add_resources)
|
||||
|
||||
add_executable(qxBlogRestApi ${SRCS} ${HEADERS} ${QRCS_HDRS})
|
||||
|
||||
target_compile_definitions(qxBlogRestApi PRIVATE -D_BUILDING_QX_BLOG)
|
||||
|
||||
if(COMMAND target_precompile_headers)
|
||||
target_precompile_headers(qxBlogRestApi PRIVATE ./include/precompiled.h)
|
||||
endif() # (COMMAND target_precompile_headers)
|
||||
|
||||
target_link_libraries(qxBlogRestApi ${QX_LIBRARIES} QxOrm Qt${QT_VERSION_MAJOR}::Gui Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Quick Qt${QT_VERSION_MAJOR}::Qml)
|
||||
|
||||
set_target_properties(qxBlogRestApi PROPERTIES
|
||||
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../_bin"
|
||||
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../_bin"
|
||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../_bin"
|
||||
ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${CMAKE_CURRENT_SOURCE_DIR}/../_bin"
|
||||
LIBRARY_OUTPUT_DIRECTORY_DEBUG "${CMAKE_CURRENT_SOURCE_DIR}/../_bin"
|
||||
RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_CURRENT_SOURCE_DIR}/../_bin"
|
||||
ARCHIVE_OUTPUT_DIRECTORY_RELEASE "${CMAKE_CURRENT_SOURCE_DIR}/../_bin"
|
||||
LIBRARY_OUTPUT_DIRECTORY_RELEASE "${CMAKE_CURRENT_SOURCE_DIR}/../_bin"
|
||||
RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_CURRENT_SOURCE_DIR}/../_bin"
|
||||
ARCHIVE_OUTPUT_DIRECTORY_MINSIZEREL "${CMAKE_CURRENT_SOURCE_DIR}/../_bin"
|
||||
LIBRARY_OUTPUT_DIRECTORY_MINSIZEREL "${CMAKE_CURRENT_SOURCE_DIR}/../_bin"
|
||||
RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL "${CMAKE_CURRENT_SOURCE_DIR}/../_bin"
|
||||
ARCHIVE_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_CURRENT_SOURCE_DIR}/../_bin"
|
||||
LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_CURRENT_SOURCE_DIR}/../_bin"
|
||||
RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_CURRENT_SOURCE_DIR}/../_bin"
|
||||
)
|
||||
|
||||
set_target_properties(qxBlogRestApi PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})
|
||||
|
||||
else() # _QX_NO_JSON
|
||||
|
||||
message(STATUS "qxBlogRestApi project not loaded because _QX_NO_JSON option is defined (QxOrm REST API requires JSON serialization)")
|
||||
|
||||
endif() # _QX_NO_JSON
|
||||
7
test/qxBlogRestApi/debug/.gitignore
vendored
Normal file
7
test/qxBlogRestApi/debug/.gitignore
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
# git does not allow empty directories.
|
||||
# Yet, we need to add this empty directory on git.
|
||||
# To achieve that, we created this .gitignore file, so that the directory will not be empty thus enabling us to commit it.
|
||||
# Since we want all generated files/folders in this directory to be ignored by git, we add a rule for this.
|
||||
*
|
||||
# And then add an exception for this specifc file (so that we can commit it).
|
||||
!.gitignore
|
||||
34
test/qxBlogRestApi/include/author.h
Normal file
34
test/qxBlogRestApi/include/author.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#ifndef _QX_BLOG_AUTHOR_H_
|
||||
#define _QX_BLOG_AUTHOR_H_
|
||||
|
||||
class blog;
|
||||
|
||||
class QX_BLOG_DLL_EXPORT author : public qx::IxPersistable
|
||||
{
|
||||
QX_PERSISTABLE_HPP(author)
|
||||
public:
|
||||
// -- typedef
|
||||
typedef std::shared_ptr<blog> blog_ptr;
|
||||
typedef std::vector<blog_ptr> list_blog;
|
||||
// -- enum
|
||||
enum enum_sex { male, female, unknown };
|
||||
// -- properties
|
||||
QString m_id;
|
||||
QString m_name;
|
||||
QDate m_birthdate;
|
||||
enum_sex m_sex;
|
||||
list_blog m_blogX;
|
||||
// -- contructor, virtual destructor
|
||||
author() : qx::IxPersistable(), m_id("0"), m_sex(unknown) { ; }
|
||||
virtual ~author() { ; }
|
||||
// -- methods
|
||||
int age() const;
|
||||
};
|
||||
|
||||
QX_REGISTER_PRIMARY_KEY(author, QString)
|
||||
QX_REGISTER_HPP_QX_BLOG(author, qx::trait::no_base_class_defined, 0)
|
||||
|
||||
typedef std::shared_ptr<author> author_ptr;
|
||||
typedef qx::QxCollection<QString, author_ptr> list_author;
|
||||
|
||||
#endif // _QX_BLOG_AUTHOR_H_
|
||||
37
test/qxBlogRestApi/include/blog.h
Normal file
37
test/qxBlogRestApi/include/blog.h
Normal file
@@ -0,0 +1,37 @@
|
||||
#ifndef _QX_BLOG_BLOG_H_
|
||||
#define _QX_BLOG_BLOG_H_
|
||||
|
||||
#include "author.h"
|
||||
#include "comment.h"
|
||||
#include "category.h"
|
||||
|
||||
class QX_BLOG_DLL_EXPORT blog : public qx::IxPersistable
|
||||
{
|
||||
QX_PERSISTABLE_HPP(blog)
|
||||
QX_REGISTER_FRIEND_CLASS(blog)
|
||||
public:
|
||||
// -- properties
|
||||
long m_id;
|
||||
QString m_text;
|
||||
QDateTime m_dt_creation;
|
||||
author_ptr m_author;
|
||||
list_comment m_commentX;
|
||||
list_category m_categoryX;
|
||||
// -- contructor, virtual destructor
|
||||
blog() : qx::IxPersistable(), m_id(0) { ; }
|
||||
virtual ~blog() { ; }
|
||||
#ifndef _QX_NO_JSON
|
||||
// -- function callable by introspection and REST API
|
||||
static QJsonValue helloWorld(const QJsonValue & request);
|
||||
#endif // _QX_NO_JSON
|
||||
private:
|
||||
// -- function to validate a blog instance
|
||||
void isValid(qx::QxInvalidValueX & invalidValues);
|
||||
};
|
||||
|
||||
QX_REGISTER_HPP_QX_BLOG(blog, qx::trait::no_base_class_defined, 0)
|
||||
|
||||
typedef std::shared_ptr<blog> blog_ptr;
|
||||
typedef std::vector<blog_ptr> list_blog;
|
||||
|
||||
#endif // _QX_BLOG_BLOG_H_
|
||||
28
test/qxBlogRestApi/include/category.h
Normal file
28
test/qxBlogRestApi/include/category.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef _QX_BLOG_CATEGORY_H_
|
||||
#define _QX_BLOG_CATEGORY_H_
|
||||
|
||||
class blog;
|
||||
|
||||
class QX_BLOG_DLL_EXPORT category : public qx::IxPersistable
|
||||
{
|
||||
QX_PERSISTABLE_HPP(category)
|
||||
public:
|
||||
// -- typedef
|
||||
typedef std::shared_ptr<blog> blog_ptr;
|
||||
typedef qx::QxCollection<long, blog_ptr> list_blog;
|
||||
// -- properties
|
||||
long m_id;
|
||||
QString m_name;
|
||||
QString m_desc;
|
||||
list_blog m_blogX;
|
||||
// -- contructor, virtual destructor
|
||||
category() : qx::IxPersistable(), m_id(0) { ; }
|
||||
virtual ~category() { ; }
|
||||
};
|
||||
|
||||
QX_REGISTER_HPP_QX_BLOG(category, qx::trait::no_base_class_defined, 0)
|
||||
|
||||
typedef QSharedPointer<category> category_ptr;
|
||||
typedef qx::QxCollection<long, category_ptr> list_category;
|
||||
|
||||
#endif // _QX_BLOG_CATEGORY_H_
|
||||
27
test/qxBlogRestApi/include/comment.h
Normal file
27
test/qxBlogRestApi/include/comment.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#ifndef _QX_BLOG_COMMENT_H_
|
||||
#define _QX_BLOG_COMMENT_H_
|
||||
|
||||
class blog;
|
||||
|
||||
class QX_BLOG_DLL_EXPORT comment : public qx::IxPersistable
|
||||
{
|
||||
QX_PERSISTABLE_HPP(comment)
|
||||
public:
|
||||
// -- typedef
|
||||
typedef std::shared_ptr<blog> blog_ptr;
|
||||
// -- properties
|
||||
long m_id;
|
||||
QString m_text;
|
||||
QDateTime m_dt_create;
|
||||
blog_ptr m_blog;
|
||||
// -- contructor, virtual destructor
|
||||
comment() : qx::IxPersistable(), m_id(0) { ; }
|
||||
virtual ~comment() { ; }
|
||||
};
|
||||
|
||||
QX_REGISTER_HPP_QX_BLOG(comment, qx::trait::no_base_class_defined, 0)
|
||||
|
||||
typedef std::shared_ptr<comment> comment_ptr;
|
||||
typedef QList<comment_ptr> list_comment;
|
||||
|
||||
#endif // _QX_BLOG_COMMENT_H_
|
||||
18
test/qxBlogRestApi/include/export.h
Normal file
18
test/qxBlogRestApi/include/export.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifndef _QX_BLOG_EXPORT_H_
|
||||
#define _QX_BLOG_EXPORT_H_
|
||||
|
||||
#ifdef _BUILDING_QX_BLOG
|
||||
#define QX_BLOG_DLL_EXPORT QX_DLL_EXPORT_HELPER
|
||||
#else // _BUILDING_QX_BLOG
|
||||
#define QX_BLOG_DLL_EXPORT QX_DLL_IMPORT_HELPER
|
||||
#endif // _BUILDING_QX_BLOG
|
||||
|
||||
#ifdef _BUILDING_QX_BLOG
|
||||
#define QX_REGISTER_HPP_QX_BLOG QX_REGISTER_HPP_EXPORT_DLL
|
||||
#define QX_REGISTER_CPP_QX_BLOG QX_REGISTER_CPP_EXPORT_DLL
|
||||
#else // _BUILDING_QX_BLOG
|
||||
#define QX_REGISTER_HPP_QX_BLOG QX_REGISTER_HPP_IMPORT_DLL
|
||||
#define QX_REGISTER_CPP_QX_BLOG QX_REGISTER_CPP_IMPORT_DLL
|
||||
#endif // _BUILDING_QX_BLOG
|
||||
|
||||
#endif // _QX_BLOG_EXPORT_H_
|
||||
8
test/qxBlogRestApi/include/precompiled.h
Normal file
8
test/qxBlogRestApi/include/precompiled.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef _QX_BLOG_PRECOMPILED_HEADER_H_
|
||||
#define _QX_BLOG_PRECOMPILED_HEADER_H_
|
||||
|
||||
#include <QxOrm.h>
|
||||
|
||||
#include "export.h"
|
||||
|
||||
#endif // _QX_BLOG_PRECOMPILED_HEADER_H_
|
||||
7
test/qxBlogRestApi/qt/moc/.gitignore
vendored
Normal file
7
test/qxBlogRestApi/qt/moc/.gitignore
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
# git does not allow empty directories.
|
||||
# Yet, we need to add this empty directory on git.
|
||||
# To achieve that, we created this .gitignore file, so that the directory will not be empty thus enabling us to commit it.
|
||||
# Since we want all generated files/folders in this directory to be ignored by git, we add a rule for this.
|
||||
*
|
||||
# And then add an exception for this specifc file (so that we can commit it).
|
||||
!.gitignore
|
||||
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);
|
||||
});
|
||||
}
|
||||
}
|
||||
7
test/qxBlogRestApi/qt/rcc/images/.gitignore
vendored
Normal file
7
test/qxBlogRestApi/qt/rcc/images/.gitignore
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
# git does not allow empty directories.
|
||||
# Yet, we need to add this empty directory on git.
|
||||
# To achieve that, we created this .gitignore file, so that the directory will not be empty thus enabling us to commit it.
|
||||
# Since we want all generated files/folders in this directory to be ignored by git, we add a rule for this.
|
||||
*
|
||||
# And then add an exception for this specifc file (so that we can commit it).
|
||||
!.gitignore
|
||||
14
test/qxBlogRestApi/qt/rcc/qxBlogRestApi.qrc
Normal file
14
test/qxBlogRestApi/qt/rcc/qxBlogRestApi.qrc
Normal file
@@ -0,0 +1,14 @@
|
||||
<!DOCTYPE RCC><RCC version="1.0">
|
||||
<qresource>
|
||||
<file>documents/test_rest_api.qml</file>
|
||||
<file>documents/test_http_server.qml</file>
|
||||
<file>documents/test_rest_api_qt6.qml</file>
|
||||
<file>documents/test_http_server_qt6.qml</file>
|
||||
<file>documents/test_http_server.html</file>
|
||||
<file>documents/logo_qxorm_and_qxee.png</file>
|
||||
<file>documents/jquery.js</file>
|
||||
<file>documents/cert_qxorm_ca.pem</file>
|
||||
<file>documents/cert_qxorm_server.crt</file>
|
||||
<file>documents/cert_qxorm_server.key</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
7
test/qxBlogRestApi/qt/rcc/src/.gitignore
vendored
Normal file
7
test/qxBlogRestApi/qt/rcc/src/.gitignore
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
# git does not allow empty directories.
|
||||
# Yet, we need to add this empty directory on git.
|
||||
# To achieve that, we created this .gitignore file, so that the directory will not be empty thus enabling us to commit it.
|
||||
# Since we want all generated files/folders in this directory to be ignored by git, we add a rule for this.
|
||||
*
|
||||
# And then add an exception for this specifc file (so that we can commit it).
|
||||
!.gitignore
|
||||
44
test/qxBlogRestApi/qxBlog.pro
Normal file
44
test/qxBlogRestApi/qxBlog.pro
Normal file
@@ -0,0 +1,44 @@
|
||||
include(../../QxOrm.pri)
|
||||
|
||||
TEMPLATE = app
|
||||
DEFINES += _BUILDING_QX_BLOG
|
||||
INCLUDEPATH += ../../../QxOrm/include/
|
||||
DESTDIR = ../../../QxOrm/test/_bin/
|
||||
LIBS += -L"../../../QxOrm/lib"
|
||||
|
||||
!contains(DEFINES, _QX_NO_PRECOMPILED_HEADER) {
|
||||
PRECOMPILED_HEADER = ./include/precompiled.h
|
||||
} # !contains(DEFINES, _QX_NO_PRECOMPILED_HEADER)
|
||||
|
||||
greaterThan(QT_MAJOR_VERSION, 4) {
|
||||
QT += widgets
|
||||
QT += quick
|
||||
QT += qml
|
||||
} else {
|
||||
QT += declarative
|
||||
}
|
||||
|
||||
macx:CONFIG-=app_bundle
|
||||
|
||||
CONFIG(debug, debug|release) {
|
||||
TARGET = qxBlogRestApid
|
||||
LIBS += -l"QxOrmd"
|
||||
} else {
|
||||
TARGET = qxBlogRestApi
|
||||
LIBS += -l"QxOrm"
|
||||
} # CONFIG(debug, debug|release)
|
||||
|
||||
HEADERS += ./include/precompiled.h
|
||||
HEADERS += ./include/export.h
|
||||
HEADERS += ./include/author.h
|
||||
HEADERS += ./include/blog.h
|
||||
HEADERS += ./include/category.h
|
||||
HEADERS += ./include/comment.h
|
||||
|
||||
SOURCES += ./src/author.cpp
|
||||
SOURCES += ./src/blog.cpp
|
||||
SOURCES += ./src/category.cpp
|
||||
SOURCES += ./src/comment.cpp
|
||||
SOURCES += ./src/main.cpp
|
||||
|
||||
RESOURCES += ./qt/rcc/qxBlogRestApi.qrc
|
||||
7
test/qxBlogRestApi/release/.gitignore
vendored
Normal file
7
test/qxBlogRestApi/release/.gitignore
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
# git does not allow empty directories.
|
||||
# Yet, we need to add this empty directory on git.
|
||||
# To achieve that, we created this .gitignore file, so that the directory will not be empty thus enabling us to commit it.
|
||||
# Since we want all generated files/folders in this directory to be ignored by git, we add a rule for this.
|
||||
*
|
||||
# And then add an exception for this specifc file (so that we can commit it).
|
||||
!.gitignore
|
||||
29
test/qxBlogRestApi/src/author.cpp
Normal file
29
test/qxBlogRestApi/src/author.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
#include "../include/precompiled.h"
|
||||
|
||||
#include "../include/author.h"
|
||||
#include "../include/blog.h"
|
||||
|
||||
#include <QxOrm_Impl.h>
|
||||
|
||||
QX_REGISTER_CPP_QX_BLOG(author)
|
||||
QX_PERSISTABLE_CPP(author)
|
||||
|
||||
namespace qx {
|
||||
template <> void register_class(QxClass<author> & t)
|
||||
{
|
||||
t.id(& author::m_id, "author_id");
|
||||
|
||||
t.data(& author::m_name, "name");
|
||||
t.data(& author::m_birthdate, "birthdate");
|
||||
t.data(& author::m_sex, "sex");
|
||||
|
||||
t.relationOneToMany(& author::m_blogX, "list_blog", "author_id");
|
||||
|
||||
t.fct_0<int>(std::mem_fn(& author::age), "age"); // using std::mem_fn() here is just a workaround for an issue with some versions of MSVC, it is not required with a full compliant C++11 compiler (http://stackoverflow.com/questions/23778883/vs2013-stdfunction-with-member-function)
|
||||
}}
|
||||
|
||||
int author::age() const
|
||||
{
|
||||
if (! m_birthdate.isValid()) { return -1; }
|
||||
return (QDate::currentDate().year() - m_birthdate.year());
|
||||
}
|
||||
43
test/qxBlogRestApi/src/blog.cpp
Normal file
43
test/qxBlogRestApi/src/blog.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#include "../include/precompiled.h"
|
||||
|
||||
#include "../include/blog.h"
|
||||
|
||||
#include <QxOrm_Impl.h>
|
||||
|
||||
QX_REGISTER_CPP_QX_BLOG(blog)
|
||||
QX_PERSISTABLE_CPP(blog)
|
||||
|
||||
namespace qx {
|
||||
template <> void register_class(QxClass<blog> & t)
|
||||
{
|
||||
t.id(& blog::m_id, "blog_id");
|
||||
|
||||
t.data(& blog::m_text, "blog_text");
|
||||
t.data(& blog::m_dt_creation, "date_creation");
|
||||
|
||||
t.relationManyToOne(& blog::m_author, "author_id");
|
||||
t.relationOneToMany(& blog::m_commentX, "list_comment", "blog_id");
|
||||
t.relationManyToMany(& blog::m_categoryX, "list_category", "category_blog", "blog_id", "category_id");
|
||||
|
||||
#ifndef _QX_NO_JSON
|
||||
t.fctStatic_1<QJsonValue, const QJsonValue &>(& blog::helloWorld, "helloWorld");
|
||||
#endif // _QX_NO_JSON
|
||||
|
||||
QxValidatorX<blog> * pAllValidator = t.getAllValidator();
|
||||
pAllValidator->add_CustomValidator(std::mem_fn(& blog::isValid)); // using std::mem_fn() here is just a workaround for an issue with some versions of MSVC, it is not required with a full compliant C++11 compiler (http://stackoverflow.com/questions/23778883/vs2013-stdfunction-with-member-function)
|
||||
}}
|
||||
|
||||
#ifndef _QX_NO_JSON
|
||||
QJsonValue blog::helloWorld(const QJsonValue & request)
|
||||
{
|
||||
QJsonObject response;
|
||||
response.insert("request", request);
|
||||
response.insert("response", QString("Hello World !"));
|
||||
return response;
|
||||
}
|
||||
#endif // _QX_NO_JSON
|
||||
|
||||
void blog::isValid(qx::QxInvalidValueX & invalidValues)
|
||||
{
|
||||
if (m_text.isEmpty()) { invalidValues.insert("'blog_text' property cannot be empty"); }
|
||||
}
|
||||
20
test/qxBlogRestApi/src/category.cpp
Normal file
20
test/qxBlogRestApi/src/category.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#include "../include/precompiled.h"
|
||||
|
||||
#include "../include/category.h"
|
||||
#include "../include/blog.h"
|
||||
|
||||
#include <QxOrm_Impl.h>
|
||||
|
||||
QX_REGISTER_CPP_QX_BLOG(category)
|
||||
QX_PERSISTABLE_CPP(category)
|
||||
|
||||
namespace qx {
|
||||
template <> void register_class(QxClass<category> & t)
|
||||
{
|
||||
t.id(& category::m_id, "category_id");
|
||||
|
||||
t.data(& category::m_name, "name");
|
||||
t.data(& category::m_desc, "description");
|
||||
|
||||
t.relationManyToMany(& category::m_blogX, "list_blog", "category_blog", "category_id", "blog_id");
|
||||
}}
|
||||
20
test/qxBlogRestApi/src/comment.cpp
Normal file
20
test/qxBlogRestApi/src/comment.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#include "../include/precompiled.h"
|
||||
|
||||
#include "../include/comment.h"
|
||||
#include "../include/blog.h"
|
||||
|
||||
#include <QxOrm_Impl.h>
|
||||
|
||||
QX_REGISTER_CPP_QX_BLOG(comment)
|
||||
QX_PERSISTABLE_CPP(comment)
|
||||
|
||||
namespace qx {
|
||||
template <> void register_class(QxClass<comment> & t)
|
||||
{
|
||||
t.id(& comment::m_id, "comment_id");
|
||||
|
||||
t.data(& comment::m_text, "comment_text");
|
||||
t.data(& comment::m_dt_create, "date_creation");
|
||||
|
||||
t.relationManyToOne(& comment::m_blog, "blog_id");
|
||||
}}
|
||||
490
test/qxBlogRestApi/src/main.cpp
Normal file
490
test/qxBlogRestApi/src/main.cpp
Normal file
@@ -0,0 +1,490 @@
|
||||
#include "../include/precompiled.h"
|
||||
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
|
||||
#include <QtWidgets/qapplication.h>
|
||||
#include <QtWidgets/qtableview.h>
|
||||
#include <QtQuick/qquickview.h>
|
||||
#include <QtQml/qqmlcontext.h>
|
||||
#else // (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
|
||||
#include <QtGui/qapplication.h>
|
||||
#include <QtGui/qtableview.h>
|
||||
#include <QtDeclarative/qdeclarativeview.h>
|
||||
#include <QtDeclarative/qdeclarativecontext.h>
|
||||
#endif // (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
|
||||
|
||||
#include <QtGui/qdesktopservices.h>
|
||||
|
||||
#include "../include/blog.h"
|
||||
#include "../include/author.h"
|
||||
#include "../include/comment.h"
|
||||
#include "../include/category.h"
|
||||
|
||||
#include <QxOrm_Impl.h>
|
||||
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
// Qt application
|
||||
QApplication app(argc, argv);
|
||||
QFile::remove("./qxBlogRestApi.sqlite");
|
||||
|
||||
// Parameters to connect to database
|
||||
qx::QxSqlDatabase::getSingleton()->setDriverName("QSQLITE");
|
||||
qx::QxSqlDatabase::getSingleton()->setDatabaseName("./qxBlogRestApi.sqlite");
|
||||
qx::QxSqlDatabase::getSingleton()->setHostName("localhost");
|
||||
qx::QxSqlDatabase::getSingleton()->setUserName("root");
|
||||
qx::QxSqlDatabase::getSingleton()->setPassword("");
|
||||
qx::QxSqlDatabase::getSingleton()->setFormatSqlQueryBeforeLogging(true);
|
||||
|
||||
// Only for debug purpose : assert if invalid offset detected fetching a relation
|
||||
qx::QxSqlDatabase::getSingleton()->setVerifyOffsetRelation(true);
|
||||
|
||||
// Create all tables in database
|
||||
QSqlError daoError = qx::dao::create_table<author>();
|
||||
daoError = qx::dao::create_table<comment>();
|
||||
daoError = qx::dao::create_table<category>();
|
||||
daoError = qx::dao::create_table<blog>();
|
||||
|
||||
// Create a list of 3 author
|
||||
author_ptr author_1; author_1.reset(new author());
|
||||
author_ptr author_2; author_2.reset(new author());
|
||||
author_ptr author_3; author_3.reset(new author());
|
||||
|
||||
author_1->m_id = "author_id_1"; author_1->m_name = "author_1";
|
||||
author_1->m_sex = author::male; author_1->m_birthdate = QDate::currentDate();
|
||||
author_2->m_id = "author_id_2"; author_2->m_name = "author_2";
|
||||
author_2->m_sex = author::female; author_2->m_birthdate = QDate::currentDate();
|
||||
author_3->m_id = "author_id_3"; author_3->m_name = "author_3";
|
||||
author_3->m_sex = author::female; author_3->m_birthdate = QDate::currentDate();
|
||||
|
||||
list_author authorX;
|
||||
authorX.insert(author_1->m_id, author_1);
|
||||
authorX.insert(author_2->m_id, author_2);
|
||||
authorX.insert(author_3->m_id, author_3);
|
||||
|
||||
// Insert list of 3 author into database
|
||||
daoError = qx::dao::insert(authorX);
|
||||
qAssert(qx::dao::count<author>() == 3);
|
||||
|
||||
// Clone author 2 : 'author_id_2'
|
||||
author_ptr author_clone = qx::clone(* author_2);
|
||||
qAssert(author_clone->m_id == "author_id_2");
|
||||
qAssert(author_clone->m_sex == author::female);
|
||||
|
||||
// Create a query to fetch only female author : 'author_id_2' and 'author_id_3'
|
||||
qx::QxSqlQuery query("WHERE author.sex = :sex");
|
||||
query.bind(":sex", author::female);
|
||||
|
||||
list_author list_of_female_author;
|
||||
daoError = qx::dao::fetch_by_query(query, list_of_female_author);
|
||||
qAssert(list_of_female_author.count() == 2);
|
||||
|
||||
// Dump list of female author (xml serialization)
|
||||
qx::dump(list_of_female_author, false);
|
||||
qx::dump(list_of_female_author, true);
|
||||
|
||||
// Create 3 categories
|
||||
category_ptr category_1 = category_ptr(new category());
|
||||
category_ptr category_2 = category_ptr(new category());
|
||||
category_ptr category_3 = category_ptr(new category());
|
||||
|
||||
category_1->m_name = "category_1"; category_1->m_desc = "desc_1";
|
||||
category_2->m_name = "category_2"; category_2->m_desc = "desc_2";
|
||||
category_3->m_name = "category_3"; category_3->m_desc = "desc_3";
|
||||
|
||||
{ // Create a scope to destroy temporary connexion to database
|
||||
|
||||
// Open a transaction to database
|
||||
QSqlDatabase db = qx::QxSqlDatabase::getDatabase();
|
||||
bool bCommit = db.transaction();
|
||||
|
||||
// Insert 3 categories into database, use 'db' parameter for the transaction
|
||||
daoError = qx::dao::insert(category_1, (& db)); bCommit = (bCommit && ! daoError.isValid());
|
||||
daoError = qx::dao::insert(category_2, (& db)); bCommit = (bCommit && ! daoError.isValid());
|
||||
daoError = qx::dao::insert(category_3, (& db)); bCommit = (bCommit && ! daoError.isValid());
|
||||
|
||||
qAssert(bCommit);
|
||||
qAssert(category_1->m_id != 0);
|
||||
qAssert(category_2->m_id != 0);
|
||||
qAssert(category_3->m_id != 0);
|
||||
|
||||
// Terminate transaction => commit or rollback if there is error
|
||||
if (bCommit) { db.commit(); }
|
||||
else { db.rollback(); }
|
||||
|
||||
} // End of scope : 'db' is destroyed
|
||||
|
||||
// Create a blog with the class name (factory)
|
||||
qx::any blog_any = qx::create("blog");
|
||||
blog_ptr blog_1;
|
||||
try { blog_1 = qx::any_cast<blog_ptr>(blog_any); }
|
||||
catch (...) { blog_1.reset(new blog()); }
|
||||
blog_1->m_text = "blog_text_1";
|
||||
blog_1->m_dt_creation = QDateTime::currentDateTime();
|
||||
blog_1->m_author = author_1;
|
||||
|
||||
// Insert 'blog_1' into database with 'save()' method
|
||||
daoError = qx::dao::save(blog_1);
|
||||
|
||||
// Modify 'blog_1' properties and save into database
|
||||
blog_1->m_text = "update blog_text_1";
|
||||
blog_1->m_author = author_2;
|
||||
daoError = qx::dao::save(blog_1);
|
||||
|
||||
// Add 2 comments to 'blog_1'
|
||||
comment_ptr comment_1; comment_1.reset(new comment());
|
||||
comment_ptr comment_2; comment_2.reset(new comment());
|
||||
|
||||
comment_1->m_text = "comment_1 text";
|
||||
comment_1->m_dt_create = QDateTime::currentDateTime();
|
||||
comment_1->m_blog = blog_1;
|
||||
comment_2->m_text = "comment_2 text";
|
||||
comment_2->m_dt_create = QDateTime::currentDateTime();
|
||||
comment_2->m_blog = blog_1;
|
||||
|
||||
daoError = qx::dao::insert(comment_1);
|
||||
daoError = qx::dao::insert(comment_2);
|
||||
qAssert(qx::dao::count<comment>() == 2);
|
||||
|
||||
// Add 2 categories to 'blog_1' => must insert into extra-table 'category_blog'
|
||||
blog_1->m_categoryX.insert(category_1->m_id, category_1);
|
||||
blog_1->m_categoryX.insert(category_3->m_id, category_3);
|
||||
daoError = qx::dao::save_with_relation("list_category", blog_1);
|
||||
|
||||
// Fetch blog into a new variable with all relation : 'author', 'comment' and 'category'
|
||||
blog_ptr blog_tmp; blog_tmp.reset(new blog());
|
||||
blog_tmp->m_id = blog_1->m_id;
|
||||
daoError = qx::dao::fetch_by_id_with_all_relation(blog_tmp);
|
||||
|
||||
qAssert(blog_tmp->m_commentX.count() == 2);
|
||||
qAssert(blog_tmp->m_categoryX.count() == 2);
|
||||
qAssert(blog_tmp->m_text == "update blog_text_1");
|
||||
qAssert(blog_tmp->m_author && blog_tmp->m_author->m_id == "author_id_2");
|
||||
|
||||
// Fetch blog into a new variable with many relations using "*->*->*->*" (4 levels of relationships)
|
||||
blog_tmp.reset(new blog());
|
||||
blog_tmp->m_id = blog_1->m_id;
|
||||
daoError = qx::dao::fetch_by_id_with_relation("*->*->*->*", blog_tmp);
|
||||
|
||||
qAssert(blog_tmp->m_commentX.count() == 2);
|
||||
qAssert(blog_tmp->m_categoryX.count() == 2);
|
||||
qAssert(blog_tmp->m_text == "update blog_text_1");
|
||||
qAssert(blog_tmp->m_author && blog_tmp->m_author->m_id == "author_id_2");
|
||||
|
||||
// Dump 'blog_tmp' result from database (xml serialization)
|
||||
qx::dump(blog_tmp, false);
|
||||
qx::dump(blog_tmp, true);
|
||||
|
||||
// Fetch relations defining columns to fetch with syntax { col_1, col_2, etc... }
|
||||
list_blog lstBlogComplexRelation;
|
||||
daoError = qx::dao::fetch_all_with_relation(QStringList() << "{ blog_text }" << "author_id { name, birthdate }" << "list_comment { comment_text } -> blog_id -> *", lstBlogComplexRelation);
|
||||
qx::dump(lstBlogComplexRelation);
|
||||
qAssert(lstBlogComplexRelation.size() > 0);
|
||||
qAssert(lstBlogComplexRelation[0]->m_text != ""); // Fetched
|
||||
qAssert(lstBlogComplexRelation[0]->m_dt_creation.isNull()); // Not fetched
|
||||
qAssert(lstBlogComplexRelation[0]->m_author->m_sex == author::unknown); // Not fetched
|
||||
qAssert(lstBlogComplexRelation[0]->m_author->m_name != ""); // Fetched
|
||||
qAssert(lstBlogComplexRelation[0]->m_commentX.size() > 0);
|
||||
qAssert(lstBlogComplexRelation[0]->m_commentX[0]->m_dt_create.isNull()); // Not fetched
|
||||
qAssert(lstBlogComplexRelation[0]->m_commentX[0]->m_text != ""); // Fetched
|
||||
qAssert(lstBlogComplexRelation[0]->m_commentX[0]->m_blog);
|
||||
|
||||
// Fetch relations defining columns to remove before fetching with syntax -{ col_1, col_2, etc... }
|
||||
list_blog lstBlogComplexRelation2;
|
||||
daoError = qx::dao::fetch_all_with_relation(QStringList() << "-{ blog_text }" << "author_id -{ name, birthdate }" << "list_comment -{ comment_text } -> blog_id -> *", lstBlogComplexRelation2);
|
||||
qx::dump(lstBlogComplexRelation2);
|
||||
qAssert(lstBlogComplexRelation2.size() > 0);
|
||||
qAssert(lstBlogComplexRelation2[0]->m_text == ""); // Not fetched
|
||||
qAssert(! lstBlogComplexRelation2[0]->m_dt_creation.isNull()); // Fetched
|
||||
qAssert(lstBlogComplexRelation2[0]->m_author->m_sex != author::unknown); // Fetched
|
||||
qAssert(lstBlogComplexRelation2[0]->m_author->m_name == ""); // Not fetched
|
||||
qAssert(lstBlogComplexRelation2[0]->m_commentX.size() > 0);
|
||||
qAssert(! lstBlogComplexRelation2[0]->m_commentX[0]->m_dt_create.isNull()); // Fetched
|
||||
qAssert(lstBlogComplexRelation2[0]->m_commentX[0]->m_text == ""); // Not fetched
|
||||
qAssert(lstBlogComplexRelation2[0]->m_commentX[0]->m_blog);
|
||||
|
||||
#ifndef _QX_NO_JSON
|
||||
// Custom JSON serialization process
|
||||
QString customJsonFull = qx::serialization::json::to_string(blog_tmp, 1);
|
||||
QString customJsonFiltered = qx::serialization::json::to_string(blog_tmp, 1, "filter: { blog_text } | author_id { name, birthdate } | list_comment { comment_text } -> blog_id -> *");
|
||||
qDebug("[QxOrm] custom JSON serialization process (full) : \n%s", qPrintable(customJsonFull));
|
||||
qDebug("[QxOrm] custom JSON serialization process (filtered) : \n%s", qPrintable(customJsonFiltered));
|
||||
|
||||
blog_ptr blogFromJsonFull; blogFromJsonFull.reset(new blog());
|
||||
blog_ptr blogFromJsonFiltered; blogFromJsonFiltered.reset(new blog());
|
||||
qx::serialization::json::from_string(blogFromJsonFull, customJsonFull, 1);
|
||||
qx::serialization::json::from_string(blogFromJsonFiltered, customJsonFull, 1, "filter: { blog_text } | author_id { name, birthdate } | list_comment { comment_text } -> blog_id -> *");
|
||||
|
||||
qx::dump(blogFromJsonFull);
|
||||
qAssert(blogFromJsonFull->m_commentX.count() == 2);
|
||||
qAssert(blogFromJsonFull->m_categoryX.count() == 2);
|
||||
qAssert(blogFromJsonFull->m_text == "update blog_text_1");
|
||||
qAssert(blogFromJsonFull->m_author && blogFromJsonFull->m_author->m_id == "author_id_2");
|
||||
|
||||
qx::dump(blogFromJsonFiltered);
|
||||
qAssert(blogFromJsonFiltered->m_text != ""); // Fetched
|
||||
qAssert(blogFromJsonFiltered->m_dt_creation.isNull()); // Not fetched
|
||||
qAssert(blogFromJsonFiltered->m_author->m_sex == author::unknown); // Not fetched
|
||||
qAssert(blogFromJsonFiltered->m_author->m_name != ""); // Fetched
|
||||
qAssert(blogFromJsonFiltered->m_commentX.size() > 0);
|
||||
qAssert(blogFromJsonFiltered->m_commentX[0]->m_dt_create.isNull()); // Not fetched
|
||||
qAssert(blogFromJsonFiltered->m_commentX[0]->m_text != ""); // Fetched
|
||||
qAssert(blogFromJsonFiltered->m_commentX[0]->m_blog);
|
||||
#endif // _QX_NO_JSON
|
||||
|
||||
// Fetch relations defining columns to fetch with syntax { col_1, col_2, etc... } + custom table alias using syntax <my_table_alias> + custom table alias suffix using syntax <..._my_alias_suffix>
|
||||
list_blog lstBlogComplexRelation3;
|
||||
daoError = qx::dao::fetch_all_with_relation(QStringList() << "<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>", lstBlogComplexRelation3);
|
||||
qx::dump(lstBlogComplexRelation3);
|
||||
qAssert(lstBlogComplexRelation3.size() > 0);
|
||||
qAssert(lstBlogComplexRelation3[0]->m_text != ""); // Fetched
|
||||
qAssert(lstBlogComplexRelation3[0]->m_dt_creation.isNull()); // Not fetched
|
||||
qAssert(lstBlogComplexRelation3[0]->m_author->m_sex == author::unknown); // Not fetched
|
||||
qAssert(lstBlogComplexRelation3[0]->m_author->m_name != ""); // Fetched
|
||||
qAssert(lstBlogComplexRelation3[0]->m_commentX.size() > 0);
|
||||
qAssert(lstBlogComplexRelation3[0]->m_commentX[0]->m_dt_create.isNull()); // Not fetched
|
||||
qAssert(lstBlogComplexRelation3[0]->m_commentX[0]->m_text != ""); // Fetched
|
||||
qAssert(lstBlogComplexRelation3[0]->m_commentX[0]->m_blog);
|
||||
|
||||
// Check qx::dao::save_with_relation_recursive() function
|
||||
daoError = qx::dao::save_with_relation_recursive(blog_tmp);
|
||||
qAssert(! daoError.isValid());
|
||||
daoError = qx::dao::save_with_relation_recursive(blog_tmp, qx::dao::save_mode::e_update_only);
|
||||
qAssert(! daoError.isValid());
|
||||
|
||||
// Call 'age()' method with class name and method name (reflexion)
|
||||
qx_bool bInvokeOk = qx::QxClassX::invoke("author", "age", author_1);
|
||||
qAssert(bInvokeOk);
|
||||
|
||||
// Check count with relations and filter
|
||||
long lBlogCountWithRelation = 0; qx_query queryBlogCountWithRelation;
|
||||
daoError = qx::dao::count_with_relation<blog>(lBlogCountWithRelation, QStringList() << "author_id" << "list_comment -> blog_id -> *", queryBlogCountWithRelation);
|
||||
qAssert(! daoError.isValid() && (lBlogCountWithRelation > 0));
|
||||
|
||||
// Test 'isDirty()' method
|
||||
qx::dao::ptr<blog> blog_isdirty = qx::dao::ptr<blog>(new blog());
|
||||
blog_isdirty->m_id = blog_1->m_id;
|
||||
daoError = qx::dao::fetch_by_id(blog_isdirty);
|
||||
qAssert(! daoError.isValid() && ! blog_isdirty.isDirty());
|
||||
|
||||
blog_isdirty->m_text = "blog property 'text' modified => blog is dirty !!!";
|
||||
QStringList lstDiff; bool bDirty = blog_isdirty.isDirty(lstDiff);
|
||||
qAssert(bDirty && (lstDiff.count() == 1) && (lstDiff.at(0) == "blog_text"));
|
||||
if (bDirty) { qDebug("[QxOrm] test dirty 1 : blog is dirty => '%s'", qPrintable(lstDiff.join("|"))); }
|
||||
|
||||
// Update only property 'm_text' of 'blog_isdirty'
|
||||
daoError = qx::dao::update_optimized(blog_isdirty);
|
||||
qAssert(! daoError.isValid() && ! blog_isdirty.isDirty());
|
||||
qx::dump(blog_isdirty, false);
|
||||
qx::dump(blog_isdirty, true);
|
||||
|
||||
// Test 'isDirty()' method with a container
|
||||
typedef qx::dao::ptr< QList<author_ptr> > type_lst_author_test_is_dirty;
|
||||
type_lst_author_test_is_dirty container_isdirty = type_lst_author_test_is_dirty(new QList<author_ptr>());
|
||||
daoError = qx::dao::fetch_all(container_isdirty);
|
||||
qAssert(! daoError.isValid() && ! container_isdirty.isDirty() && (container_isdirty->count() == 3));
|
||||
|
||||
author_ptr author_ptr_dirty = container_isdirty->at(1);
|
||||
author_ptr_dirty->m_name = "author name modified at index 1 => container is dirty !!!";
|
||||
bDirty = container_isdirty.isDirty(lstDiff);
|
||||
qAssert(bDirty && (lstDiff.count() == 1));
|
||||
if (bDirty) { qDebug("[QxOrm] test dirty 2 : container is dirty => '%s'", qPrintable(lstDiff.join("|"))); }
|
||||
|
||||
author_ptr_dirty = container_isdirty->at(2);
|
||||
author_ptr_dirty->m_birthdate = QDate(1998, 03, 06);
|
||||
bDirty = container_isdirty.isDirty(lstDiff);
|
||||
qAssert(bDirty && (lstDiff.count() == 2));
|
||||
if (bDirty) { qDebug("[QxOrm] test dirty 3 : container is dirty => '%s'", qPrintable(lstDiff.join("|"))); }
|
||||
|
||||
// Update only property 'm_name' at position 1, only property 'm_birthdate' at position 2 and nothing at position 0
|
||||
daoError = qx::dao::update_optimized(container_isdirty);
|
||||
qAssert(! daoError.isValid() && ! container_isdirty.isDirty());
|
||||
qx::dump(container_isdirty, false);
|
||||
qx::dump(container_isdirty, true);
|
||||
|
||||
// Fetch only property 'm_dt_creation' of blog
|
||||
QStringList lstColumns = QStringList() << "date_creation";
|
||||
list_blog lst_blog_with_only_date_creation;
|
||||
daoError = qx::dao::fetch_all(lst_blog_with_only_date_creation, NULL, lstColumns);
|
||||
qAssert(! daoError.isValid() && (lst_blog_with_only_date_creation.size() > 0));
|
||||
if ((lst_blog_with_only_date_creation.size() > 0) && (lst_blog_with_only_date_creation[0].get() != NULL))
|
||||
{ qAssert(lst_blog_with_only_date_creation[0]->m_text.isEmpty()); }
|
||||
qx::dump(lst_blog_with_only_date_creation, false);
|
||||
qx::dump(lst_blog_with_only_date_creation, true);
|
||||
|
||||
// Dump all registered classes into QxOrm context (introspection engine)
|
||||
qx::QxClassX::dumpAllClasses();
|
||||
|
||||
// Call a custom SQL query or a stored procedure
|
||||
qx_query testStoredProc("SELECT * FROM author");
|
||||
daoError = qx::dao::call_query(testStoredProc);
|
||||
qAssert(! daoError.isValid());
|
||||
testStoredProc.dumpSqlResult();
|
||||
|
||||
// Call a custom SQL query or a stored procedure and fetch automatically properties (with a collection of items)
|
||||
qx_query testStoredProcBis("SELECT * FROM author");
|
||||
authorX.clear();
|
||||
daoError = qx::dao::execute_query(testStoredProcBis, authorX);
|
||||
qAssert(! daoError.isValid()); qAssert(authorX.count() > 0);
|
||||
qx::dump(authorX, false);
|
||||
qx::dump(authorX, true);
|
||||
|
||||
// Call a custom SQL query or a stored procedure and fetch automatically properties
|
||||
qx_query testStoredProcThird("SELECT name, category_id FROM category");
|
||||
category_ptr category_tmp = category_ptr(new category());
|
||||
daoError = qx::dao::execute_query(testStoredProcThird, category_tmp);
|
||||
qAssert(! daoError.isValid()); qAssert(category_tmp->m_id != 0);
|
||||
qx::dump(category_tmp, false);
|
||||
qx::dump(category_tmp, true);
|
||||
|
||||
// Create several blogs
|
||||
blog_tmp.reset(new blog());
|
||||
blog_tmp->m_id = blog_1->m_id;
|
||||
daoError = qx::dao::fetch_by_id_with_relation("*", blog_tmp);
|
||||
blog_ptr blog_cloned = qx::clone(* blog_tmp);
|
||||
daoError = qx::dao::save_with_relation_recursive(blog_cloned, qx::dao::save_mode::e_insert_only); qAssert(! daoError.isValid());
|
||||
blog_cloned = qx::clone(* blog_tmp);
|
||||
daoError = qx::dao::save_with_relation_recursive(blog_cloned, qx::dao::save_mode::e_insert_only); qAssert(! daoError.isValid());
|
||||
blog_cloned = qx::clone(* blog_tmp);
|
||||
daoError = qx::dao::save_with_relation_recursive(blog_cloned, qx::dao::save_mode::e_insert_only); qAssert(! daoError.isValid());
|
||||
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
|
||||
|
||||
{
|
||||
qx::QxRestApi api;
|
||||
|
||||
QQuickView qmlView;
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
||||
QString sQmlFile = "qrc:/documents/test_rest_api_qt6.qml";
|
||||
#else // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
||||
QString sQmlFile = "qrc:/documents/test_rest_api.qml";
|
||||
#endif // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
||||
|
||||
qmlView.rootContext()->setContextProperty("qxRestApi", (& api));
|
||||
qmlView.setResizeMode(QQuickView::SizeRootObjectToView);
|
||||
qmlView.setSource(QUrl(sQmlFile));
|
||||
qmlView.show();
|
||||
qApp->exec();
|
||||
}
|
||||
|
||||
#ifdef _QX_ENABLE_QT_NETWORK
|
||||
|
||||
{
|
||||
// Just to be sure to have static files on the system
|
||||
QDir appPath(QDir::currentPath()); appPath.mkdir("files");
|
||||
QFile::copy(":/documents/test_http_server.html", appPath.filePath("files/test_http_server.html"));
|
||||
QFile::copy(":/documents/logo_qxorm_and_qxee.png", appPath.filePath("files/logo_qxorm_and_qxee.png"));
|
||||
QFile::copy(":/documents/jquery.js", appPath.filePath("files/jquery.js"));
|
||||
|
||||
// HTTP server settings
|
||||
qx::service::QxConnect * serverSettings = qx::service::QxConnect::getSingleton();
|
||||
serverSettings->setKeepAlive(5000);
|
||||
serverSettings->setCompressData(true);
|
||||
serverSettings->setThreadCount(50);
|
||||
serverSettings->setPort(9642);
|
||||
|
||||
#ifndef QT_NO_SSL
|
||||
if (false) // If you want to test SSL/TLS secured connection, just force this condition to 'true'
|
||||
{
|
||||
// Certificates created with this tutorial : https://deliciousbrains.com/ssl-certificate-authority-for-local-https-development/
|
||||
QFile::copy(":/documents/cert_qxorm_ca.pem", appPath.filePath("files/cert_qxorm_ca.pem"));
|
||||
QFile::copy(":/documents/cert_qxorm_server.crt", appPath.filePath("files/cert_qxorm_server.crt"));
|
||||
QFile::copy(":/documents/cert_qxorm_server.key", appPath.filePath("files/cert_qxorm_server.key"));
|
||||
|
||||
QFile fileCertCA(appPath.filePath("files/cert_qxorm_ca.pem"));
|
||||
fileCertCA.open(QIODevice::ReadOnly);
|
||||
QList<QSslCertificate> certCA; certCA << QSslCertificate(fileCertCA.readAll());
|
||||
|
||||
QFile fileCertServerPublic(appPath.filePath("files/cert_qxorm_server.crt"));
|
||||
fileCertServerPublic.open(QIODevice::ReadOnly);
|
||||
QSslCertificate certServerPublic(fileCertServerPublic.readAll());
|
||||
|
||||
QFile fileCertServerPrivate(appPath.filePath("files/cert_qxorm_server.key"));
|
||||
fileCertServerPrivate.open(QIODevice::ReadOnly);
|
||||
QSslKey certServerPrivate(fileCertServerPrivate.readAll(), QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey, "qxorm");
|
||||
|
||||
serverSettings->setSSLEnabled(true);
|
||||
serverSettings->setSSLCACertificates(certCA);
|
||||
serverSettings->setSSLLocalCertificate(certServerPublic);
|
||||
serverSettings->setSSLPrivateKey(certServerPrivate);
|
||||
}
|
||||
#endif // QT_NO_SSL
|
||||
|
||||
// Create a QxOrm HTTP server instance
|
||||
qx::QxHttpServer httpServer;
|
||||
|
||||
// Define all HTTP server routes (dispatcher) to handle requests
|
||||
// Each callback is executed in a dedicated thread, so QxOrm HTTP server can handle several requests in parallel
|
||||
httpServer.dispatch("GET", "/files/*", [](qx::QxHttpRequest & request, qx::QxHttpResponse & response) {
|
||||
qx::QxHttpServer::buildResponseStaticFile(request, response, QDir::currentPath(), 5000);
|
||||
});
|
||||
httpServer.dispatch("POST", "/qx", [](qx::QxHttpRequest & request, qx::QxHttpResponse & response) {
|
||||
qx::QxHttpServer::buildResponseQxRestApi(request, response);
|
||||
|
||||
// Not useful here but this is how to get a server session per user
|
||||
// If this is the first time to access to session, then a cookie is created automatically and attached to the response
|
||||
// Then each request sent by web browser will contain a cookie with the session id
|
||||
// The session expires on server side after qx::service::QxConnect::setSessionTimeOut() milliseconds
|
||||
qx::QxHttpSession_ptr session = qx::QxHttpSessionManager::getSession(request, response);
|
||||
if (session) { session->set("last_request_per_user", QDateTime::currentDateTime()); }
|
||||
});
|
||||
httpServer.dispatch("GET", "/params/<var1>/<var2:int>", [](qx::QxHttpRequest & request, qx::QxHttpResponse & response) {
|
||||
response.data() = "Test URL dispatch parameters :\r\n";
|
||||
response.data() += " - var1 = " + request.dispatchParams().value("var1").toByteArray() + "\r\n";
|
||||
response.data() += " - var2 = " + request.dispatchParams().value("var2").toByteArray() + "\r\n";
|
||||
});
|
||||
httpServer.dispatch("GET", "/test_big_json", [](qx::QxHttpRequest & request, qx::QxHttpResponse & response) {
|
||||
// To compare with this benchmark : https://blog.binaryspaceship.com/2017/cpp-rest-api-frameworks-benchmark/
|
||||
// This is more a JSON benchmark than HTTP server benchmark (RapidJSON is faster than Qt QJson engine)
|
||||
QJsonArray arr; Q_UNUSED(request);
|
||||
for (int i = 0; i < 10000; ++i)
|
||||
{
|
||||
QJsonObject item;
|
||||
item.insert("id", QString::number(i));
|
||||
item.insert("name", QString("Hello World"));
|
||||
item.insert("type", QString("application"));
|
||||
arr.append(item);
|
||||
}
|
||||
QJsonDocument doc(arr);
|
||||
response.headers().insert("Content-Type", "application/json; charset=utf-8");
|
||||
response.data() = doc.toJson(QJsonDocument::Compact);
|
||||
});
|
||||
|
||||
// Start HTTP server
|
||||
httpServer.startServer();
|
||||
|
||||
// Open default web browser to connect to QxOrm HTTP server instance
|
||||
#ifndef QT_NO_SSL
|
||||
if (serverSettings->getSSLEnabled()) { QDesktopServices::openUrl(QUrl("https://localhost:9642/files/test_http_server.html")); }
|
||||
else { QDesktopServices::openUrl(QUrl("http://localhost:9642/files/test_http_server.html")); }
|
||||
#else // QT_NO_SSL
|
||||
QDesktopServices::openUrl(QUrl("http://localhost:9642/files/test_http_server.html"));
|
||||
#endif // QT_NO_SSL
|
||||
|
||||
QQuickView qmlView;
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
||||
QString sQmlFile = "qrc:/documents/test_http_server_qt6.qml";
|
||||
#else // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
||||
QString sQmlFile = "qrc:/documents/test_http_server.qml";
|
||||
#endif // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
||||
|
||||
qmlView.rootContext()->setContextProperty("qxHttpServer", (& httpServer));
|
||||
qmlView.setResizeMode(QQuickView::SizeRootObjectToView);
|
||||
qmlView.setSource(QUrl(sQmlFile));
|
||||
qmlView.show();
|
||||
qApp->exec();
|
||||
}
|
||||
|
||||
#else // _QX_ENABLE_QT_NETWORK
|
||||
|
||||
qDebug("[QxOrm] qxBlogRestApi example project : %s", "cannot start QxOrm HTTP server because _QX_ENABLE_QT_NETWORK compilation option is not defined");
|
||||
|
||||
#endif // _QX_ENABLE_QT_NETWORK
|
||||
|
||||
#else // (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
|
||||
|
||||
qDebug("[QxOrm] %s", "qxBlogRestApi example project only works with Qt5 or +");
|
||||
|
||||
#endif // (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user