Module for highlight category
This commit is contained in:
		
							parent
							
								
									8ce49202e0
								
							
						
					
					
						commit
						a50f9ab69a
					
				
							
								
								
									
										139
									
								
								modules/api/hightlight/category.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										139
									
								
								modules/api/hightlight/category.py
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,139 @@
 | 
				
			|||||||
 | 
					import  mysql.connector         as      mariadb
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from	bottle			import	request
 | 
				
			||||||
 | 
					from    config                  import  database
 | 
				
			||||||
 | 
					from	scripts			import	loggorilla
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class category:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    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/category/add"
 | 
				
			||||||
 | 
					        response        = {}
 | 
				
			||||||
 | 
					        loggorilla.prcss(APIADDR, "Define Models")
 | 
				
			||||||
 | 
					        title		= params["title"	]
 | 
				
			||||||
 | 
					        desc		= params["desc"		]
 | 
				
			||||||
 | 
					        background	= params["background"	]
 | 
				
			||||||
 | 
					        illustration	= params["illustration"	]
 | 
				
			||||||
 | 
					        self.cursor.execute("BEGIN;")
 | 
				
			||||||
 | 
					        try:
 | 
				
			||||||
 | 
					            loggorilla.prcss(APIADDR, "Activity: Insert")
 | 
				
			||||||
 | 
					            self.cursor.execute("INSERT INTO `highlight_category` VALUES (DEFAULT, %s, %s, %s, %s ) ;", (title, desc, background, illustration) )
 | 
				
			||||||
 | 
					            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 list(self, params):
 | 
				
			||||||
 | 
					        APIADDR         = "/api/highlight/category/list"
 | 
				
			||||||
 | 
					        response        = {}
 | 
				
			||||||
 | 
					        self.cursor.execute("BEGIN;")
 | 
				
			||||||
 | 
					        try:
 | 
				
			||||||
 | 
					            self.cursor.execute("SELECT * FROM `highlight_category`;")
 | 
				
			||||||
 | 
					            ls = self.cursor.fetchall()
 | 
				
			||||||
 | 
					            loggorilla.prcss(APIADDR, "Set Response")
 | 
				
			||||||
 | 
					            response["status"   ] = "success"
 | 
				
			||||||
 | 
					            response["desc"     ] = "data collected"
 | 
				
			||||||
 | 
					            response["data"     ] = ls
 | 
				
			||||||
 | 
					        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/highlight/category/detail"
 | 
				
			||||||
 | 
					        response        = {}
 | 
				
			||||||
 | 
					        loggorilla.prcss(APIADDR, "Define Models")
 | 
				
			||||||
 | 
					        id		= params["id"	]
 | 
				
			||||||
 | 
					        self.cursor.execute("BEGIN;")
 | 
				
			||||||
 | 
					        try:
 | 
				
			||||||
 | 
					            self.cursor.execute("SELECT * FROM `highlight_category` WHERE `id` = %s ; ", (id,) )
 | 
				
			||||||
 | 
					            d = self.cursor.fetchone()
 | 
				
			||||||
 | 
					            loggorilla.prcss(APIADDR, "Set Response")
 | 
				
			||||||
 | 
					            response["status"   ] = "success"
 | 
				
			||||||
 | 
					            response["desc"     ] = "data collected"
 | 
				
			||||||
 | 
					            response["data"     ] = d
 | 
				
			||||||
 | 
					        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 edit(self, params):
 | 
				
			||||||
 | 
					        APIADDR         = "/api/highlight/category/edit"
 | 
				
			||||||
 | 
					        response        = {}
 | 
				
			||||||
 | 
					        loggorilla.prcss(APIADDR, "Define Models")
 | 
				
			||||||
 | 
					        id		= params["id"		]
 | 
				
			||||||
 | 
					        title		= params["title"	]
 | 
				
			||||||
 | 
					        desc		= params["desc"		]
 | 
				
			||||||
 | 
					        background	= params["background"	]
 | 
				
			||||||
 | 
					        illustration	= params["illustration"	]
 | 
				
			||||||
 | 
					        self.cursor.execute("BEGIN;")
 | 
				
			||||||
 | 
					        try:
 | 
				
			||||||
 | 
					            loggorilla.prcss(APIADDR, "Activity: Update")
 | 
				
			||||||
 | 
					            self.cursor.execute("UPDATE `highlight_category` SET `title` = %s, `desc` = %s, `background` = %s, `illustration` = %s WHERE `id` = %s ; ", (title, desc, background, illustration, id) )
 | 
				
			||||||
 | 
					            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 remove(self, params):
 | 
				
			||||||
 | 
					        APIADDR         = "/api/highlight/category/remove"
 | 
				
			||||||
 | 
					        response        = {}
 | 
				
			||||||
 | 
					        loggorilla.prcss(APIADDR, "Define Models")
 | 
				
			||||||
 | 
					        id		= params["id"		]
 | 
				
			||||||
 | 
					        self.cursor.execute("BEGIN;")
 | 
				
			||||||
 | 
					        try:
 | 
				
			||||||
 | 
					            loggorilla.prcss(APIADDR, "Activity: Remove")
 | 
				
			||||||
 | 
					            self.cursor.execute("DELETE FROM `highlight_category` WHERE `id` = %s ; ", (id,) )
 | 
				
			||||||
 | 
					            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
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user