Initial Comit
This commit is contained in:
43
DPMMobileB4X/test/MyWebApi/Objects/config.ini
Normal file
43
DPMMobileB4X/test/MyWebApi/Objects/config.ini
Normal file
@@ -0,0 +1,43 @@
|
||||
# Product: Web API (server)
|
||||
# Version: 1.08
|
||||
# Developer: Aeric Poon
|
||||
# License: Open Source
|
||||
# Thanks to Erel, Anywhere Software for the great products and B4X community for encouragement and supports ;)
|
||||
# Lines starting with '#' are comments.
|
||||
# Backslash character at the end of line means that the command continues in the next line.
|
||||
|
||||
# Server Path
|
||||
ROOT_PATH=/v1/
|
||||
ROOT_URL=http://127.0.0.1
|
||||
|
||||
# Java server port
|
||||
ServerPort=19800
|
||||
SSLPort=0
|
||||
|
||||
# SSL Keystores
|
||||
SSL_KEYSTORE_DIR=/etc/letsencrypt/live/mydomain.com
|
||||
SSL_KEYSTORE_FILE=keystore.jks
|
||||
SSL_KEYSTORE_PASSWORD=xxxxxx
|
||||
|
||||
# Define App Constants
|
||||
HOME_TITLE=WEB API
|
||||
APP_TITLE=Web API
|
||||
APP_TRADEMARK=B4X
|
||||
APP_COPYRIGHT=Copyright B4X 2021
|
||||
|
||||
# DATABASE CONFIGURATION
|
||||
|
||||
# SQLite
|
||||
DbName=webapi.db
|
||||
DbType=sqlite
|
||||
DriverClass=com.sqlite.JdbcUrl
|
||||
JdbcUrl=jdbc:sqlite:webapi.db
|
||||
|
||||
# MySQL
|
||||
# DbName=webapi
|
||||
# DbType=mysql
|
||||
# DriverClass=com.mysql.jdbc.Driver
|
||||
# JdbcUrl=jdbc:mysql://localhost/webapi?characterEncoding=utf8&useSSL=false
|
||||
# User=root
|
||||
# Password=password
|
||||
# MaxPoolSize=100
|
||||
78
DPMMobileB4X/test/MyWebApi/Objects/queries-mysql.ini
Normal file
78
DPMMobileB4X/test/MyWebApi/Objects/queries-mysql.ini
Normal file
@@ -0,0 +1,78 @@
|
||||
# Product: SQL commands for Web API (for MySQL Backend)
|
||||
# Version: 1.08
|
||||
# Lines starting with '#' are comments.
|
||||
# Backslash character at the end of line means that the command continues in the next line.
|
||||
|
||||
# Check and create database
|
||||
CHECK_DATABASE=SELECT * FROM SCHEMATA WHERE SCHEMA_NAME = ?
|
||||
|
||||
CREATE_DATABASE=CREATE DATABASE {DBNAME} CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci
|
||||
|
||||
USE_DATABASE=USE {DBNAME}
|
||||
|
||||
# DROP_TABLE_IF_EXIST_TBL_CATEGORY=DROP TABLE IF EXISTS `tbl_category`
|
||||
|
||||
CREATE_TABLE_TBL_CATEGORY=CREATE TABLE `tbl_category` ( \
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT, \
|
||||
`category_name` varchar(200) COLLATE utf8mb4_unicode_ci DEFAULT NULL, \
|
||||
PRIMARY KEY (`id`) \
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
|
||||
|
||||
INSERT_DUMMY_TBL_CATEGORY=INSERT INTO `tbl_category` (`category_name`) VALUES \
|
||||
('Hardwares'), \
|
||||
('Toys')
|
||||
|
||||
# DROP_TABLE_IF_EXIST_TBL_PRODUCTS=DROP TABLE IF EXISTS `tbl_products`
|
||||
|
||||
CREATE_TABLE_TBL_PRODUCTS=CREATE TABLE `tbl_products` ( \
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT, \
|
||||
`category_id` int(11) NOT NULL, \
|
||||
`product_code` varchar(12) COLLATE utf8mb4_unicode_ci DEFAULT NULL, \
|
||||
`product_name` varchar(200) COLLATE utf8mb4_unicode_ci DEFAULT NULL, \
|
||||
`product_price` decimal(10,2) DEFAULT '0.00', \
|
||||
PRIMARY KEY (`id`), \
|
||||
KEY `category_id` (`category_id`), \
|
||||
CONSTRAINT `tbl_products_ibfk_1` FOREIGN KEY (`category_id`) REFERENCES `tbl_category` (`id`) \
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
|
||||
|
||||
INSERT_DUMMY_TBL_PRODUCTS=INSERT INTO `tbl_products` \
|
||||
(`category_id`, `product_code`, `product_name`, `product_price`) VALUES \
|
||||
(2, 'T001', 'Teddy Bear', 99.9), \
|
||||
(1, 'H001', 'Hammer', 15.75), \
|
||||
(2, 'T002', 'Optimus Prime', 1000.00)
|
||||
|
||||
# CATEGORY
|
||||
GET_ALL_CATEGORIES=SELECT * FROM `tbl_category`
|
||||
GET_CATEGORY_BY_ID=SELECT * FROM `tbl_category` WHERE `id` = ?
|
||||
ADD_NEW_CATEGORY=INSERT INTO `tbl_category` (`category_name`) SELECT ?
|
||||
EDIT_CATEGORY_BY_ID=UPDATE `tbl_category` SET `category_name` = ? WHERE `id` = ?
|
||||
REMOVE_CATEGORY_BY_ID=DELETE FROM `tbl_category` WHERE `id` = ?
|
||||
GET_ID_BY_CATEGORY_NAME=SELECT `id` FROM `tbl_category` WHERE `category_name` = ?
|
||||
|
||||
# PRODUCT
|
||||
GET_ALL_PRODUCTS_BY_CATEGORY=SELECT * FROM `tbl_products` \
|
||||
WHERE `category_id` = ?
|
||||
GET_PRODUCT_BY_CATEGORY_AND_ID=SELECT * FROM `tbl_products` \
|
||||
WHERE `category_id` = ? AND `id` = ?
|
||||
ADD_NEW_PRODUCT_BY_CATEGORY=INSERT INTO `tbl_products` \
|
||||
(`category_id`, `product_code`, `product_name`, `product_price`) SELECT ?, ?, ?, ?
|
||||
EDIT_PRODUCT_BY_CATEGORY_AND_ID=UPDATE `tbl_products` \
|
||||
SET `category_id` = ?, `product_code` = ?, `product_name` = ?, `product_price` = ? \
|
||||
WHERE `category_id` = ? AND `id` = ?
|
||||
REMOVE_PRODUCT_BY_CATEGORY_AND_ID=DELETE FROM `tbl_products` \
|
||||
WHERE `category_id` = ? AND `id` = ?
|
||||
GET_ID_BY_CATEGORY_ID_AND_PRODUCT_NAME=SELECT `id` FROM `tbl_products` \
|
||||
WHERE `category_id` = ? AND `product_name` = ?
|
||||
|
||||
# SEARCH
|
||||
SEARCH_PRODUCT_BY_CATEGORY_CODE_AND_NAME_ONEWORD_ORDERED=SELECT P.id AS aa, \
|
||||
P.product_code AS bb, C.`category_name` AS cc, P.product_name AS dd, P.product_price AS ee \
|
||||
FROM `tbl_products` P JOIN `tbl_category` C ON P.`category_id` = C.`id` \
|
||||
WHERE C.`category_name` LIKE ? OR P.`product_code` LIKE ? OR P.`product_name` LIKE ?
|
||||
SEARCH_PRODUCT_BY_CATEGORY_CODE_AND_NAME_TWOWORDS_ORDERED=SELECT P.id AS aa, \
|
||||
P.product_code AS bb, C.`category_name` AS cc, P.product_name AS dd, P.product_price AS ee \
|
||||
FROM `tbl_products` P JOIN `tbl_category` C ON P.`category_id` = C.`id` \
|
||||
WHERE C.`category_name` LIKE ? OR P.`product_code` LIKE ? OR P.`product_name` LIKE ? \
|
||||
OR C.`category_name` LIKE ? OR P.`product_code` LIKE ? OR P.`product_name` LIKE ?
|
||||
|
||||
GET_LAST_INSERT_ID=SELECT LAST_INSERT_ID()
|
||||
65
DPMMobileB4X/test/MyWebApi/Objects/queries-sqlite.ini
Normal file
65
DPMMobileB4X/test/MyWebApi/Objects/queries-sqlite.ini
Normal file
@@ -0,0 +1,65 @@
|
||||
# Product: SQL commands for Web API (for SQLite Backend)
|
||||
# Version: 1.08
|
||||
# Lines starting with '#' are comments.
|
||||
# Backslash character at the end of line means that the command continues in the next line.
|
||||
|
||||
# Create tables
|
||||
CREATE_TABLE_TBL_CATEGORY=CREATE TABLE IF NOT EXISTS `tbl_category` ( \
|
||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT, \
|
||||
`category_name` varchar(200) NULL \
|
||||
)
|
||||
|
||||
INSERT_DUMMY_TBL_CATEGORY=INSERT INTO `tbl_category` (`category_name`) VALUES \
|
||||
('Hardwares'), \
|
||||
('Toys')
|
||||
|
||||
CREATE_TABLE_TBL_PRODUCTS=CREATE TABLE IF NOT EXISTS `tbl_products` ( \
|
||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT, \
|
||||
`category_id` INTEGER NOT NULL, \
|
||||
`product_code` varchar(12) NULL, \
|
||||
`product_name` varchar(200) NULL, \
|
||||
`product_price` decimal(10,2) DEFAULT '0.00', \
|
||||
FOREIGN KEY (`category_id`) REFERENCES `tbl_category` (`id`) \
|
||||
)
|
||||
|
||||
INSERT_DUMMY_TBL_PRODUCTS=INSERT INTO `tbl_products` \
|
||||
(`category_id`, `product_code`, `product_name`, `product_price`) VALUES \
|
||||
(2, 'T001', 'Teddy Bear', 99.9), \
|
||||
(1, 'H001', 'Hammer', 15.75), \
|
||||
(2, 'T002', 'Optimus Prime', 1000.00)
|
||||
|
||||
# CATEGORY
|
||||
GET_ALL_CATEGORIES=SELECT * FROM `tbl_category`
|
||||
GET_CATEGORY_BY_ID=SELECT * FROM `tbl_category` WHERE `id` = ?
|
||||
ADD_NEW_CATEGORY=INSERT INTO `tbl_category` (`category_name`) SELECT ?
|
||||
EDIT_CATEGORY_BY_ID=UPDATE `tbl_category` SET `category_name` = ? WHERE `id` = ?
|
||||
REMOVE_CATEGORY_BY_ID=DELETE FROM `tbl_category` WHERE `id` = ?
|
||||
GET_ID_BY_CATEGORY_NAME=SELECT `id` FROM `tbl_category` WHERE `category_name` = ?
|
||||
|
||||
# PRODUCT
|
||||
GET_ALL_PRODUCTS_BY_CATEGORY=SELECT * FROM `tbl_products` \
|
||||
WHERE `category_id` = ?
|
||||
GET_PRODUCT_BY_CATEGORY_AND_ID=SELECT * FROM `tbl_products` \
|
||||
WHERE `category_id` = ? AND `id` = ?
|
||||
ADD_NEW_PRODUCT_BY_CATEGORY=INSERT INTO `tbl_products` \
|
||||
(`category_id`, `product_code`, `product_name`, `product_price`) SELECT ?, ?, ?, ?
|
||||
EDIT_PRODUCT_BY_CATEGORY_AND_ID=UPDATE `tbl_products` \
|
||||
SET `category_id` = ?, `product_code` = ?, `product_name` = ?, `product_price` = ? \
|
||||
WHERE `category_id` = ? AND `id` = ?
|
||||
REMOVE_PRODUCT_BY_CATEGORY_AND_ID=DELETE FROM `tbl_products` \
|
||||
WHERE `category_id` = ? AND `id` = ?
|
||||
GET_ID_BY_CATEGORY_ID_AND_PRODUCT_NAME=SELECT `id` FROM `tbl_products` \
|
||||
WHERE `category_id` = ? AND `product_name` = ?
|
||||
|
||||
# SEARCH
|
||||
SEARCH_PRODUCT_BY_CATEGORY_CODE_AND_NAME_ONEWORD_ORDERED=SELECT P.id AS aa, \
|
||||
P.product_code AS bb, C.`category_name` AS cc, P.product_name AS dd, P.product_price AS ee \
|
||||
FROM `tbl_products` P JOIN `tbl_category` C ON P.`category_id` = C.`id` \
|
||||
WHERE C.`category_name` LIKE ? OR P.`product_code` LIKE ? OR P.`product_name` LIKE ?
|
||||
SEARCH_PRODUCT_BY_CATEGORY_CODE_AND_NAME_TWOWORDS_ORDERED=SELECT P.id AS aa, \
|
||||
P.product_code AS bb, C.`category_name` AS cc, P.product_name AS dd, P.product_price AS ee \
|
||||
FROM `tbl_products` P JOIN `tbl_category` C ON P.`category_id` = C.`id` \
|
||||
WHERE C.`category_name` LIKE ? OR P.`product_code` LIKE ? OR P.`product_name` LIKE ? \
|
||||
OR C.`category_name` LIKE ? OR P.`product_code` LIKE ? OR P.`product_name` LIKE ?
|
||||
|
||||
GET_LAST_INSERT_ID=SELECT LAST_INSERT_ROWID()
|
||||
14
DPMMobileB4X/test/MyWebApi/Objects/start.bat
Normal file
14
DPMMobileB4X/test/MyWebApi/Objects/start.bat
Normal file
@@ -0,0 +1,14 @@
|
||||
REM ================================================================
|
||||
REM Run this batch file in Windows Command Prompt as Administrator
|
||||
REM ================================================================
|
||||
|
||||
@ECHO OFF
|
||||
TITLE Web API server is starting...
|
||||
|
||||
REM CD C:\Java\jdk-11.0.1\bin
|
||||
REM java --module-path C:\Java\jdk-11.0.1\javafx\lib --add-modules ALL-MODULE-PATH -jar "C:\Development\B4J\WebAPI\Objects\webapi.jar"
|
||||
|
||||
C:
|
||||
CD C:\Program Files\Java\jdk1.8.0_181\bin
|
||||
java -jar "C:\Development\B4J\WebAPI\Objects\webapi.jar"
|
||||
::PAUSE
|
||||
7
DPMMobileB4X/test/MyWebApi/Objects/www/assets/css/bootstrap.min.css
vendored
Normal file
7
DPMMobileB4X/test/MyWebApi/Objects/www/assets/css/bootstrap.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
5
DPMMobileB4X/test/MyWebApi/Objects/www/assets/css/fontawesome.min.css
vendored
Normal file
5
DPMMobileB4X/test/MyWebApi/Objects/www/assets/css/fontawesome.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
5
DPMMobileB4X/test/MyWebApi/Objects/www/assets/css/solid.min.css
vendored
Normal file
5
DPMMobileB4X/test/MyWebApi/Objects/www/assets/css/solid.min.css
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
/*!
|
||||
* Font Awesome Free 5.8.1 by @fontawesome - https://fontawesome.com
|
||||
* License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License)
|
||||
*/
|
||||
@font-face{font-family:"Font Awesome 5 Free";font-style:normal;font-weight:900;font-display:auto;src:url(../webfonts/fa-solid-900.eot);src:url(../webfonts/fa-solid-900.eot?#iefix) format("embedded-opentype"),url(../webfonts/fa-solid-900.woff2) format("woff2"),url(../webfonts/fa-solid-900.woff) format("woff"),url(../webfonts/fa-solid-900.ttf) format("truetype"),url(../webfonts/fa-solid-900.svg#fontawesome) format("svg")}.fa,.fas{font-family:"Font Awesome 5 Free";font-weight:900}
|
||||
BIN
DPMMobileB4X/test/MyWebApi/Objects/www/assets/img/favicon.png
Normal file
BIN
DPMMobileB4X/test/MyWebApi/Objects/www/assets/img/favicon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 865 B |
7
DPMMobileB4X/test/MyWebApi/Objects/www/assets/js/bootstrap.bundle.min.js
vendored
Normal file
7
DPMMobileB4X/test/MyWebApi/Objects/www/assets/js/bootstrap.bundle.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
2
DPMMobileB4X/test/MyWebApi/Objects/www/assets/js/jquery.min.js
vendored
Normal file
2
DPMMobileB4X/test/MyWebApi/Objects/www/assets/js/jquery.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@@ -0,0 +1,50 @@
|
||||
$( document ).ready(function() {
|
||||
$("#btnsearch").click(function(e) {
|
||||
e.preventDefault();
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "/",
|
||||
data: $("form").serialize(),
|
||||
success: function(response)
|
||||
{
|
||||
if (response.s == "ok") {
|
||||
// console.log(response.r);
|
||||
var tbl_head = "";
|
||||
var tbl_body = "";
|
||||
if (response.r.length) {
|
||||
tbl_head = "<thead class=\"bg-light\"><th style=\"text-align: right\">#</th><th>Code</th><th>Category</th><th>Name</th><th style=\"text-align: right\">Price</th></thead>";
|
||||
tbl_body += "<tbody>";
|
||||
$.each(response.r, function() {
|
||||
var tbl_row = "";
|
||||
$.each(this, function(key, value) {
|
||||
if (key == "ee" || key == "aa")
|
||||
{
|
||||
tbl_row += "<td style=\"text-align: right\">"+value+"</td>";
|
||||
}
|
||||
else
|
||||
{
|
||||
tbl_row += "<td>"+value+"</td>";
|
||||
}
|
||||
});
|
||||
tbl_body += "<tr>"+tbl_row+"</tr>";
|
||||
});
|
||||
tbl_body += "</tbody>";
|
||||
}
|
||||
else
|
||||
{
|
||||
tbl_body = "<tr><td>No results</td></tr>";
|
||||
}
|
||||
$("#results table").html(tbl_head+tbl_body);
|
||||
}
|
||||
else {
|
||||
$(".alert").html(response.e);
|
||||
$(".alert").fadeIn();
|
||||
}
|
||||
},
|
||||
error: function (xhr, ajaxOptions, thrownError) {
|
||||
$(".alert").html(thrownError);
|
||||
$(".alert").fadeIn();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user