@@ 271-334 (lines=64) @@ | ||
268 | ||
269 | resp.text = json.dumps(meta_result) |
|
270 | ||
271 | @staticmethod |
|
272 | @user_logger |
|
273 | def on_delete(req, resp, id_): |
|
274 | admin_control(req) |
|
275 | if not id_.isdigit() or int(id_) <= 0: |
|
276 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
277 | description='API.INVALID_SHOPFLOOR_ID') |
|
278 | ||
279 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
280 | cursor = cnx.cursor() |
|
281 | ||
282 | cursor.execute(" SELECT name " |
|
283 | " FROM tbl_shopfloors " |
|
284 | " WHERE id = %s ", (id_,)) |
|
285 | if cursor.fetchone() is None: |
|
286 | cursor.close() |
|
287 | cnx.close() |
|
288 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
289 | description='API.SHOPFLOOR_NOT_FOUND') |
|
290 | ||
291 | # check relation with spaces |
|
292 | cursor.execute(" SELECT space_id " |
|
293 | " FROM tbl_spaces_shopfloors " |
|
294 | " WHERE shopfloor_id = %s ", |
|
295 | (id_,)) |
|
296 | rows_spaces = cursor.fetchall() |
|
297 | if rows_spaces is not None and len(rows_spaces) > 0: |
|
298 | cursor.close() |
|
299 | cnx.close() |
|
300 | raise falcon.HTTPError(status=falcon.HTTP_400, |
|
301 | title='API.BAD_REQUEST', |
|
302 | description='API.THERE_IS_RELATION_WITH_SPACES') |
|
303 | ||
304 | # delete relation with equipments |
|
305 | cursor.execute(" DELETE FROM tbl_shopfloors_equipments WHERE shopfloor_id = %s ", (id_,)) |
|
306 | ||
307 | # delete relation with meters |
|
308 | cursor.execute(" DELETE FROM tbl_shopfloors_meters WHERE shopfloor_id = %s ", (id_,)) |
|
309 | ||
310 | # delete relation with offline meters |
|
311 | cursor.execute(" DELETE FROM tbl_shopfloors_offline_meters WHERE shopfloor_id = %s ", (id_,)) |
|
312 | ||
313 | # delete relation with points |
|
314 | cursor.execute(" DELETE FROM tbl_shopfloors_points WHERE shopfloor_id = %s ", (id_,)) |
|
315 | ||
316 | # delete relation with sensor |
|
317 | cursor.execute(" DELETE FROM tbl_shopfloors_sensors WHERE shopfloor_id = %s ", (id_,)) |
|
318 | ||
319 | # delete relation with virtual meter |
|
320 | cursor.execute(" DELETE FROM tbl_shopfloors_virtual_meters WHERE shopfloor_id = %s ", (id_,)) |
|
321 | ||
322 | # delete relation with command |
|
323 | cursor.execute(" DELETE FROM tbl_shopfloors_commands WHERE shopfloor_id = %s ", (id_,)) |
|
324 | ||
325 | # delete relation with working calendar |
|
326 | cursor.execute(" DELETE FROM tbl_shopfloors_working_calendars WHERE shopfloor_id = %s ", (id_,)) |
|
327 | ||
328 | cursor.execute(" DELETE FROM tbl_shopfloors WHERE id = %s ", (id_,)) |
|
329 | cnx.commit() |
|
330 | ||
331 | cursor.close() |
|
332 | cnx.close() |
|
333 | ||
334 | resp.status = falcon.HTTP_204 |
|
335 | ||
336 | @staticmethod |
|
337 | @user_logger |
@@ 411-471 (lines=61) @@ | ||
408 | ||
409 | resp.text = json.dumps(meta_result) |
|
410 | ||
411 | @staticmethod |
|
412 | @user_logger |
|
413 | def on_delete(req, resp, id_): |
|
414 | admin_control(req) |
|
415 | if not id_.isdigit() or int(id_) <= 0: |
|
416 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
417 | description='API.INVALID_TENANT_ID') |
|
418 | ||
419 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
420 | cursor = cnx.cursor() |
|
421 | ||
422 | cursor.execute(" SELECT name " |
|
423 | " FROM tbl_tenants " |
|
424 | " WHERE id = %s ", (id_,)) |
|
425 | if cursor.fetchone() is None: |
|
426 | cursor.close() |
|
427 | cnx.close() |
|
428 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
429 | description='API.TENANT_NOT_FOUND') |
|
430 | ||
431 | # check relation with space |
|
432 | cursor.execute(" SELECT space_id " |
|
433 | " FROM tbl_spaces_tenants " |
|
434 | " WHERE tenant_id = %s ", |
|
435 | (id_,)) |
|
436 | rows_spaces = cursor.fetchall() |
|
437 | if rows_spaces is not None and len(rows_spaces) > 0: |
|
438 | cursor.close() |
|
439 | cnx.close() |
|
440 | raise falcon.HTTPError(status=falcon.HTTP_400, |
|
441 | title='API.BAD_REQUEST', |
|
442 | description='API.THERE_IS_RELATION_WITH_SPACES') |
|
443 | ||
444 | # delete relation with meter |
|
445 | cursor.execute(" DELETE FROM tbl_tenants_meters WHERE tenant_id = %s ", (id_,)) |
|
446 | ||
447 | # delete relation with offline meter |
|
448 | cursor.execute(" DELETE FROM tbl_tenants_offline_meters WHERE tenant_id = %s ", (id_,)) |
|
449 | ||
450 | # delete relation with points |
|
451 | cursor.execute(" DELETE FROM tbl_tenants_points WHERE tenant_id = %s ", (id_,)) |
|
452 | ||
453 | # delete relation with sensor |
|
454 | cursor.execute(" DELETE FROM tbl_tenants_sensors WHERE tenant_id = %s ", (id_,)) |
|
455 | ||
456 | # delete relation with virtual meter |
|
457 | cursor.execute(" DELETE FROM tbl_tenants_virtual_meters WHERE tenant_id = %s ", (id_,)) |
|
458 | ||
459 | # delete relation with command |
|
460 | cursor.execute(" DELETE FROM tbl_tenants_commands WHERE tenant_id = %s ", (id_,)) |
|
461 | ||
462 | # delete relation with working calendar |
|
463 | cursor.execute(" DELETE FROM tbl_tenants_working_calendars WHERE tenant_id = %s ", (id_,)) |
|
464 | ||
465 | cursor.execute(" DELETE FROM tbl_tenants WHERE id = %s ", (id_,)) |
|
466 | cnx.commit() |
|
467 | ||
468 | cursor.close() |
|
469 | cnx.close() |
|
470 | ||
471 | resp.status = falcon.HTTP_204 |
|
472 | ||
473 | @staticmethod |
|
474 | @user_logger |
@@ 349-409 (lines=61) @@ | ||
346 | ||
347 | resp.text = json.dumps(meta_result) |
|
348 | ||
349 | @staticmethod |
|
350 | @user_logger |
|
351 | def on_delete(req, resp, id_): |
|
352 | admin_control(req) |
|
353 | if not id_.isdigit() or int(id_) <= 0: |
|
354 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
355 | description='API.INVALID_STORE_ID') |
|
356 | ||
357 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
358 | cursor = cnx.cursor() |
|
359 | ||
360 | cursor.execute(" SELECT name " |
|
361 | " FROM tbl_stores " |
|
362 | " WHERE id = %s ", (id_,)) |
|
363 | if cursor.fetchone() is None: |
|
364 | cursor.close() |
|
365 | cnx.close() |
|
366 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
367 | description='API.STORE_NOT_FOUND') |
|
368 | ||
369 | # check relation with space |
|
370 | cursor.execute(" SELECT space_id " |
|
371 | " FROM tbl_spaces_stores " |
|
372 | " WHERE store_id = %s ", |
|
373 | (id_,)) |
|
374 | rows_spaces = cursor.fetchall() |
|
375 | if rows_spaces is not None and len(rows_spaces) > 0: |
|
376 | cursor.close() |
|
377 | cnx.close() |
|
378 | raise falcon.HTTPError(status=falcon.HTTP_400, |
|
379 | title='API.BAD_REQUEST', |
|
380 | description='API.THERE_IS_RELATION_WITH_SPACES') |
|
381 | ||
382 | # delete relation with meter |
|
383 | cursor.execute(" DELETE FROM tbl_stores_meters WHERE store_id = %s ", (id_,)) |
|
384 | ||
385 | # delete relation with offline meter |
|
386 | cursor.execute(" DELETE FROM tbl_stores_offline_meters WHERE store_id = %s ", (id_,)) |
|
387 | ||
388 | # delete relation with points |
|
389 | cursor.execute(" DELETE FROM tbl_stores_points WHERE store_id = %s ", (id_,)) |
|
390 | ||
391 | # delete relation with sensor |
|
392 | cursor.execute(" DELETE FROM tbl_stores_sensors WHERE store_id = %s ", (id_,)) |
|
393 | ||
394 | # delete relation with virtual meter |
|
395 | cursor.execute(" DELETE FROM tbl_stores_virtual_meters WHERE store_id = %s ", (id_,)) |
|
396 | ||
397 | # delete relation with command |
|
398 | cursor.execute(" DELETE FROM tbl_stores_commands WHERE store_id = %s ", (id_,)) |
|
399 | ||
400 | # delete relation with working calendar |
|
401 | cursor.execute(" DELETE FROM tbl_stores_working_calendars WHERE store_id = %s ", (id_,)) |
|
402 | ||
403 | cursor.execute(" DELETE FROM tbl_stores WHERE id = %s ", (id_,)) |
|
404 | cnx.commit() |
|
405 | ||
406 | cursor.close() |
|
407 | cnx.close() |
|
408 | ||
409 | resp.status = falcon.HTTP_204 |
|
410 | ||
411 | @staticmethod |
|
412 | @user_logger |