def getClothesById(self, rid):

        dao = ClothesDAO()
        row = dao.getClothesById(rid)
        if not row:
            return jsonify(Error="Clothes Not Found"), 404
        else:
            clothes = self.build_clothes_dict(row)
        return jsonify(Clothes=clothes)
    def getAllClothes(self):

        dao = ClothesDAO()
        clothes_list = dao.getAllClothes()
        result_list = []
        for row in clothes_list:
            result = self.build_clothes_dict(row)
            result_list.append(result)
        return jsonify(Clothes=result_list)
 def getClothesSuppliersByRegion(self, region):
     dao = ClothesDAO()
     suppliers_list = dao.getClothesSuppliersByRegion(region)
     if not suppliers_list:
         return jsonify(Error="No Suppliers found"), 404
     else:
         result_list = []
         for row in suppliers_list:
             result = self.build_supplierclothes_dict(row)
             result_list.append(result)
     return jsonify(Suppliers=result_list)
    def getClothesBySize(self, size):

        dao = ClothesDAO()
        clothes_list = dao.getClothesBySize(size)
        if not clothes_list:
            return jsonify(Error="No Clothes found"), 404
        else:
            result_list = []
            for row in clothes_list:
                result = self.build_clothes_dict(row)
                result_list.append(result)
        return jsonify(Clothes=result_list)
    def searchClothesRequests(self, args):
        if len(args) > 6:
            return jsonify(Error="Malformed search string."), 400
        else:
            rid = args.get("rid")
            price = args.get("price")
            color = args.get("color")
            size = args.get("size")
            gender = args.get("gender")
            piece = args.get("piece")

            dao = ClothesDAO()
            clothes_list = []
            if (len(args) == 1) and rid:
                clothes_list = dao.getClothesRequestsById(rid)
            elif (len(args) == 1) and price:
                clothes_list = dao.getClothesRequestsByPrice(price)
            elif (len(args) == 1) and color:
                clothes_list = dao.getClothesRequestsByColor(color)
            elif (len(args) == 1) and size:
                clothes_list = dao.getClothesRequestsBySize(size)
            elif (len(args) == 1) and gender:
                clothes_list = dao.getClothesRequestsByGender(gender)
            elif (len(args) == 1) and piece:
                clothes_list = dao.getClothesRequestsByPiece(piece)
            else:
                return jsonify(Error="Malformed query string"), 400
            result_list = []
            for row in clothes_list:
                result = self.build_requestclothes_dict(row)
                result_list.append(result)
            return jsonify(Clothes=result_list)
    def insertClothes(self, form):
        if len(form) != 7:
            return jsonify(Error="Malformed POST request"), 400
        else:
            sid = form['sid']
            qty = form['qty']
            price = form['price']
            color = form['color']
            size = form['size']
            gender = form['gender']
            piece = form['piece']

            if sid and qty and price and color and size and gender and piece:
                rid = ResourcesDAO().insert(sid, qty)
                dao = ClothesDAO()
                dao.insert(rid, price, color, size, gender, piece)
                result = self.build_clothes_attributes(rid, price, color, size,
                                                       gender, piece)
                return jsonify(Clothes=result), 201
            else:
                return jsonify(
                    Error="Unexpected attributes in POST request"), 400