Compare commits

..

No commits in common. "67b60276ae15bec964eb3b2515d13cdb57ae5fc0" and "a50f9ab69a80319c44fe7c537a9b03dab3ec999f" have entirely different histories.

4 changed files with 0 additions and 83 deletions

View File

@ -1,5 +0,0 @@
{
"version": "1",
"name": "CostaPy",
"type": "collection"
}

View File

@ -1,69 +0,0 @@
import mysql.connector as mariadb
from bottle import request
from config import database
from scripts import loggorilla
class catalog:
def __init__(self):
self.db_main = mariadb.connect(**database.db_main)
self.cursor = self.db_main.cursor(dictionary=True)
def add(self, params):
APIADDR = "/api/highlight/catalog/add"
response = {}
loggorilla.prcss(APIADDR, "Define Models")
item = params["item" ]
category = params["category" ]
self.cursor.execute("BEGIN;")
try:
self.cursor.execute("SELECT COUNT(*) AS `count` FROM `highlight_catalog` WHERE `item` = %s AND `category` = %s ; ", (item, category) )
exist = self.cursor.fetchone()
loggorilla.prcss(APIADDR, "Validation")
if exist["count"] > 0:
loggorilla.prcss(APIADDR, "Set Response")
response["status" ] = "failed"
response["desc" ] = "Your data already exist"
else:
loggorilla.prcss(APIADDR, "Activity: Insert")
self.cursor.execute("INSERT INTO `highlight_catalog` VALUES ( DEFAULT, %s, %s ) ; ", (item, category) )
loggorilla.prcss(APIADDR, "Set Response")
response["status" ] = "success"
response["desc" ] = "Data Added"
except Exception as e:
self.cursor.execute("ROLLBACK;")
loggorilla.error(APIADDR, str(e) )
loggorilla.prcss(APIADDR, "Set Response")
response["status" ] = "failed"
response["desc" ] = "Internal Server Error. Please contact us if you still have an error."
finally:
self.cursor.execute("COMMIT;")
self.cursor.close()
self.db_main.close()
return response
def remove(self, params):
APIADDR = "/api/highlight/catalog/remove"
response = {}
loggorilla.prcss(APIADDR, "Define Models")
item = params["item" ]
category = params["category" ]
self.cursor.execute("BEGIN;")
try:
loggorilla.prcss(APIADDR, "Activity: Remove")
self.cursor.execute("DELETE FROM `highlight_catalog` WHERE `item` = %s AND `category` = %s ; ", (item, category) )
loggorilla.prcss(APIADDR, "Set Response")
response["status" ] = "success"
response["desc" ] = "data removed"
except Exception as e:
self.cursor.execute("ROLLBACK;")
loggorilla.error(APIADDR, str(e) )
loggorilla.prcss(APIADDR, "Set Response")
response["status" ] = "failed"
response["desc" ] = "Internal Server Error. Please contact us if you still have an error."
finally:
self.cursor.execute("COMMIT;")
self.cursor.close()
self.db_main.close()
return response

View File

@ -11,15 +11,6 @@ create table if not exists `catalog_item` (
name varchar(36) not null
) engine=InnoDB default charset=utf8mb4;
insert into `catalog_item` values
(default, 'Item A'),
(default, 'Item B'),
(default, 'Item C'),
(default, 'Item D'),
(default, 'Item E'),
(default, 'Item F'),
(default, 'Item G');
-- Main table
create table if not exists `highlight_category` (