Compare commits
	
		
			13 Commits
		
	
	
		
			master
			...
			system/hig
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 39ca30c293 | |||
| 23be0b74f9 | |||
| a960e7af8e | |||
| 43319c914a | |||
| 469d5b045e | |||
| 189518a2ba | |||
| 67b60276ae | |||
| 51afa10505 | |||
| bb455cf9b7 | |||
| 1b7addaefb | |||
| a50f9ab69a | |||
| 8ce49202e0 | |||
| b66e5aa9cc | 
							
								
								
									
										23
									
								
								bruno/Highlight/Catalog (sample)/Add.bru
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								bruno/Highlight/Catalog (sample)/Add.bru
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,23 @@
 | 
				
			|||||||
 | 
					meta {
 | 
				
			||||||
 | 
					  name: Add
 | 
				
			||||||
 | 
					  type: http
 | 
				
			||||||
 | 
					  seq: 1
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					post {
 | 
				
			||||||
 | 
					  url: http://localhost:11000/api/highlight/:module/:alder
 | 
				
			||||||
 | 
					  body: json
 | 
				
			||||||
 | 
					  auth: inherit
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					params:path {
 | 
				
			||||||
 | 
					  module: catalog
 | 
				
			||||||
 | 
					  alder: add
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					body:json {
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    "item":1,
 | 
				
			||||||
 | 
					    "category":1
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										23
									
								
								bruno/Highlight/Catalog (sample)/Remove.bru
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								bruno/Highlight/Catalog (sample)/Remove.bru
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,23 @@
 | 
				
			|||||||
 | 
					meta {
 | 
				
			||||||
 | 
					  name: Remove
 | 
				
			||||||
 | 
					  type: http
 | 
				
			||||||
 | 
					  seq: 2
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					post {
 | 
				
			||||||
 | 
					  url: http://localhost:11000/api/highlight/:module/:alder
 | 
				
			||||||
 | 
					  body: json
 | 
				
			||||||
 | 
					  auth: inherit
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					params:path {
 | 
				
			||||||
 | 
					  module: catalog
 | 
				
			||||||
 | 
					  alder: remove
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					body:json {
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    "item":1,
 | 
				
			||||||
 | 
					    "category":1
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										8
									
								
								bruno/Highlight/Catalog (sample)/folder.bru
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								bruno/Highlight/Catalog (sample)/folder.bru
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,8 @@
 | 
				
			|||||||
 | 
					meta {
 | 
				
			||||||
 | 
					  name: Catalog (sample)
 | 
				
			||||||
 | 
					  seq: 2
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					auth {
 | 
				
			||||||
 | 
					  mode: inherit
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										24
									
								
								bruno/Highlight/Category/Add.bru
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								bruno/Highlight/Category/Add.bru
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,24 @@
 | 
				
			|||||||
 | 
					meta {
 | 
				
			||||||
 | 
					  name: Add
 | 
				
			||||||
 | 
					  type: http
 | 
				
			||||||
 | 
					  seq: 1
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					post {
 | 
				
			||||||
 | 
					  url: http://localhost:11000/api/highlight/category/:alder
 | 
				
			||||||
 | 
					  body: json
 | 
				
			||||||
 | 
					  auth: inherit
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					params:path {
 | 
				
			||||||
 | 
					  alder: add
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					body:json {
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    "title":"For your starter",
 | 
				
			||||||
 | 
					    "desc":null,
 | 
				
			||||||
 | 
					    "background":null,
 | 
				
			||||||
 | 
					    "illustration":null
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										19
									
								
								bruno/Highlight/Category/Detail.bru
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								bruno/Highlight/Category/Detail.bru
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,19 @@
 | 
				
			|||||||
 | 
					meta {
 | 
				
			||||||
 | 
					  name: Detail
 | 
				
			||||||
 | 
					  type: http
 | 
				
			||||||
 | 
					  seq: 3
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					post {
 | 
				
			||||||
 | 
					  url: http://localhost:11000/api/highlight/category/:alder
 | 
				
			||||||
 | 
					  body: json
 | 
				
			||||||
 | 
					  auth: inherit
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					params:path {
 | 
				
			||||||
 | 
					  alder: detail
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					body:json {
 | 
				
			||||||
 | 
					  {"id":1}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										25
									
								
								bruno/Highlight/Category/Edit.bru
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								bruno/Highlight/Category/Edit.bru
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,25 @@
 | 
				
			|||||||
 | 
					meta {
 | 
				
			||||||
 | 
					  name: Edit
 | 
				
			||||||
 | 
					  type: http
 | 
				
			||||||
 | 
					  seq: 4
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					post {
 | 
				
			||||||
 | 
					  url: http://localhost:11000/api/highlight/category/:alder
 | 
				
			||||||
 | 
					  body: json
 | 
				
			||||||
 | 
					  auth: inherit
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					params:path {
 | 
				
			||||||
 | 
					  alder: edit
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					body:json {
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    "id":1,
 | 
				
			||||||
 | 
					    "title":"For your starter (Edit)",
 | 
				
			||||||
 | 
					    "desc":null,
 | 
				
			||||||
 | 
					    "background":null,
 | 
				
			||||||
 | 
					    "illustration":null
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										19
									
								
								bruno/Highlight/Category/List.bru
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								bruno/Highlight/Category/List.bru
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,19 @@
 | 
				
			|||||||
 | 
					meta {
 | 
				
			||||||
 | 
					  name: List
 | 
				
			||||||
 | 
					  type: http
 | 
				
			||||||
 | 
					  seq: 2
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					post {
 | 
				
			||||||
 | 
					  url: http://localhost:11000/api/highlight/category/:alder
 | 
				
			||||||
 | 
					  body: json
 | 
				
			||||||
 | 
					  auth: inherit
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					params:path {
 | 
				
			||||||
 | 
					  alder: list
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					body:json {
 | 
				
			||||||
 | 
					  {}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										19
									
								
								bruno/Highlight/Category/Remove.bru
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								bruno/Highlight/Category/Remove.bru
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,19 @@
 | 
				
			|||||||
 | 
					meta {
 | 
				
			||||||
 | 
					  name: Remove
 | 
				
			||||||
 | 
					  type: http
 | 
				
			||||||
 | 
					  seq: 5
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					post {
 | 
				
			||||||
 | 
					  url: http://localhost:11000/api/highlight/category/:alder
 | 
				
			||||||
 | 
					  body: json
 | 
				
			||||||
 | 
					  auth: inherit
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					params:path {
 | 
				
			||||||
 | 
					  alder: remove
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					body:json {
 | 
				
			||||||
 | 
					  {"id":1}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										8
									
								
								bruno/Highlight/Category/folder.bru
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								bruno/Highlight/Category/folder.bru
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,8 @@
 | 
				
			|||||||
 | 
					meta {
 | 
				
			||||||
 | 
					  name: Category
 | 
				
			||||||
 | 
					  seq: 1
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					auth {
 | 
				
			||||||
 | 
					  mode: inherit
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										8
									
								
								bruno/Highlight/folder.bru
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								bruno/Highlight/folder.bru
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,8 @@
 | 
				
			|||||||
 | 
					meta {
 | 
				
			||||||
 | 
					  name: Highlight
 | 
				
			||||||
 | 
					  seq: 1
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					auth {
 | 
				
			||||||
 | 
					  mode: inherit
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										5
									
								
								bruno/bruno.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								bruno/bruno.json
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,5 @@
 | 
				
			|||||||
 | 
					{
 | 
				
			||||||
 | 
					  "version": "1",
 | 
				
			||||||
 | 
					  "name": "CostaPy",
 | 
				
			||||||
 | 
					  "type": "collection"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -1,3 +0,0 @@
 | 
				
			|||||||
image = {
 | 
					 | 
				
			||||||
    "profile":"https://ditaajipratama.net/img/no-profile-donut.png"
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
							
								
								
									
										50
									
								
								handler.py
									
									
									
									
									
								
							
							
						
						
									
										50
									
								
								handler.py
									
									
									
									
									
								
							@ -5,12 +5,17 @@
 | 
				
			|||||||
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 | 
					# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 | 
				
			||||||
# You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.
 | 
					# You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from    bottle                  import Bottle, route
 | 
					from    bottle                  import Bottle, route, request, response
 | 
				
			||||||
from    config                  import directory
 | 
					from    config                  import directory
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import  templates.plain.main	as template_public
 | 
					import  templates.plain.main	as template_public
 | 
				
			||||||
import  modules.public.home     as public_home
 | 
					import  modules.public.home     as public_home
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import  modules.api.highlight.category	as api_highlight_category
 | 
				
			||||||
 | 
					import  modules.api.highlight.catalog	as api_highlight_catalog
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import	json
 | 
				
			||||||
 | 
					
 | 
				
			||||||
app = Bottle()
 | 
					app = Bottle()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@app.route('/')
 | 
					@app.route('/')
 | 
				
			||||||
@ -21,3 +26,46 @@ def index():
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    return public_home.main().html(params)
 | 
					    return public_home.main().html(params)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@app.route('/api/highlight/category/<alder>', method=['OPTIONS', 'POST'])
 | 
				
			||||||
 | 
					def index(alder):
 | 
				
			||||||
 | 
					    try:
 | 
				
			||||||
 | 
					        if request.method == 'OPTIONS':
 | 
				
			||||||
 | 
					            return None
 | 
				
			||||||
 | 
					        else:
 | 
				
			||||||
 | 
					            response.content_type = 'application/json'
 | 
				
			||||||
 | 
					            params = request.json
 | 
				
			||||||
 | 
					            if alder == 'add':
 | 
				
			||||||
 | 
					                return json.dumps(api_highlight_category.category().add(params), indent = 2).encode()
 | 
				
			||||||
 | 
					            elif alder == 'list':
 | 
				
			||||||
 | 
					                return json.dumps(api_highlight_category.category().list(params), indent = 2).encode()
 | 
				
			||||||
 | 
					            elif alder == 'detail':
 | 
				
			||||||
 | 
					                return json.dumps(api_highlight_category.category().detail(params), indent = 2).encode()
 | 
				
			||||||
 | 
					            elif alder == 'edit':
 | 
				
			||||||
 | 
					                return json.dumps(api_highlight_category.category().edit(params), indent = 2).encode()
 | 
				
			||||||
 | 
					            elif alder == 'remove':
 | 
				
			||||||
 | 
					                return json.dumps(api_highlight_category.category().remove(params), indent = 2).encode()
 | 
				
			||||||
 | 
					            else:
 | 
				
			||||||
 | 
					                return json.dumps({}, indent = 2).encode()
 | 
				
			||||||
 | 
					    except Exception as e:
 | 
				
			||||||
 | 
					        print(str(e),flush=True)
 | 
				
			||||||
 | 
					        return json.dumps({}, indent = 2).encode()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@app.route('/api/highlight/catalog/<alder>', method=['OPTIONS', 'POST'])
 | 
				
			||||||
 | 
					def index(alder):
 | 
				
			||||||
 | 
					    try:
 | 
				
			||||||
 | 
					        if request.method == 'OPTIONS':
 | 
				
			||||||
 | 
					            return None
 | 
				
			||||||
 | 
					        else:
 | 
				
			||||||
 | 
					            response.content_type = 'application/json'
 | 
				
			||||||
 | 
					            params = request.json
 | 
				
			||||||
 | 
					            if alder == 'add':
 | 
				
			||||||
 | 
					                return json.dumps(api_highlight_catalog.catalog().add(params), indent = 2).encode()
 | 
				
			||||||
 | 
					            elif alder == 'remove':
 | 
				
			||||||
 | 
					                return json.dumps(api_highlight_catalog.catalog().remove(params), indent = 2).encode()
 | 
				
			||||||
 | 
					            else:
 | 
				
			||||||
 | 
					                return json.dumps({}, indent = 2).encode()
 | 
				
			||||||
 | 
					    except Exception as e:
 | 
				
			||||||
 | 
					        print(str(e),flush=True)
 | 
				
			||||||
 | 
					        return json.dumps({}, indent = 2).encode()
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										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
 | 
				
			||||||
							
								
								
									
										141
									
								
								modules/api/highlight/category.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										141
									
								
								modules/api/highlight/category.py
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,141 @@
 | 
				
			|||||||
 | 
					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()
 | 
				
			||||||
 | 
					            self.cursor.execute("SELECT * FROM `highlight_catalog` WHERE `category` = %s ; ", (id,) )
 | 
				
			||||||
 | 
					            d["catalog"] = self.cursor.fetchall()
 | 
				
			||||||
 | 
					            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
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							
								
								
									
										13
									
								
								scripts/loggorilla.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								scripts/loggorilla.py
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,13 @@
 | 
				
			|||||||
 | 
					import datetime
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def prcss(loc, msg):
 | 
				
			||||||
 | 
					    print(f"[loggorilla][{datetime.datetime.now()}][\033[32mprcss\033[39m][\033[95m{loc}\033[39m] {msg}", flush=True)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def accss(loc, msg):
 | 
				
			||||||
 | 
					    print(f"[loggorilla][{datetime.datetime.now()}][\033[36maccss\033[39m][\033[95m{loc}\033[39m] {msg}", flush=True)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def fyinf(loc, msg):
 | 
				
			||||||
 | 
					    print(f"[loggorilla][{datetime.datetime.now()}][\033[93mfyinf\033[39m][\033[95m{loc}\033[39m] {msg}", flush=True)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def error(loc, msg):
 | 
				
			||||||
 | 
					    print(f"[loggorilla][{datetime.datetime.now()}][\033[31merror\033[39m][\033[95m{loc}\033[39m] {msg}", flush=True)
 | 
				
			||||||
							
								
								
									
										73
									
								
								sql/highlight.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										73
									
								
								sql/highlight.sql
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,73 @@
 | 
				
			|||||||
 | 
					-- README
 | 
				
			||||||
 | 
					-- idx_ = index
 | 
				
			||||||
 | 
					-- fk_  = foreign
 | 
				
			||||||
 | 
					-- Create an index for fast lookups
 | 
				
			||||||
 | 
					-- Defining constraints separately for better readability & maintainability
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					-- Item table
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					create table if not exists `catalog_item` (
 | 
				
			||||||
 | 
						`id`			int(11)			not null auto_increment primary key,
 | 
				
			||||||
 | 
						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` (
 | 
				
			||||||
 | 
						`id`			int(11)			not null auto_increment primary key,
 | 
				
			||||||
 | 
						`title`			longtext		not null,
 | 
				
			||||||
 | 
						`desc`			longtext		default null,
 | 
				
			||||||
 | 
						`background`	longtext		default null,
 | 
				
			||||||
 | 
						`illustration`	longtext		default null
 | 
				
			||||||
 | 
					) engine=InnoDB default charset=utf8mb4;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					-- Bridge table
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					create table if not exists `highlight_<item>` (
 | 
				
			||||||
 | 
						`id`			int(11)			not null auto_increment primary key,
 | 
				
			||||||
 | 
						`<fk>`			int(11)			not null,
 | 
				
			||||||
 | 
						`category`		int(11)			not null,
 | 
				
			||||||
 | 
						key				`idx_<fk>`		(`<fk>`),
 | 
				
			||||||
 | 
						key				`idx_category`	(`category`),
 | 
				
			||||||
 | 
						constraint		`highlight_<item>_fk_<fk>`
 | 
				
			||||||
 | 
							foreign key (`<fk>`) references `<table>` (`<pk>`)
 | 
				
			||||||
 | 
							on update cascade
 | 
				
			||||||
 | 
							on delete cascade,
 | 
				
			||||||
 | 
						constraint		`highlight_<item>_fk_category`
 | 
				
			||||||
 | 
							foreign key (`category`) references `highlight_category` (`id`)
 | 
				
			||||||
 | 
							on update cascade
 | 
				
			||||||
 | 
							on delete cascade
 | 
				
			||||||
 | 
					) engine=InnoDB default charset=utf8mb4;
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					-- <item> 	= Your reference module name	: "catalog"			[2]
 | 
				
			||||||
 | 
					-- <fk> 	= Your FK field name 			: "item"			[5]
 | 
				
			||||||
 | 
					-- <table> 	= Your reference table name 	: "catalog_item"	[1]
 | 
				
			||||||
 | 
					-- <pk> 	= Your reference table PK 		: "id"				[1]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					create table if not exists `highlight_catalog` (
 | 
				
			||||||
 | 
						`id`			int(11)			not null auto_increment primary key,
 | 
				
			||||||
 | 
						`item`			int(11)			not null,
 | 
				
			||||||
 | 
						`category`		int(11)			not null,
 | 
				
			||||||
 | 
						key				`idx_item`		(`item`),
 | 
				
			||||||
 | 
						key				`idx_category`	(`category`),
 | 
				
			||||||
 | 
						constraint		`highlight_catalog_fk_item`
 | 
				
			||||||
 | 
							foreign key (`item`) references `catalog_item` (`id`)
 | 
				
			||||||
 | 
							on update cascade
 | 
				
			||||||
 | 
							on delete cascade,
 | 
				
			||||||
 | 
						constraint		`highlight_catalog_fk_category`
 | 
				
			||||||
 | 
							foreign key (`category`) references `highlight_category` (`id`)
 | 
				
			||||||
 | 
							on update cascade
 | 
				
			||||||
 | 
							on delete cascade
 | 
				
			||||||
 | 
					) engine=InnoDB default charset=utf8mb4;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user