def post(self, key, item_type, item_key): # updates an existing profile item user_id = g.model_db.id() profile = Profile.get_by('user_id', user_id) if auth.current_user_db().id( ) != user_id: # check profile belongs to current_user return ApiException.error(108) return self.update_item(profile, item_type, item_key)
def put(self, key): user_id = g.model_db.id() profile = Profile.get_by('user_id', user_id) if auth.current_user_db().id() != user_id: # logged in return ApiException.error(108) new_profile_data = _.pick(request.json, Profile.ALL_NON_STRUCTURED_PROPERTIES) profile.populate(**new_profile_data) profile.put() return profile.to_dict(include=profile.get_all_properties())
def delete(self, key, item_type, item_key): user_id = g.model_db.id() profile = Profile.get_by('user_id', user_id) if auth.current_user_db().id( ) != user_id: # check profile belongs to current_user return ApiException.error(108) ModelClass = Profile.ALL_STRUCTURED_PROPERTIES.get(item_type) success, value = ModelClass.delete(profile, item_key) if success: return value else: return ApiException.error(200, value)
def post(self, key, item_type): user_id = g.model_db.id() profile = Profile.get_by('user_id', user_id) if auth.current_user_db().id( ) != user_id: # check profile belongs to current_user return ApiException.error(108) ModelClass = Profile.ALL_STRUCTURED_PROPERTIES.get(item_type) data = request.json if not data: return ApiException.error(200) success, value = ModelClass.create(profile, data) if success: return value else: return ApiException.error(200, value)