| @@ 228-256 (lines=29) @@ | ||
| 225 | ||
| 226 | resp.body = json.dumps(meta_result) |
|
| 227 | ||
| 228 | @staticmethod |
|
| 229 | def on_delete(req, resp, id_): |
|
| 230 | if not id_.isdigit() or int(id_) <= 0: |
|
| 231 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 232 | description='API.INVALID_DISTRIBUTION_CIRCUIT_ID') |
|
| 233 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 234 | cursor = cnx.cursor() |
|
| 235 | ||
| 236 | cursor.execute(" SELECT name " |
|
| 237 | " FROM tbl_distribution_circuits " |
|
| 238 | " WHERE id = %s ", (id_,)) |
|
| 239 | if cursor.fetchone() is None: |
|
| 240 | cursor.close() |
|
| 241 | cnx.disconnect() |
|
| 242 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 243 | description='API.DISTRIBUTION_CIRCUIT_NOT_FOUND') |
|
| 244 | ||
| 245 | # delete relation with points |
|
| 246 | cursor.execute(" DELETE FROM tbl_distribution_circuits_points " |
|
| 247 | " WHERE distribution_circuit_id = %s ", (id_,)) |
|
| 248 | # delete distribution circuit itself |
|
| 249 | cursor.execute(" DELETE FROM tbl_distribution_circuits " |
|
| 250 | " WHERE id = %s ", (id_,)) |
|
| 251 | cnx.commit() |
|
| 252 | ||
| 253 | cursor.close() |
|
| 254 | cnx.disconnect() |
|
| 255 | ||
| 256 | resp.status = falcon.HTTP_204 |
|
| 257 | ||
| 258 | @staticmethod |
|
| 259 | def on_put(req, resp, id_): |
|
| @@ 281-307 (lines=27) @@ | ||
| 278 | ||
| 279 | resp.body = json.dumps(meta_result) |
|
| 280 | ||
| 281 | @staticmethod |
|
| 282 | def on_delete(req, resp, id_): |
|
| 283 | if not id_.isdigit() or int(id_) <= 0: |
|
| 284 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 285 | description='API.INVALID_ENERGY_FLOW_DIAGRAM_ID') |
|
| 286 | ||
| 287 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 288 | cursor = cnx.cursor() |
|
| 289 | ||
| 290 | # delete all associated nodes |
|
| 291 | cursor.execute(" DELETE FROM tbl_energy_flow_diagrams_nodes" |
|
| 292 | " WHERE energy_flow_diagram_id = %s ", (id_,)) |
|
| 293 | cnx.commit() |
|
| 294 | ||
| 295 | # delete all associated links |
|
| 296 | cursor.execute(" DELETE FROM tbl_energy_flow_diagrams_links" |
|
| 297 | " WHERE energy_flow_diagram_id = %s ", (id_,)) |
|
| 298 | cnx.commit() |
|
| 299 | ||
| 300 | cursor.execute(" DELETE FROM tbl_energy_flow_diagrams" |
|
| 301 | " WHERE id = %s ", (id_,)) |
|
| 302 | cnx.commit() |
|
| 303 | ||
| 304 | cursor.close() |
|
| 305 | cnx.disconnect() |
|
| 306 | ||
| 307 | resp.status = falcon.HTTP_204 |
|
| 308 | ||
| 309 | @staticmethod |
|
| 310 | def on_put(req, resp, id_): |
|
| @@ 197-222 (lines=26) @@ | ||
| 194 | "email": row[4]} |
|
| 195 | resp.body = json.dumps(result) |
|
| 196 | ||
| 197 | @staticmethod |
|
| 198 | def on_delete(req, resp, id_): |
|
| 199 | if not id_.isdigit() or int(id_) <= 0: |
|
| 200 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 201 | description='API.INVALID_USER_ID') |
|
| 202 | ||
| 203 | cnx = mysql.connector.connect(**config.myems_user_db) |
|
| 204 | cursor = cnx.cursor() |
|
| 205 | ||
| 206 | cursor.execute(" SELECT name " |
|
| 207 | " FROM tbl_users " |
|
| 208 | " WHERE id = %s ", (id_,)) |
|
| 209 | if cursor.fetchone() is None: |
|
| 210 | cursor.close() |
|
| 211 | cnx.disconnect() |
|
| 212 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 213 | description='API.USER_NOT_FOUND') |
|
| 214 | ||
| 215 | # TODO: delete associated objects |
|
| 216 | cursor.execute(" DELETE FROM tbl_users WHERE id = %s ", (id_,)) |
|
| 217 | cnx.commit() |
|
| 218 | ||
| 219 | cursor.close() |
|
| 220 | cnx.disconnect() |
|
| 221 | ||
| 222 | resp.status = falcon.HTTP_204 |
|
| 223 | ||
| 224 | @staticmethod |
|
| 225 | def on_put(req, resp, id_): |
|
| @@ 152-177 (lines=26) @@ | ||
| 149 | "is_enabled": bool(row[6])} |
|
| 150 | resp.body = json.dumps(result) |
|
| 151 | ||
| 152 | @staticmethod |
|
| 153 | def on_delete(req, resp, id_): |
|
| 154 | if not id_.isdigit() or int(id_) <= 0: |
|
| 155 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 156 | description='API.INVALID_RULE_ID') |
|
| 157 | ||
| 158 | cnx = mysql.connector.connect(**config.myems_fdd_db) |
|
| 159 | cursor = cnx.cursor() |
|
| 160 | ||
| 161 | cursor.execute(" SELECT id " |
|
| 162 | " FROM tbl_rules " |
|
| 163 | " WHERE id = %s ", |
|
| 164 | (id_,)) |
|
| 165 | if cursor.fetchone() is None: |
|
| 166 | cursor.close() |
|
| 167 | cnx.disconnect() |
|
| 168 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 169 | description='API.RULE_NOT_FOUND') |
|
| 170 | ||
| 171 | cursor.execute(" DELETE FROM tbl_rules WHERE id = %s ", (id_,)) |
|
| 172 | cnx.commit() |
|
| 173 | ||
| 174 | cursor.close() |
|
| 175 | cnx.disconnect() |
|
| 176 | ||
| 177 | resp.status = falcon.HTTP_204 |
|
| 178 | ||
| 179 | @staticmethod |
|
| 180 | def on_put(req, resp, id_): |
|
| @@ 175-199 (lines=25) @@ | ||
| 172 | "from_addr": row[5]} |
|
| 173 | resp.body = json.dumps(result) |
|
| 174 | ||
| 175 | @staticmethod |
|
| 176 | def on_delete(req, resp, id_): |
|
| 177 | if not id_.isdigit() or int(id_) <= 0: |
|
| 178 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 179 | description='API.INVALID_EMAIL_SERVER_ID') |
|
| 180 | ||
| 181 | cnx = mysql.connector.connect(**config.myems_fdd_db) |
|
| 182 | cursor = cnx.cursor() |
|
| 183 | ||
| 184 | cursor.execute(" SELECT host " |
|
| 185 | " FROM tbl_email_servers " |
|
| 186 | " WHERE id = %s ", (id_,)) |
|
| 187 | if cursor.fetchone() is None: |
|
| 188 | cursor.close() |
|
| 189 | cnx.disconnect() |
|
| 190 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 191 | description='API.EMAIL_SERVER_NOT_FOUND') |
|
| 192 | ||
| 193 | cursor.execute(" DELETE FROM tbl_email_servers WHERE id = %s ", (id_,)) |
|
| 194 | cnx.commit() |
|
| 195 | ||
| 196 | cursor.close() |
|
| 197 | cnx.disconnect() |
|
| 198 | ||
| 199 | resp.status = falcon.HTTP_204 |
|
| 200 | ||
| 201 | @staticmethod |
|
| 202 | def on_put(req, resp, id_): |
|
| @@ 123-147 (lines=25) @@ | ||
| 120 | "baud_rate": row[2]} |
|
| 121 | resp.body = json.dumps(result) |
|
| 122 | ||
| 123 | @staticmethod |
|
| 124 | def on_delete(req, resp, id_): |
|
| 125 | if not id_.isdigit() or int(id_) <= 0: |
|
| 126 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 127 | description='API.INVALID_GSM_MODEM_ID') |
|
| 128 | ||
| 129 | cnx = mysql.connector.connect(**config.myems_fdd_db) |
|
| 130 | cursor = cnx.cursor() |
|
| 131 | ||
| 132 | cursor.execute(" SELECT serial_port " |
|
| 133 | " FROM tbl_gsm_modems " |
|
| 134 | " WHERE id = %s ", (id_,)) |
|
| 135 | if cursor.fetchone() is None: |
|
| 136 | cursor.close() |
|
| 137 | cnx.disconnect() |
|
| 138 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 139 | description='API.GSM_MODEM_NOT_FOUND') |
|
| 140 | ||
| 141 | cursor.execute(" DELETE FROM tbl_gsm_modems WHERE id = %s ", (id_,)) |
|
| 142 | cnx.commit() |
|
| 143 | ||
| 144 | cursor.close() |
|
| 145 | cnx.disconnect() |
|
| 146 | ||
| 147 | resp.status = falcon.HTTP_204 |
|
| 148 | ||
| 149 | @staticmethod |
|
| 150 | def on_put(req, resp, id_): |
|