def update(self): update_count = 0 for item in self.items: updated_item = self.collection.find_one_and_update({ "_id": ObjectId(item["id"]), "user_id": ObjectId(self.user_id), "name": item["name"] }, { "$set": { "details": item["details"], "comments": item["comments"] } }) if updated_item: update_count += 1 if update_count == 0: message = "No items were updated." else: message = "Successfully Updated" return response.set_ok({"message": message})
def upload(self): if self.is_gpx_file() is False: return ErrorMessage.MAP_ROUTE["INVALID_FILE_TYPE"] uploaded_file = mongo.save_file(self.file.filename, self.file) return response.set_ok({"id": str(uploaded_file)})
def create(self): documents = [dict(item, **{ "user_id": ObjectId(self.user_id), "last_updated": date_time.get_current_datetime(), "created_at": date_time.get_current_datetime(), "date": date_time.convert_datetime_str_to_obj(self.date) }) for item in self.items] created_items = self.collection.insert_many(documents) item_ids = [str(id) for id in created_items.inserted_ids] return response.set_ok(item_ids)
def get(self): if self.start_date != self.end_date: if date_time.is_before_date(self.start_date, self.end_date) is False: return response.set_error(["start_date is after end_date"]) if self.activity_id is not None: data = self.get_by_id() else: data = self.get_by_date_range() return response.set_ok(data)
def get_route(args): request_params = args route_id = request_params["route_id"] if route_id is None or query.object_id_is_valid(route_id) is False: return jsonify(response.set_error(["route_id is invalid format." ])), 400 get_response = MapRoute(request_params).get() if get_response is None: return jsonify(response.set_ok({"message": "no route found"})) return get_response