Compare commits
2 Commits
master
...
system/met
| Author | SHA1 | Date | |
|---|---|---|---|
| 96456c485b | |||
| 6328c35c93 |
64
modules/api/metaprofile/metaprofile.py
Normal file
64
modules/api/metaprofile/metaprofile.py
Normal file
@ -0,0 +1,64 @@
|
||||
import mysql.connector as mariadb
|
||||
|
||||
from config import database
|
||||
from scripts import loggorilla
|
||||
|
||||
import datetime
|
||||
|
||||
class metaprofile:
|
||||
|
||||
def __init__(self):
|
||||
self.db_main = mariadb.connect(**database.db_main)
|
||||
self.cursor = self.db_main.cursor(dictionary=True)
|
||||
|
||||
def save(self, params):
|
||||
APIADDR = "/api/metaprofile/save"
|
||||
response = {}
|
||||
loggorilla.prcss(APIADDR, "Define Models")
|
||||
key = params["key" ]
|
||||
favicon = params["favicon" ]
|
||||
copyright = params["copyright" ]
|
||||
self.cursor.execute("BEGIN;")
|
||||
try:
|
||||
loggorilla.prcss(APIADDR, "Activity: Update")
|
||||
self.cursor.execute("UPDATE `metaprofile` SET `favicon` = %s, `copyright` = %s WHERE `id` = %s ;", (favicon, copyright, key) )
|
||||
loggorilla.prcss(APIADDR, "Set Response")
|
||||
response["status" ] = "success"
|
||||
response["desc" ] = "data updated"
|
||||
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 detail(self, params):
|
||||
APIADDR = "/api/metaprofile/detail"
|
||||
response = {}
|
||||
loggorilla.prcss(APIADDR, "Define Models")
|
||||
key = params["key" ]
|
||||
self.cursor.execute("BEGIN;")
|
||||
try:
|
||||
self.cursor.execute("select `favicon`, `copyright` from `metaprofile` where `id` = %s ;", (key,) )
|
||||
row = self.cursor.fetchone()
|
||||
loggorilla.prcss(APIADDR, "Set Response")
|
||||
response["status" ] = "success"
|
||||
response["desc" ] = "data collected"
|
||||
response["data" ] = row
|
||||
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
|
||||
|
||||
54
sql/metaprofile.sql
Normal file
54
sql/metaprofile.sql
Normal file
@ -0,0 +1,54 @@
|
||||
-- README
|
||||
-- Prefix idx_ = index
|
||||
-- Prefix fk_ = foreign
|
||||
-- Create an index for fast lookups
|
||||
-- Defining constraints separately for better readability & maintainability
|
||||
-- Prefix p_ = Procedure
|
||||
-- Prefix i_ = Input(s)
|
||||
-- Prefix v_ = Variable(s)
|
||||
-- Prefix o_ = Output(s)
|
||||
|
||||
-- Main table
|
||||
|
||||
create table if not exists `metaprofile` (
|
||||
`id` int(11) not null auto_increment primary key,
|
||||
`favicon` longtext default null,
|
||||
`copyright` longtext default null
|
||||
) engine=InnoDB default charset=utf8mb4;
|
||||
|
||||
create table if not exists `metaprofile_baseurl` (
|
||||
`id` int(11) not null auto_increment primary key,
|
||||
`metaprofile` int(11) not null,
|
||||
`name` longtext not null,
|
||||
`url` longtext not null,
|
||||
key `idx_metaprofile` (`metaprofile`),
|
||||
constraint `metaprofile_baseurl_fk_metaprofile`
|
||||
foreign key (`metaprofile`) references `metaprofile` (`id`)
|
||||
on update cascade
|
||||
on delete cascade
|
||||
) engine=InnoDB default charset=utf8mb4;
|
||||
|
||||
create table if not exists `metaprofile_brand` (
|
||||
`id` int(11) not null auto_increment primary key,
|
||||
`metaprofile` int(11) not null,
|
||||
`name` longtext not null,
|
||||
`tagline` longtext default null,
|
||||
`description` longtext default null,
|
||||
key `idx_metaprofile` (`metaprofile`),
|
||||
constraint `metaprofile_brand_fk_metaprofile`
|
||||
foreign key (`metaprofile`) references `metaprofile` (`id`)
|
||||
on update cascade
|
||||
on delete cascade
|
||||
) engine=InnoDB default charset=utf8mb4;
|
||||
|
||||
create table if not exists `metaprofile_brand_logo` (
|
||||
`id` int(11) not null auto_increment primary key,
|
||||
`brand` int(11) not null,
|
||||
`name` longtext not null,
|
||||
`image` longtext not null,
|
||||
key `idx_brand` (`brand`),
|
||||
constraint `metaprofile_brand_logo_fk_brand`
|
||||
foreign key (`brand`) references `metaprofile_brand` (`id`)
|
||||
on update cascade
|
||||
on delete cascade
|
||||
) engine=InnoDB default charset=utf8mb4;
|
||||
Loading…
Reference in New Issue
Block a user