def getClothById(self, cloth_id): dao = ClothDAO() row = dao.getClothById(cloth_id) if not row: return jsonify(Error="Cloth Not Found"), 404 else: cloth = self.build_cloth_dict(row) return jsonify(Cloth=cloth)
def deleteCloth(self, cloth_id): cloth_dao = ClothDAO() if not cloth_dao.getClothById(cloth_id): return jsonify(Error="Cloth not found."), 404 else: resource_id = cloth_dao.delete(cloth_id) resource_dao = ResourceDAO() resource_dao.delete(resource_id) return jsonify(DeleteStatus="OK"), 200
def getClothAddress(self, cloth_id): cloth_dao = ClothDAO() try: supplier_id = cloth_dao.getClothById(cloth_id)[7] except Exception: return jsonify(Error="Cloth not found."), 404 supplier_dao = SupplierDAO() if not supplier_dao.getSupplierById(supplier_id): return jsonify(Error="Supplier not found."), 404 else: row = cloth_dao.getClothAddress(supplier_id) if not row: return jsonify(Error="Address Not Found"), 404 else: address = self.build_address_dict(row) return jsonify(Address=address)
def updateCloth(self, cloth_id, json): cloth_dao = ClothDAO() if not cloth_dao.getClothById(cloth_id): return jsonify(Error="Cloth not found."), 404 else: supplier_id = json["supplier_id"] category_id = json["category_id"] cloth_name = json["cloth_name"] cloth_brand = json["cloth_brand"] cloth_quantity = json["cloth_quantity"] cloth_price = json["cloth_price"] cloth_size = json["cloth_size"] cloth_material = json["cloth_material"] cloth_condition = json["cloth_condition"] cloth_gender = json["cloth_gender"] cloth_type = json["cloth_type"] if supplier_id and category_id and cloth_name and cloth_brand and cloth_quantity and ( cloth_price >= 0 ) and cloth_size and cloth_material and cloth_condition and cloth_gender and cloth_type: resource_id = cloth_dao.update(cloth_id, cloth_size, cloth_material, cloth_condition, cloth_gender, cloth_type) resource_dao = ResourceDAO() resource_dao.update(resource_id, supplier_id, category_id, cloth_name, cloth_brand, cloth_quantity, cloth_price) result = self.build_cloth_attributes( cloth_id, resource_id, supplier_id, category_id, cloth_name, cloth_brand, cloth_quantity, cloth_price, cloth_size, cloth_material, cloth_condition, cloth_gender, cloth_type) return jsonify(Cloth=result), 200 else: return jsonify( Error="Unexpected attributes in update request"), 400