@@ 140-169 (lines=30) @@ | ||
137 | def on_options(req, resp, id_): |
|
138 | resp.status = falcon.HTTP_200 |
|
139 | ||
140 | @staticmethod |
|
141 | def on_get(req, resp, id_): |
|
142 | if not id_.isdigit() or int(id_) <= 0: |
|
143 | raise falcon.HTTPError(falcon.HTTP_400, |
|
144 | title='API.BAD_REQUEST', |
|
145 | description='API.INVALID_OFFLINE_METER_FILE_ID') |
|
146 | ||
147 | cnx = mysql.connector.connect(**config.myems_historical_db) |
|
148 | cursor = cnx.cursor() |
|
149 | ||
150 | query = (" SELECT id, file_name, uuid, upload_datetime_utc, status " |
|
151 | " FROM tbl_offline_meter_files " |
|
152 | " WHERE id = %s ") |
|
153 | cursor.execute(query, (id_,)) |
|
154 | row = cursor.fetchone() |
|
155 | cursor.close() |
|
156 | cnx.disconnect() |
|
157 | if row is None: |
|
158 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
159 | description='API.OFFLINE_METER_FILE_NOT_FOUND') |
|
160 | ||
161 | upload_datetime = row[3] |
|
162 | upload_datetime = upload_datetime.replace(tzinfo=timezone.utc) |
|
163 | ||
164 | result = {"id": row[0], |
|
165 | "file_name": row[1], |
|
166 | "uuid": row[2], |
|
167 | "upload_datetime": upload_datetime.timestamp() * 1000, |
|
168 | "status": row[4]} |
|
169 | resp.body = json.dumps(result) |
|
170 | ||
171 | @staticmethod |
|
172 | def on_delete(req, resp, id_): |
@@ 112-140 (lines=29) @@ | ||
109 | def on_options(req, resp, id_): |
|
110 | resp.status = falcon.HTTP_200 |
|
111 | ||
112 | @staticmethod |
|
113 | def on_get(req, resp, id_): |
|
114 | if not id_.isdigit() or int(id_) <= 0: |
|
115 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
116 | description='API.INVALID_METER_ID') |
|
117 | ||
118 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
119 | cursor = cnx.cursor(dictionary=True) |
|
120 | ||
121 | query = (" SELECT id, name, uuid, " |
|
122 | " svg, description " |
|
123 | " FROM tbl_distribution_systems " |
|
124 | " WHERE id = %s ") |
|
125 | cursor.execute(query, (id_,)) |
|
126 | row = cursor.fetchone() |
|
127 | cursor.close() |
|
128 | cnx.disconnect() |
|
129 | ||
130 | if row is None: |
|
131 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
132 | description='API.DISTRIBUTION_SYSTEM_NOT_FOUND') |
|
133 | else: |
|
134 | meta_result = {"id": row['id'], |
|
135 | "name": row['name'], |
|
136 | "uuid": row['uuid'], |
|
137 | "svg": row['svg'], |
|
138 | "description": row['description']} |
|
139 | ||
140 | resp.body = json.dumps(meta_result) |
|
141 | ||
142 | @staticmethod |
|
143 | def on_delete(req, resp, id_): |
@@ 127-154 (lines=28) @@ | ||
124 | def on_options(req, resp, id_): |
|
125 | resp.status = falcon.HTTP_200 |
|
126 | ||
127 | @staticmethod |
|
128 | def on_get(req, resp, id_): |
|
129 | if not id_.isdigit() or int(id_) <= 0: |
|
130 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
131 | description='API.INVALID_CONTACT_ID') |
|
132 | ||
133 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
134 | cursor = cnx.cursor() |
|
135 | ||
136 | query = (" SELECT id, name, uuid, email, phone, description " |
|
137 | " FROM tbl_contacts " |
|
138 | " WHERE id = %s ") |
|
139 | cursor.execute(query, (id_,)) |
|
140 | row = cursor.fetchone() |
|
141 | cursor.close() |
|
142 | cnx.disconnect() |
|
143 | ||
144 | if row is None: |
|
145 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
146 | description='API.CONTACT_NOT_FOUND') |
|
147 | ||
148 | result = {"id": row[0], |
|
149 | "name": row[1], |
|
150 | "uuid": row[2], |
|
151 | "email": row[3], |
|
152 | "phone": row[4], |
|
153 | "description": row[5]} |
|
154 | resp.body = json.dumps(result) |
|
155 | ||
156 | @staticmethod |
|
157 | def on_delete(req, resp, id_): |
@@ 117-143 (lines=27) @@ | ||
114 | def on_options(req, resp, id_): |
|
115 | resp.status = falcon.HTTP_200 |
|
116 | ||
117 | @staticmethod |
|
118 | def on_get(req, resp, id_): |
|
119 | if not id_.isdigit() or int(id_) <= 0: |
|
120 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
121 | description='API.INVALID_ENERGY_CATEGORY_ID') |
|
122 | ||
123 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
124 | cursor = cnx.cursor() |
|
125 | ||
126 | query = (" SELECT id, name, uuid, unit_of_measure, kgce, kgco2e " |
|
127 | " FROM tbl_energy_categories " |
|
128 | " WHERE id =%s ") |
|
129 | cursor.execute(query, (id_,)) |
|
130 | row = cursor.fetchone() |
|
131 | cursor.close() |
|
132 | cnx.disconnect() |
|
133 | if row is None: |
|
134 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
135 | description='API.ENERGY_CATEGORY_NOT_FOUND') |
|
136 | ||
137 | result = {"id": row[0], |
|
138 | "name": row[1], |
|
139 | "uuid": row[2], |
|
140 | "unit_of_measure": row[3], |
|
141 | "kgce": row[4], |
|
142 | "kgco2e": row[5]} |
|
143 | resp.body = json.dumps(result) |
|
144 | ||
145 | @staticmethod |
|
146 | def on_delete(req, resp, id_): |