2025-09-16 15:19:12 +07:00
import mysql . connector as mariadb
from bottle import request
from config import database
from scripts import loggorilla
import datetime
class version :
def __init__ ( self ) :
self . db_main = mariadb . connect ( * * database . db_main )
self . cursor = self . db_main . cursor ( dictionary = True )
def add ( self , params ) :
2025-09-16 20:43:42 +07:00
APIADDR = " /api/gebox/package/version/add "
2025-09-16 15:19:12 +07:00
response = { }
loggorilla . prcss ( APIADDR , " Define Models " )
package = params [ " package " ]
version = params [ " version " ]
release = params [ " release " ]
self . cursor . execute ( " BEGIN; " )
try :
loggorilla . prcss ( APIADDR , " Insert " )
self . cursor . execute ( " INSERT INTO `gebox_package_version` VALUES (DEFAULT, %s , %s , %s ) ; " , ( package , version , release ) )
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 ) :
2025-09-16 20:43:42 +07:00
APIADDR = " /api/gebox/package/version/list "
2025-09-16 15:19:12 +07:00
response = { }
2025-09-17 14:27:05 +07:00
loggorilla . prcss ( APIADDR , " Define Models " )
package = params [ " package " ]
2025-09-16 15:19:12 +07:00
self . cursor . execute ( " BEGIN; " )
try :
2025-09-17 14:27:05 +07:00
self . cursor . execute ( " select `id`, `package`, `version`, DATE_FORMAT(`release`, ' % Y- % m- %d % H: %i : % S ' ) AS `release` from gebox_package_version where `package` = %s ; " , ( package , ) )
2025-09-16 15:19:12 +07:00
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 ) :
2025-09-16 20:43:42 +07:00
APIADDR = " /api/gebox/package/version/detail "
2025-09-16 15:19:12 +07:00
response = { }
loggorilla . prcss ( APIADDR , " Define Models " )
key = params [ " key " ]
self . cursor . execute ( " BEGIN; " )
try :
2025-09-17 14:27:05 +07:00
self . cursor . execute ( " select `id`, `package`, `version`, DATE_FORMAT(`release`, ' % Y- % m- %d % H: %i : % S ' ) AS `release` from gebox_package_version where `id` = %s ; " , ( key , ) )
2025-09-16 15:19:12 +07:00
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
def edit ( self , params ) :
2025-09-16 20:43:42 +07:00
APIADDR = " /api/gebox/package/version/edit "
2025-09-16 15:19:12 +07:00
response = { }
loggorilla . prcss ( APIADDR , " Define Models " )
key = params [ " key " ]
package = params [ " package " ]
version = params [ " version " ]
release = params [ " release " ]
self . cursor . execute ( " BEGIN; " )
try :
loggorilla . prcss ( APIADDR , " Update " )
self . cursor . execute ( " update gebox_package_version set `package` = %s , `version` = %s , `release` = %s where `id` = %s ; " , ( package , version , release , key ) )
row = self . cursor . fetchone ( )
loggorilla . prcss ( APIADDR , " Set Response " )
response [ " status " ] = " success "
response [ " desc " ] = " data edited "
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 ) :
2025-09-16 20:43:42 +07:00
APIADDR = " /api/gebox/package/version/remove "
2025-09-16 15:19:12 +07:00
response = { }
loggorilla . prcss ( APIADDR , " Define Models " )
key = params [ " key " ]
self . cursor . execute ( " BEGIN; " )
try :
loggorilla . prcss ( APIADDR , " Delete " )
self . cursor . execute ( " delete from gebox_package_version where `id` = %s ; " , ( key , ) )
row = self . cursor . fetchone ( )
loggorilla . prcss ( APIADDR , " Set Response " )
response [ " status " ] = " success "
response [ " desc " ] = " data edited "
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