def insert_provider(self, json_input):
     if len(json_input
            ) != 2:  # check if there are sufficient elements in input
         return jsonify(Error="Malformed insert provider request"), 400
     try:  # check parameters are valid
         puser = json_input['puser']
         prequest = json_input['prequest']
     except:
         return jsonify(
             Error="Unexpected attributes in insert provider request"), 400
     try:
         if puser and prequest:
             # Validate that puser != ruser:
             if puser == RequestHandler.create_request_dict(
                     RequestDAO().get_request_by_id(prequest))['ruser']:
                 return jsonify(
                     Error="User cannot provide his own request"), 400
             # Insert provider
             dao = ProviderDAO()
             pid = dao.insert_provider(puser, prequest)
             # Update status of request
             form = {}
             form['prequest'] = prequest
             form[
                 'rstatus'] = 'InProgress'  #  YELLOW, its updated to delivery on it's way.
             self.update_request_status_by_provider(form)
         else:
             return jsonify(Error="One or more attribute is empty"), 400
     except:
         return jsonify(Error="Provider insertion failed horribly."), 400
     # Finally returns an user dict of the inserted provider.
     return jsonify(
         Provider=self.createProviderDict([pid, puser, prequest])), 201
コード例 #2
0
 def insert_provider(self, json_input):
     if len(json_input
            ) != 2:  # check if there are sufficient elements in input
         return jsonify(Error="Malformed insert provider request"), 400
     try:  # check parameters are valid
         puser = json_input['puser']
         prequest = json_input['prequest']
     except:
         return jsonify(
             Error="Unexpected attributes in insert provider request"), 400
     try:
         if puser and prequest:
             dao = ProviderDAO()
             pid = dao.insert_provider(puser, prequest)
         else:
             return jsonify(Error="One or more attribute is empty"), 400
     except:
         return jsonify(Error="Provider insertion failed horribly."), 400
     # Finally returns an user dict of the inserted user.
     return jsonify(
         Provider=self.createProviderDict([pid, puser, prequest])), 201