Compare commits
5 Commits
a50f9ab69a
...
67b60276ae
Author | SHA1 | Date | |
---|---|---|---|
67b60276ae | |||
51afa10505 | |||
bb455cf9b7 | |||
1b7addaefb | |||
b66e5aa9cc |
5
bruno/bruno.json
Normal file
5
bruno/bruno.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"version": "1",
|
||||
"name": "CostaPy",
|
||||
"type": "collection"
|
||||
}
|
69
modules/api/highlight/catalog.py
Normal file
69
modules/api/highlight/catalog.py
Normal file
@ -0,0 +1,69 @@
|
||||
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
|
@ -11,6 +11,15 @@ 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` (
|
||||
|
Loading…
Reference in New Issue
Block a user