def HandleCarUpdate(self, id): if "userId" not in self.session: self.Handle401() return length = int(self.headers["Content-length"]) body = self.rfile.read(length).decode("utf-8") parsed_body = parse_qs(body) db = CarsDB() if db.getCar(id) == None: self.Handle404() return owner_name = parsed_body['owner_name'][0] year = parsed_body['year'][0] make = parsed_body['make'][0] model = parsed_body['model'][0] color = parsed_body['color'][0] platenumber = parsed_body['platenumber'][0] db.getUpdate(id, owner_name, year, make, model, color, platenumber) self.send_response(200) self.end_headers() self.wfile.write(bytes("Updated", "utf-8")) return
def HandleCarRetrieve(self, id): if "userId" not in self.session: self.Handle401() return db = CarsDB() car = db.getCar(id) if car == None: self.Handle404() return json_string = json.dumps(car) print("JSON String", json_string) self.send_response(200) self.send_header("Content-Type", "application/json") self.end_headers() self.wfile.write(bytes(json_string, "utf-8")) return