| @@ 2055-2193 (lines=139) @@ | ||
| 2052 | resp.status = falcon.HTTP_204 |
|
| 2053 | ||
| 2054 | ||
| 2055 | class CombinedEquipmentOfflineMeterCollection: |
|
| 2056 | def __init__(self): |
|
| 2057 | pass |
|
| 2058 | ||
| 2059 | @staticmethod |
|
| 2060 | def on_options(req, resp, id_): |
|
| 2061 | _ = req |
|
| 2062 | resp.status = falcon.HTTP_200 |
|
| 2063 | _ = id_ |
|
| 2064 | ||
| 2065 | @staticmethod |
|
| 2066 | def on_get(req, resp, id_): |
|
| 2067 | if 'API-KEY' not in req.headers or \ |
|
| 2068 | not isinstance(req.headers['API-KEY'], str) or \ |
|
| 2069 | len(str.strip(req.headers['API-KEY'])) == 0: |
|
| 2070 | access_control(req) |
|
| 2071 | else: |
|
| 2072 | api_key_control(req) |
|
| 2073 | if not id_.isdigit() or int(id_) <= 0: |
|
| 2074 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 2075 | description='API.INVALID_COMBINED_EQUIPMENT_ID') |
|
| 2076 | ||
| 2077 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 2078 | cursor = cnx.cursor() |
|
| 2079 | ||
| 2080 | cursor.execute(" SELECT name " |
|
| 2081 | " FROM tbl_combined_equipments " |
|
| 2082 | " WHERE id = %s ", (id_,)) |
|
| 2083 | if cursor.fetchone() is None: |
|
| 2084 | cursor.close() |
|
| 2085 | cnx.close() |
|
| 2086 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 2087 | description='API.COMBINED_EQUIPMENT_NOT_FOUND') |
|
| 2088 | ||
| 2089 | query = (" SELECT id, name, uuid " |
|
| 2090 | " FROM tbl_energy_categories ") |
|
| 2091 | cursor.execute(query) |
|
| 2092 | rows_energy_categories = cursor.fetchall() |
|
| 2093 | ||
| 2094 | energy_category_dict = dict() |
|
| 2095 | if rows_energy_categories is not None and len(rows_energy_categories) > 0: |
|
| 2096 | for row in rows_energy_categories: |
|
| 2097 | energy_category_dict[row[0]] = {"id": row[0], |
|
| 2098 | "name": row[1], |
|
| 2099 | "uuid": row[2]} |
|
| 2100 | ||
| 2101 | query = (" SELECT m.id, m.name, m.uuid, m.energy_category_id, em.is_output " |
|
| 2102 | " FROM tbl_combined_equipments e, tbl_combined_equipments_offline_meters em, tbl_offline_meters m " |
|
| 2103 | " WHERE em.combined_equipment_id = e.id AND m.id = em.offline_meter_id AND e.id = %s " |
|
| 2104 | " ORDER BY m.id ") |
|
| 2105 | cursor.execute(query, (id_,)) |
|
| 2106 | rows = cursor.fetchall() |
|
| 2107 | ||
| 2108 | result = list() |
|
| 2109 | if rows is not None and len(rows) > 0: |
|
| 2110 | for row in rows: |
|
| 2111 | meta_result = {"id": row[0], "name": row[1], "uuid": row[2], |
|
| 2112 | "energy_category": energy_category_dict.get(row[3], None), |
|
| 2113 | "is_output": bool(row[4])} |
|
| 2114 | result.append(meta_result) |
|
| 2115 | ||
| 2116 | cursor.close() |
|
| 2117 | cnx.close() |
|
| 2118 | ||
| 2119 | resp.text = json.dumps(result) |
|
| 2120 | ||
| 2121 | @staticmethod |
|
| 2122 | @user_logger |
|
| 2123 | def on_post(req, resp, id_): |
|
| 2124 | """Handles POST requests""" |
|
| 2125 | admin_control(req) |
|
| 2126 | try: |
|
| 2127 | raw_json = req.stream.read().decode('utf-8') |
|
| 2128 | except Exception as ex: |
|
| 2129 | print(ex) |
|
| 2130 | raise falcon.HTTPError(status=falcon.HTTP_400, |
|
| 2131 | title='API.BAD_REQUEST', |
|
| 2132 | description='API.FAILED_TO_READ_REQUEST_STREAM') |
|
| 2133 | ||
| 2134 | if not id_.isdigit() or int(id_) <= 0: |
|
| 2135 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 2136 | description='API.INVALID_COMBINED_EQUIPMENT_ID') |
|
| 2137 | ||
| 2138 | new_values = json.loads(raw_json) |
|
| 2139 | ||
| 2140 | if 'offline_meter_id' not in new_values['data'].keys() or \ |
|
| 2141 | not isinstance(new_values['data']['offline_meter_id'], int) or \ |
|
| 2142 | new_values['data']['offline_meter_id'] <= 0: |
|
| 2143 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 2144 | description='API.INVALID_OFFLINE_METER_ID') |
|
| 2145 | offline_meter_id = new_values['data']['offline_meter_id'] |
|
| 2146 | ||
| 2147 | if 'is_output' not in new_values['data'].keys() or \ |
|
| 2148 | not isinstance(new_values['data']['is_output'], bool): |
|
| 2149 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 2150 | description='API.INVALID_IS_OUTPUT_VALUE') |
|
| 2151 | is_output = new_values['data']['is_output'] |
|
| 2152 | ||
| 2153 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 2154 | cursor = cnx.cursor() |
|
| 2155 | ||
| 2156 | cursor.execute(" SELECT name " |
|
| 2157 | " from tbl_combined_equipments " |
|
| 2158 | " WHERE id = %s ", (id_,)) |
|
| 2159 | if cursor.fetchone() is None: |
|
| 2160 | cursor.close() |
|
| 2161 | cnx.close() |
|
| 2162 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 2163 | description='API.COMBINED_EQUIPMENT_NOT_FOUND') |
|
| 2164 | ||
| 2165 | cursor.execute(" SELECT name " |
|
| 2166 | " FROM tbl_offline_meters " |
|
| 2167 | " WHERE id = %s ", (offline_meter_id,)) |
|
| 2168 | if cursor.fetchone() is None: |
|
| 2169 | cursor.close() |
|
| 2170 | cnx.close() |
|
| 2171 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 2172 | description='API.OFFLINE_METER_NOT_FOUND') |
|
| 2173 | ||
| 2174 | query = (" SELECT id " |
|
| 2175 | " FROM tbl_combined_equipments_offline_meters " |
|
| 2176 | " WHERE combined_equipment_id = %s AND offline_meter_id = %s") |
|
| 2177 | cursor.execute(query, (id_, offline_meter_id,)) |
|
| 2178 | if cursor.fetchone() is not None: |
|
| 2179 | cursor.close() |
|
| 2180 | cnx.close() |
|
| 2181 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.ERROR', |
|
| 2182 | description='API.COMBINED_EQUIPMENT_OFFLINE_METER_RELATION_EXISTS') |
|
| 2183 | ||
| 2184 | add_row = (" INSERT INTO tbl_combined_equipments_offline_meters " |
|
| 2185 | " (combined_equipment_id, offline_meter_id, is_output ) " |
|
| 2186 | " VALUES (%s, %s, %s) ") |
|
| 2187 | cursor.execute(add_row, (id_, offline_meter_id, is_output)) |
|
| 2188 | cnx.commit() |
|
| 2189 | cursor.close() |
|
| 2190 | cnx.close() |
|
| 2191 | ||
| 2192 | resp.status = falcon.HTTP_201 |
|
| 2193 | resp.location = '/combinedequipments/' + str(id_) + '/offlinemeters/' + str(offline_meter_id) |
|
| 2194 | ||
| 2195 | ||
| 2196 | class CombinedEquipmentOfflineMeterItem: |
|
| @@ 2258-2395 (lines=138) @@ | ||
| 2255 | resp.status = falcon.HTTP_204 |
|
| 2256 | ||
| 2257 | ||
| 2258 | class CombinedEquipmentVirtualMeterCollection: |
|
| 2259 | def __init__(self): |
|
| 2260 | pass |
|
| 2261 | ||
| 2262 | @staticmethod |
|
| 2263 | def on_options(req, resp, id_): |
|
| 2264 | _ = req |
|
| 2265 | resp.status = falcon.HTTP_200 |
|
| 2266 | _ = id_ |
|
| 2267 | ||
| 2268 | @staticmethod |
|
| 2269 | def on_get(req, resp, id_): |
|
| 2270 | if 'API-KEY' not in req.headers or \ |
|
| 2271 | not isinstance(req.headers['API-KEY'], str) or \ |
|
| 2272 | len(str.strip(req.headers['API-KEY'])) == 0: |
|
| 2273 | access_control(req) |
|
| 2274 | else: |
|
| 2275 | api_key_control(req) |
|
| 2276 | if not id_.isdigit() or int(id_) <= 0: |
|
| 2277 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 2278 | description='API.INVALID_COMBINED_EQUIPMENT_ID') |
|
| 2279 | ||
| 2280 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 2281 | cursor = cnx.cursor() |
|
| 2282 | ||
| 2283 | cursor.execute(" SELECT name " |
|
| 2284 | " FROM tbl_combined_equipments " |
|
| 2285 | " WHERE id = %s ", (id_,)) |
|
| 2286 | if cursor.fetchone() is None: |
|
| 2287 | cursor.close() |
|
| 2288 | cnx.close() |
|
| 2289 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 2290 | description='API.COMBINED_EQUIPMENT_NOT_FOUND') |
|
| 2291 | ||
| 2292 | query = (" SELECT id, name, uuid " |
|
| 2293 | " FROM tbl_energy_categories ") |
|
| 2294 | cursor.execute(query) |
|
| 2295 | rows_energy_categories = cursor.fetchall() |
|
| 2296 | ||
| 2297 | energy_category_dict = dict() |
|
| 2298 | if rows_energy_categories is not None and len(rows_energy_categories) > 0: |
|
| 2299 | for row in rows_energy_categories: |
|
| 2300 | energy_category_dict[row[0]] = {"id": row[0], |
|
| 2301 | "name": row[1], |
|
| 2302 | "uuid": row[2]} |
|
| 2303 | ||
| 2304 | query = (" SELECT m.id, m.name, m.uuid, m.energy_category_id, em.is_output " |
|
| 2305 | " FROM tbl_combined_equipments e, tbl_combined_equipments_virtual_meters em, tbl_virtual_meters m " |
|
| 2306 | " WHERE em.combined_equipment_id = e.id AND m.id = em.virtual_meter_id AND e.id = %s " |
|
| 2307 | " ORDER BY m.id ") |
|
| 2308 | cursor.execute(query, (id_,)) |
|
| 2309 | rows = cursor.fetchall() |
|
| 2310 | ||
| 2311 | result = list() |
|
| 2312 | if rows is not None and len(rows) > 0: |
|
| 2313 | for row in rows: |
|
| 2314 | meta_result = {"id": row[0], "name": row[1], "uuid": row[2], |
|
| 2315 | "energy_category": energy_category_dict.get(row[3], None), |
|
| 2316 | "is_output": bool(row[4])} |
|
| 2317 | result.append(meta_result) |
|
| 2318 | ||
| 2319 | cursor.close() |
|
| 2320 | cnx.close() |
|
| 2321 | resp.text = json.dumps(result) |
|
| 2322 | ||
| 2323 | @staticmethod |
|
| 2324 | @user_logger |
|
| 2325 | def on_post(req, resp, id_): |
|
| 2326 | """Handles POST requests""" |
|
| 2327 | admin_control(req) |
|
| 2328 | try: |
|
| 2329 | raw_json = req.stream.read().decode('utf-8') |
|
| 2330 | except Exception as ex: |
|
| 2331 | print(ex) |
|
| 2332 | raise falcon.HTTPError(status=falcon.HTTP_400, |
|
| 2333 | title='API.BAD_REQUEST', |
|
| 2334 | description='API.FAILED_TO_READ_REQUEST_STREAM') |
|
| 2335 | ||
| 2336 | if not id_.isdigit() or int(id_) <= 0: |
|
| 2337 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 2338 | description='API.INVALID_COMBINED_EQUIPMENT_ID') |
|
| 2339 | ||
| 2340 | new_values = json.loads(raw_json) |
|
| 2341 | ||
| 2342 | if 'virtual_meter_id' not in new_values['data'].keys() or \ |
|
| 2343 | not isinstance(new_values['data']['virtual_meter_id'], int) or \ |
|
| 2344 | new_values['data']['virtual_meter_id'] <= 0: |
|
| 2345 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 2346 | description='API.INVALID_VIRTUAL_METER_ID') |
|
| 2347 | virtual_meter_id = new_values['data']['virtual_meter_id'] |
|
| 2348 | ||
| 2349 | if 'is_output' not in new_values['data'].keys() or \ |
|
| 2350 | not isinstance(new_values['data']['is_output'], bool): |
|
| 2351 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 2352 | description='API.INVALID_IS_OUTPUT_VALUE') |
|
| 2353 | is_output = new_values['data']['is_output'] |
|
| 2354 | ||
| 2355 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 2356 | cursor = cnx.cursor() |
|
| 2357 | ||
| 2358 | cursor.execute(" SELECT name " |
|
| 2359 | " from tbl_combined_equipments " |
|
| 2360 | " WHERE id = %s ", (id_,)) |
|
| 2361 | if cursor.fetchone() is None: |
|
| 2362 | cursor.close() |
|
| 2363 | cnx.close() |
|
| 2364 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 2365 | description='API.COMBINED_EQUIPMENT_NOT_FOUND') |
|
| 2366 | ||
| 2367 | cursor.execute(" SELECT name " |
|
| 2368 | " FROM tbl_virtual_meters " |
|
| 2369 | " WHERE id = %s ", (virtual_meter_id,)) |
|
| 2370 | if cursor.fetchone() is None: |
|
| 2371 | cursor.close() |
|
| 2372 | cnx.close() |
|
| 2373 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 2374 | description='API.VIRTUAL_METER_NOT_FOUND') |
|
| 2375 | ||
| 2376 | query = (" SELECT id " |
|
| 2377 | " FROM tbl_combined_equipments_virtual_meters " |
|
| 2378 | " WHERE combined_equipment_id = %s AND virtual_meter_id = %s") |
|
| 2379 | cursor.execute(query, (id_, virtual_meter_id,)) |
|
| 2380 | if cursor.fetchone() is not None: |
|
| 2381 | cursor.close() |
|
| 2382 | cnx.close() |
|
| 2383 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.ERROR', |
|
| 2384 | description='API.COMBINED_EQUIPMENT_VIRTUAL_METER_RELATION_EXISTS') |
|
| 2385 | ||
| 2386 | add_row = (" INSERT INTO tbl_combined_equipments_virtual_meters " |
|
| 2387 | " (combined_equipment_id, virtual_meter_id, is_output ) " |
|
| 2388 | " VALUES (%s, %s, %s) ") |
|
| 2389 | cursor.execute(add_row, (id_, virtual_meter_id, is_output)) |
|
| 2390 | cnx.commit() |
|
| 2391 | cursor.close() |
|
| 2392 | cnx.close() |
|
| 2393 | ||
| 2394 | resp.status = falcon.HTTP_201 |
|
| 2395 | resp.location = '/combinedequipments/' + str(id_) + '/virtualmeters/' + str(virtual_meter_id) |
|
| 2396 | ||
| 2397 | ||
| 2398 | class CombinedEquipmentVirtualMeterItem: |
|
| @@ 1853-1990 (lines=138) @@ | ||
| 1850 | resp.text = json.dumps(result) |
|
| 1851 | ||
| 1852 | ||
| 1853 | class CombinedEquipmentMeterCollection: |
|
| 1854 | def __init__(self): |
|
| 1855 | pass |
|
| 1856 | ||
| 1857 | @staticmethod |
|
| 1858 | def on_options(req, resp, id_): |
|
| 1859 | _ = req |
|
| 1860 | resp.status = falcon.HTTP_200 |
|
| 1861 | _ = id_ |
|
| 1862 | ||
| 1863 | @staticmethod |
|
| 1864 | def on_get(req, resp, id_): |
|
| 1865 | if 'API-KEY' not in req.headers or \ |
|
| 1866 | not isinstance(req.headers['API-KEY'], str) or \ |
|
| 1867 | len(str.strip(req.headers['API-KEY'])) == 0: |
|
| 1868 | access_control(req) |
|
| 1869 | else: |
|
| 1870 | api_key_control(req) |
|
| 1871 | if not id_.isdigit() or int(id_) <= 0: |
|
| 1872 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1873 | description='API.INVALID_COMBINED_EQUIPMENT_ID') |
|
| 1874 | ||
| 1875 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 1876 | cursor = cnx.cursor() |
|
| 1877 | ||
| 1878 | cursor.execute(" SELECT name " |
|
| 1879 | " FROM tbl_combined_equipments " |
|
| 1880 | " WHERE id = %s ", (id_,)) |
|
| 1881 | if cursor.fetchone() is None: |
|
| 1882 | cursor.close() |
|
| 1883 | cnx.close() |
|
| 1884 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1885 | description='API.COMBINED_EQUIPMENT_NOT_FOUND') |
|
| 1886 | ||
| 1887 | query = (" SELECT id, name, uuid " |
|
| 1888 | " FROM tbl_energy_categories ") |
|
| 1889 | cursor.execute(query) |
|
| 1890 | rows_energy_categories = cursor.fetchall() |
|
| 1891 | ||
| 1892 | energy_category_dict = dict() |
|
| 1893 | if rows_energy_categories is not None and len(rows_energy_categories) > 0: |
|
| 1894 | for row in rows_energy_categories: |
|
| 1895 | energy_category_dict[row[0]] = {"id": row[0], |
|
| 1896 | "name": row[1], |
|
| 1897 | "uuid": row[2]} |
|
| 1898 | ||
| 1899 | query = (" SELECT m.id, m.name, m.uuid, m.energy_category_id, em.is_output " |
|
| 1900 | " FROM tbl_combined_equipments e, tbl_combined_equipments_meters em, tbl_meters m " |
|
| 1901 | " WHERE em.combined_equipment_id = e.id AND m.id = em.meter_id AND e.id = %s " |
|
| 1902 | " ORDER BY m.id ") |
|
| 1903 | cursor.execute(query, (id_,)) |
|
| 1904 | rows = cursor.fetchall() |
|
| 1905 | ||
| 1906 | result = list() |
|
| 1907 | if rows is not None and len(rows) > 0: |
|
| 1908 | for row in rows: |
|
| 1909 | meta_result = {"id": row[0], "name": row[1], "uuid": row[2], |
|
| 1910 | "energy_category": energy_category_dict.get(row[3], None), |
|
| 1911 | "is_output": bool(row[4])} |
|
| 1912 | result.append(meta_result) |
|
| 1913 | ||
| 1914 | cursor.close() |
|
| 1915 | cnx.close() |
|
| 1916 | ||
| 1917 | resp.text = json.dumps(result) |
|
| 1918 | ||
| 1919 | @staticmethod |
|
| 1920 | @user_logger |
|
| 1921 | def on_post(req, resp, id_): |
|
| 1922 | """Handles POST requests""" |
|
| 1923 | admin_control(req) |
|
| 1924 | try: |
|
| 1925 | raw_json = req.stream.read().decode('utf-8') |
|
| 1926 | except Exception as ex: |
|
| 1927 | print(ex) |
|
| 1928 | raise falcon.HTTPError(status=falcon.HTTP_400, |
|
| 1929 | title='API.BAD_REQUEST', |
|
| 1930 | description='API.FAILED_TO_READ_REQUEST_STREAM') |
|
| 1931 | ||
| 1932 | if not id_.isdigit() or int(id_) <= 0: |
|
| 1933 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1934 | description='API.INVALID_COMBINED_EQUIPMENT_ID') |
|
| 1935 | ||
| 1936 | new_values = json.loads(raw_json) |
|
| 1937 | ||
| 1938 | if 'meter_id' not in new_values['data'].keys() or \ |
|
| 1939 | not isinstance(new_values['data']['meter_id'], int) or \ |
|
| 1940 | new_values['data']['meter_id'] <= 0: |
|
| 1941 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1942 | description='API.INVALID_METER_ID') |
|
| 1943 | meter_id = new_values['data']['meter_id'] |
|
| 1944 | ||
| 1945 | if 'is_output' not in new_values['data'].keys() or \ |
|
| 1946 | not isinstance(new_values['data']['is_output'], bool): |
|
| 1947 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1948 | description='API.INVALID_IS_OUTPUT_VALUE') |
|
| 1949 | is_output = new_values['data']['is_output'] |
|
| 1950 | ||
| 1951 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 1952 | cursor = cnx.cursor() |
|
| 1953 | ||
| 1954 | cursor.execute(" SELECT name " |
|
| 1955 | " from tbl_combined_equipments " |
|
| 1956 | " WHERE id = %s ", (id_,)) |
|
| 1957 | if cursor.fetchone() is None: |
|
| 1958 | cursor.close() |
|
| 1959 | cnx.close() |
|
| 1960 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1961 | description='API.COMBINED_EQUIPMENT_NOT_FOUND') |
|
| 1962 | ||
| 1963 | cursor.execute(" SELECT name " |
|
| 1964 | " FROM tbl_meters " |
|
| 1965 | " WHERE id = %s ", (meter_id,)) |
|
| 1966 | if cursor.fetchone() is None: |
|
| 1967 | cursor.close() |
|
| 1968 | cnx.close() |
|
| 1969 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1970 | description='API.METER_NOT_FOUND') |
|
| 1971 | ||
| 1972 | query = (" SELECT id " |
|
| 1973 | " FROM tbl_combined_equipments_meters " |
|
| 1974 | " WHERE combined_equipment_id = %s AND meter_id = %s") |
|
| 1975 | cursor.execute(query, (id_, meter_id,)) |
|
| 1976 | if cursor.fetchone() is not None: |
|
| 1977 | cursor.close() |
|
| 1978 | cnx.close() |
|
| 1979 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.ERROR', |
|
| 1980 | description='API.COMBINED_EQUIPMENT_METER_RELATION_EXISTS') |
|
| 1981 | ||
| 1982 | add_row = (" INSERT INTO tbl_combined_equipments_meters (combined_equipment_id, meter_id, is_output ) " |
|
| 1983 | " VALUES (%s, %s, %s) ") |
|
| 1984 | cursor.execute(add_row, (id_, meter_id, is_output)) |
|
| 1985 | cnx.commit() |
|
| 1986 | cursor.close() |
|
| 1987 | cnx.close() |
|
| 1988 | ||
| 1989 | resp.status = falcon.HTTP_201 |
|
| 1990 | resp.location = '/combinedequipments/' + str(id_) + '/meters/' + str(meter_id) |
|
| 1991 | ||
| 1992 | ||
| 1993 | class CombinedEquipmentMeterItem: |
|
| @@ 1762-1899 (lines=138) @@ | ||
| 1759 | resp.status = falcon.HTTP_204 |
|
| 1760 | ||
| 1761 | ||
| 1762 | class EquipmentVirtualMeterCollection: |
|
| 1763 | def __init__(self): |
|
| 1764 | pass |
|
| 1765 | ||
| 1766 | @staticmethod |
|
| 1767 | def on_options(req, resp, id_): |
|
| 1768 | _ = req |
|
| 1769 | resp.status = falcon.HTTP_200 |
|
| 1770 | _ = id_ |
|
| 1771 | ||
| 1772 | @staticmethod |
|
| 1773 | def on_get(req, resp, id_): |
|
| 1774 | if 'API-KEY' not in req.headers or \ |
|
| 1775 | not isinstance(req.headers['API-KEY'], str) or \ |
|
| 1776 | len(str.strip(req.headers['API-KEY'])) == 0: |
|
| 1777 | access_control(req) |
|
| 1778 | else: |
|
| 1779 | api_key_control(req) |
|
| 1780 | if not id_.isdigit() or int(id_) <= 0: |
|
| 1781 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1782 | description='API.INVALID_EQUIPMENT_ID') |
|
| 1783 | ||
| 1784 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 1785 | cursor = cnx.cursor() |
|
| 1786 | ||
| 1787 | cursor.execute(" SELECT name " |
|
| 1788 | " FROM tbl_equipments " |
|
| 1789 | " WHERE id = %s ", (id_,)) |
|
| 1790 | if cursor.fetchone() is None: |
|
| 1791 | cursor.close() |
|
| 1792 | cnx.close() |
|
| 1793 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1794 | description='API.EQUIPMENT_NOT_FOUND') |
|
| 1795 | ||
| 1796 | query = (" SELECT id, name, uuid " |
|
| 1797 | " FROM tbl_energy_categories ") |
|
| 1798 | cursor.execute(query) |
|
| 1799 | rows_energy_categories = cursor.fetchall() |
|
| 1800 | ||
| 1801 | energy_category_dict = dict() |
|
| 1802 | if rows_energy_categories is not None and len(rows_energy_categories) > 0: |
|
| 1803 | for row in rows_energy_categories: |
|
| 1804 | energy_category_dict[row[0]] = {"id": row[0], |
|
| 1805 | "name": row[1], |
|
| 1806 | "uuid": row[2]} |
|
| 1807 | ||
| 1808 | query = (" SELECT m.id, m.name, m.uuid, m.energy_category_id, em.is_output " |
|
| 1809 | " FROM tbl_equipments e, tbl_equipments_virtual_meters em, tbl_virtual_meters m " |
|
| 1810 | " WHERE em.equipment_id = e.id AND m.id = em.virtual_meter_id AND e.id = %s " |
|
| 1811 | " ORDER BY m.id ") |
|
| 1812 | cursor.execute(query, (id_,)) |
|
| 1813 | rows = cursor.fetchall() |
|
| 1814 | ||
| 1815 | result = list() |
|
| 1816 | if rows is not None and len(rows) > 0: |
|
| 1817 | for row in rows: |
|
| 1818 | meta_result = {"id": row[0], |
|
| 1819 | "name": row[1], |
|
| 1820 | "uuid": row[2], |
|
| 1821 | "energy_category": energy_category_dict.get(row[3], None), |
|
| 1822 | "is_output": bool(row[4])} |
|
| 1823 | result.append(meta_result) |
|
| 1824 | ||
| 1825 | resp.text = json.dumps(result) |
|
| 1826 | ||
| 1827 | @staticmethod |
|
| 1828 | @user_logger |
|
| 1829 | def on_post(req, resp, id_): |
|
| 1830 | """Handles POST requests""" |
|
| 1831 | admin_control(req) |
|
| 1832 | try: |
|
| 1833 | raw_json = req.stream.read().decode('utf-8') |
|
| 1834 | except Exception as ex: |
|
| 1835 | print(str(ex)) |
|
| 1836 | raise falcon.HTTPError(status=falcon.HTTP_400, |
|
| 1837 | title='API.BAD_REQUEST', |
|
| 1838 | description='API.FAILED_TO_READ_REQUEST_STREAM') |
|
| 1839 | ||
| 1840 | if not id_.isdigit() or int(id_) <= 0: |
|
| 1841 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1842 | description='API.INVALID_EQUIPMENT_ID') |
|
| 1843 | ||
| 1844 | new_values = json.loads(raw_json) |
|
| 1845 | ||
| 1846 | if 'virtual_meter_id' not in new_values['data'].keys() or \ |
|
| 1847 | not isinstance(new_values['data']['virtual_meter_id'], int) or \ |
|
| 1848 | new_values['data']['virtual_meter_id'] <= 0: |
|
| 1849 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1850 | description='API.INVALID_VIRTUAL_METER_ID') |
|
| 1851 | virtual_meter_id = new_values['data']['virtual_meter_id'] |
|
| 1852 | ||
| 1853 | if 'is_output' not in new_values['data'].keys() or \ |
|
| 1854 | not isinstance(new_values['data']['is_output'], bool): |
|
| 1855 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1856 | description='API.INVALID_IS_OUTPUT_VALUE') |
|
| 1857 | is_output = new_values['data']['is_output'] |
|
| 1858 | ||
| 1859 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 1860 | cursor = cnx.cursor() |
|
| 1861 | ||
| 1862 | cursor.execute(" SELECT name " |
|
| 1863 | " from tbl_equipments " |
|
| 1864 | " WHERE id = %s ", (id_,)) |
|
| 1865 | if cursor.fetchone() is None: |
|
| 1866 | cursor.close() |
|
| 1867 | cnx.close() |
|
| 1868 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1869 | description='API.EQUIPMENT_NOT_FOUND') |
|
| 1870 | ||
| 1871 | cursor.execute(" SELECT name " |
|
| 1872 | " FROM tbl_virtual_meters " |
|
| 1873 | " WHERE id = %s ", (virtual_meter_id,)) |
|
| 1874 | if cursor.fetchone() is None: |
|
| 1875 | cursor.close() |
|
| 1876 | cnx.close() |
|
| 1877 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1878 | description='API.VIRTUAL_METER_NOT_FOUND') |
|
| 1879 | ||
| 1880 | query = (" SELECT id " |
|
| 1881 | " FROM tbl_equipments_virtual_meters " |
|
| 1882 | " WHERE equipment_id = %s AND virtual_meter_id = %s") |
|
| 1883 | cursor.execute(query, (id_, virtual_meter_id,)) |
|
| 1884 | if cursor.fetchone() is not None: |
|
| 1885 | cursor.close() |
|
| 1886 | cnx.close() |
|
| 1887 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.ERROR', |
|
| 1888 | description='API.EQUIPMENT_VIRTUAL_METER_RELATION_EXISTS') |
|
| 1889 | ||
| 1890 | add_row = (" INSERT INTO tbl_equipments_virtual_meters (equipment_id, virtual_meter_id, is_output ) " |
|
| 1891 | " VALUES (%s, %s, %s) ") |
|
| 1892 | cursor.execute(add_row, (id_, virtual_meter_id, is_output)) |
|
| 1893 | cnx.commit() |
|
| 1894 | cursor.close() |
|
| 1895 | cnx.close() |
|
| 1896 | ||
| 1897 | resp.status = falcon.HTTP_201 |
|
| 1898 | resp.location = '/equipments/' + str(id_) + '/virtualmeters/' + str(virtual_meter_id) |
|
| 1899 | ||
| 1900 | ||
| 1901 | class EquipmentVirtualMeterItem: |
|
| 1902 | def __init__(self): |
|
| @@ 1560-1697 (lines=138) @@ | ||
| 1557 | resp.status = falcon.HTTP_204 |
|
| 1558 | ||
| 1559 | ||
| 1560 | class EquipmentOfflineMeterCollection: |
|
| 1561 | def __init__(self): |
|
| 1562 | pass |
|
| 1563 | ||
| 1564 | @staticmethod |
|
| 1565 | def on_options(req, resp, id_): |
|
| 1566 | _ = req |
|
| 1567 | resp.status = falcon.HTTP_200 |
|
| 1568 | _ = id_ |
|
| 1569 | ||
| 1570 | @staticmethod |
|
| 1571 | def on_get(req, resp, id_): |
|
| 1572 | if 'API-KEY' not in req.headers or \ |
|
| 1573 | not isinstance(req.headers['API-KEY'], str) or \ |
|
| 1574 | len(str.strip(req.headers['API-KEY'])) == 0: |
|
| 1575 | access_control(req) |
|
| 1576 | else: |
|
| 1577 | api_key_control(req) |
|
| 1578 | if not id_.isdigit() or int(id_) <= 0: |
|
| 1579 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1580 | description='API.INVALID_EQUIPMENT_ID') |
|
| 1581 | ||
| 1582 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 1583 | cursor = cnx.cursor() |
|
| 1584 | ||
| 1585 | cursor.execute(" SELECT name " |
|
| 1586 | " FROM tbl_equipments " |
|
| 1587 | " WHERE id = %s ", (id_,)) |
|
| 1588 | if cursor.fetchone() is None: |
|
| 1589 | cursor.close() |
|
| 1590 | cnx.close() |
|
| 1591 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1592 | description='API.EQUIPMENT_NOT_FOUND') |
|
| 1593 | ||
| 1594 | query = (" SELECT id, name, uuid " |
|
| 1595 | " FROM tbl_energy_categories ") |
|
| 1596 | cursor.execute(query) |
|
| 1597 | rows_energy_categories = cursor.fetchall() |
|
| 1598 | ||
| 1599 | energy_category_dict = dict() |
|
| 1600 | if rows_energy_categories is not None and len(rows_energy_categories) > 0: |
|
| 1601 | for row in rows_energy_categories: |
|
| 1602 | energy_category_dict[row[0]] = {"id": row[0], |
|
| 1603 | "name": row[1], |
|
| 1604 | "uuid": row[2]} |
|
| 1605 | ||
| 1606 | query = (" SELECT m.id, m.name, m.uuid, m.energy_category_id, em.is_output " |
|
| 1607 | " FROM tbl_equipments e, tbl_equipments_offline_meters em, tbl_offline_meters m " |
|
| 1608 | " WHERE em.equipment_id = e.id AND m.id = em.offline_meter_id AND e.id = %s " |
|
| 1609 | " ORDER BY m.id ") |
|
| 1610 | cursor.execute(query, (id_,)) |
|
| 1611 | rows = cursor.fetchall() |
|
| 1612 | ||
| 1613 | result = list() |
|
| 1614 | if rows is not None and len(rows) > 0: |
|
| 1615 | for row in rows: |
|
| 1616 | meta_result = {"id": row[0], |
|
| 1617 | "name": row[1], |
|
| 1618 | "uuid": row[2], |
|
| 1619 | "energy_category": energy_category_dict.get(row[3], None), |
|
| 1620 | "is_output": bool(row[4])} |
|
| 1621 | result.append(meta_result) |
|
| 1622 | ||
| 1623 | resp.text = json.dumps(result) |
|
| 1624 | ||
| 1625 | @staticmethod |
|
| 1626 | @user_logger |
|
| 1627 | def on_post(req, resp, id_): |
|
| 1628 | """Handles POST requests""" |
|
| 1629 | admin_control(req) |
|
| 1630 | try: |
|
| 1631 | raw_json = req.stream.read().decode('utf-8') |
|
| 1632 | except Exception as ex: |
|
| 1633 | print(str(ex)) |
|
| 1634 | raise falcon.HTTPError(status=falcon.HTTP_400, |
|
| 1635 | title='API.BAD_REQUEST', |
|
| 1636 | description='API.FAILED_TO_READ_REQUEST_STREAM') |
|
| 1637 | ||
| 1638 | if not id_.isdigit() or int(id_) <= 0: |
|
| 1639 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1640 | description='API.INVALID_EQUIPMENT_ID') |
|
| 1641 | ||
| 1642 | new_values = json.loads(raw_json) |
|
| 1643 | ||
| 1644 | if 'offline_meter_id' not in new_values['data'].keys() or \ |
|
| 1645 | not isinstance(new_values['data']['offline_meter_id'], int) or \ |
|
| 1646 | new_values['data']['offline_meter_id'] <= 0: |
|
| 1647 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1648 | description='API.INVALID_OFFLINE_METER_ID') |
|
| 1649 | offline_meter_id = new_values['data']['offline_meter_id'] |
|
| 1650 | ||
| 1651 | if 'is_output' not in new_values['data'].keys() or \ |
|
| 1652 | not isinstance(new_values['data']['is_output'], bool): |
|
| 1653 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1654 | description='API.INVALID_IS_OUTPUT_VALUE') |
|
| 1655 | is_output = new_values['data']['is_output'] |
|
| 1656 | ||
| 1657 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 1658 | cursor = cnx.cursor() |
|
| 1659 | ||
| 1660 | cursor.execute(" SELECT name " |
|
| 1661 | " from tbl_equipments " |
|
| 1662 | " WHERE id = %s ", (id_,)) |
|
| 1663 | if cursor.fetchone() is None: |
|
| 1664 | cursor.close() |
|
| 1665 | cnx.close() |
|
| 1666 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1667 | description='API.EQUIPMENT_NOT_FOUND') |
|
| 1668 | ||
| 1669 | cursor.execute(" SELECT name " |
|
| 1670 | " FROM tbl_offline_meters " |
|
| 1671 | " WHERE id = %s ", (offline_meter_id,)) |
|
| 1672 | if cursor.fetchone() is None: |
|
| 1673 | cursor.close() |
|
| 1674 | cnx.close() |
|
| 1675 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1676 | description='API.OFFLINE_METER_NOT_FOUND') |
|
| 1677 | ||
| 1678 | query = (" SELECT id " |
|
| 1679 | " FROM tbl_equipments_offline_meters " |
|
| 1680 | " WHERE equipment_id = %s AND offline_meter_id = %s") |
|
| 1681 | cursor.execute(query, (id_, offline_meter_id,)) |
|
| 1682 | if cursor.fetchone() is not None: |
|
| 1683 | cursor.close() |
|
| 1684 | cnx.close() |
|
| 1685 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.ERROR', |
|
| 1686 | description='API.EQUIPMENT_OFFLINE_METER_RELATION_EXISTS') |
|
| 1687 | ||
| 1688 | add_row = (" INSERT INTO tbl_equipments_offline_meters (equipment_id, offline_meter_id, is_output ) " |
|
| 1689 | " VALUES (%s, %s, %s) ") |
|
| 1690 | cursor.execute(add_row, (id_, offline_meter_id, is_output)) |
|
| 1691 | cnx.commit() |
|
| 1692 | cursor.close() |
|
| 1693 | cnx.close() |
|
| 1694 | ||
| 1695 | resp.status = falcon.HTTP_201 |
|
| 1696 | resp.location = '/equipments/' + str(id_) + '/offlinemeters/' + str(offline_meter_id) |
|
| 1697 | ||
| 1698 | ||
| 1699 | class EquipmentOfflineMeterItem: |
|
| 1700 | def __init__(self): |
|
| @@ 1359-1496 (lines=138) @@ | ||
| 1356 | resp.status = falcon.HTTP_200 |
|
| 1357 | ||
| 1358 | ||
| 1359 | class EquipmentMeterCollection: |
|
| 1360 | def __init__(self): |
|
| 1361 | pass |
|
| 1362 | ||
| 1363 | @staticmethod |
|
| 1364 | def on_options(req, resp, id_): |
|
| 1365 | _ = req |
|
| 1366 | resp.status = falcon.HTTP_200 |
|
| 1367 | _ = id_ |
|
| 1368 | ||
| 1369 | @staticmethod |
|
| 1370 | def on_get(req, resp, id_): |
|
| 1371 | if 'API-KEY' not in req.headers or \ |
|
| 1372 | not isinstance(req.headers['API-KEY'], str) or \ |
|
| 1373 | len(str.strip(req.headers['API-KEY'])) == 0: |
|
| 1374 | access_control(req) |
|
| 1375 | else: |
|
| 1376 | api_key_control(req) |
|
| 1377 | if not id_.isdigit() or int(id_) <= 0: |
|
| 1378 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1379 | description='API.INVALID_EQUIPMENT_ID') |
|
| 1380 | ||
| 1381 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 1382 | cursor = cnx.cursor() |
|
| 1383 | ||
| 1384 | cursor.execute(" SELECT name " |
|
| 1385 | " FROM tbl_equipments " |
|
| 1386 | " WHERE id = %s ", (id_,)) |
|
| 1387 | if cursor.fetchone() is None: |
|
| 1388 | cursor.close() |
|
| 1389 | cnx.close() |
|
| 1390 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1391 | description='API.EQUIPMENT_NOT_FOUND') |
|
| 1392 | ||
| 1393 | query = (" SELECT id, name, uuid " |
|
| 1394 | " FROM tbl_energy_categories ") |
|
| 1395 | cursor.execute(query) |
|
| 1396 | rows_energy_categories = cursor.fetchall() |
|
| 1397 | ||
| 1398 | energy_category_dict = dict() |
|
| 1399 | if rows_energy_categories is not None and len(rows_energy_categories) > 0: |
|
| 1400 | for row in rows_energy_categories: |
|
| 1401 | energy_category_dict[row[0]] = {"id": row[0], |
|
| 1402 | "name": row[1], |
|
| 1403 | "uuid": row[2]} |
|
| 1404 | ||
| 1405 | query = (" SELECT m.id, m.name, m.uuid, m.energy_category_id, em.is_output " |
|
| 1406 | " FROM tbl_equipments e, tbl_equipments_meters em, tbl_meters m " |
|
| 1407 | " WHERE em.equipment_id = e.id AND m.id = em.meter_id AND e.id = %s " |
|
| 1408 | " ORDER BY m.id ") |
|
| 1409 | cursor.execute(query, (id_,)) |
|
| 1410 | rows = cursor.fetchall() |
|
| 1411 | ||
| 1412 | result = list() |
|
| 1413 | if rows is not None and len(rows) > 0: |
|
| 1414 | for row in rows: |
|
| 1415 | meta_result = {"id": row[0], |
|
| 1416 | "name": row[1], |
|
| 1417 | "uuid": row[2], |
|
| 1418 | "energy_category": energy_category_dict.get(row[3], None), |
|
| 1419 | "is_output": bool(row[4])} |
|
| 1420 | result.append(meta_result) |
|
| 1421 | ||
| 1422 | resp.text = json.dumps(result) |
|
| 1423 | ||
| 1424 | @staticmethod |
|
| 1425 | @user_logger |
|
| 1426 | def on_post(req, resp, id_): |
|
| 1427 | """Handles POST requests""" |
|
| 1428 | admin_control(req) |
|
| 1429 | try: |
|
| 1430 | raw_json = req.stream.read().decode('utf-8') |
|
| 1431 | except Exception as ex: |
|
| 1432 | print(str(ex)) |
|
| 1433 | raise falcon.HTTPError(status=falcon.HTTP_400, |
|
| 1434 | title='API.BAD_REQUEST', |
|
| 1435 | description='API.FAILED_TO_READ_REQUEST_STREAM') |
|
| 1436 | ||
| 1437 | if not id_.isdigit() or int(id_) <= 0: |
|
| 1438 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1439 | description='API.INVALID_EQUIPMENT_ID') |
|
| 1440 | ||
| 1441 | new_values = json.loads(raw_json) |
|
| 1442 | ||
| 1443 | if 'meter_id' not in new_values['data'].keys() or \ |
|
| 1444 | not isinstance(new_values['data']['meter_id'], int) or \ |
|
| 1445 | new_values['data']['meter_id'] <= 0: |
|
| 1446 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1447 | description='API.INVALID_METER_ID') |
|
| 1448 | meter_id = new_values['data']['meter_id'] |
|
| 1449 | ||
| 1450 | if 'is_output' not in new_values['data'].keys() or \ |
|
| 1451 | not isinstance(new_values['data']['is_output'], bool): |
|
| 1452 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1453 | description='API.INVALID_IS_OUTPUT_VALUE') |
|
| 1454 | is_output = new_values['data']['is_output'] |
|
| 1455 | ||
| 1456 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 1457 | cursor = cnx.cursor() |
|
| 1458 | ||
| 1459 | cursor.execute(" SELECT name " |
|
| 1460 | " from tbl_equipments " |
|
| 1461 | " WHERE id = %s ", (id_,)) |
|
| 1462 | if cursor.fetchone() is None: |
|
| 1463 | cursor.close() |
|
| 1464 | cnx.close() |
|
| 1465 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1466 | description='API.EQUIPMENT_NOT_FOUND') |
|
| 1467 | ||
| 1468 | cursor.execute(" SELECT name " |
|
| 1469 | " FROM tbl_meters " |
|
| 1470 | " WHERE id = %s ", (meter_id,)) |
|
| 1471 | if cursor.fetchone() is None: |
|
| 1472 | cursor.close() |
|
| 1473 | cnx.close() |
|
| 1474 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1475 | description='API.METER_NOT_FOUND') |
|
| 1476 | ||
| 1477 | query = (" SELECT id " |
|
| 1478 | " FROM tbl_equipments_meters " |
|
| 1479 | " WHERE equipment_id = %s AND meter_id = %s") |
|
| 1480 | cursor.execute(query, (id_, meter_id,)) |
|
| 1481 | if cursor.fetchone() is not None: |
|
| 1482 | cursor.close() |
|
| 1483 | cnx.close() |
|
| 1484 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.ERROR', |
|
| 1485 | description='API.EQUIPMENT_METER_RELATION_EXISTS') |
|
| 1486 | ||
| 1487 | add_row = (" INSERT INTO tbl_equipments_meters (equipment_id, meter_id, is_output ) " |
|
| 1488 | " VALUES (%s, %s, %s) ") |
|
| 1489 | cursor.execute(add_row, (id_, meter_id, is_output)) |
|
| 1490 | cnx.commit() |
|
| 1491 | cursor.close() |
|
| 1492 | cnx.close() |
|
| 1493 | ||
| 1494 | resp.status = falcon.HTTP_201 |
|
| 1495 | resp.location = '/equipments/' + str(id_) + '/meters/' + str(meter_id) |
|
| 1496 | ||
| 1497 | ||
| 1498 | class EquipmentMeterItem: |
|
| 1499 | def __init__(self): |
|