Ejemplo n.º 1
0
    def set_settings(self, db_session: Session, setting_to_set: SettingSet):
        new_setting = Setting(welcome_speech=setting_to_set.welcome_speech,
                              color_button=setting_to_set.color_button,
                              community_id=setting_to_set.community_id)

        db_session.add(new_setting)
        db_session.commit()
        db_session.refresh(new_setting)
        return new_setting
Ejemplo n.º 2
0
    def add_time_table(self, db_session: Session, time_to_set: TimeTableSet):
        new_time_table = TimeTable(manager_id=time_to_set.manager_id,
                                   day_of_the_week=time_to_set.day_of_the_week,
                                   start_work=time_to_set.start_work,
                                   end_work=time_to_set.end_work)

        db_session.add(new_time_table)
        db_session.commit()
        db_session.refresh(new_time_table)
        return new_time_table
Ejemplo n.º 3
0
    def update_settings(self, db_session: Session, community_id: int,
                        setting_to_update: SettingUpdate):
        update_setting = db_session.query(Setting).filter_by(
            community_id=community_id).first()
        if update_setting is None:
            raise NoResultFound('Setting not found')

        update_setting.welcome_speech = setting_to_update.welcome_speech
        update_setting.color_button = setting_to_update.color_button

        db_session.add(update_setting)
        db_session.commit()
        db_session.refresh(update_setting)
        return update_setting
Ejemplo n.º 4
0
    def add_manager(self, db_session: Session, community_id: int,
                    manager_to_add: ManagerCreate):
        community = (db_session.query(Community).options(
            lazyload("managers")).get(community_id))
        manager = Manager(
            phone=manager_to_add.phone,
            name=manager_to_add.name,
            is_blocked=manager_to_add.is_blocked,
        )

        community.managers.append(manager)
        db_session.add(community)
        db_session.commit()
        db_session.refresh(community)
        return community
Ejemplo n.º 5
0
    def update_time_table(self, db_session: Session, time_table_id: int,
                          time_to_update: TimeTableUpdate):
        update_time = db_session.query(TimeTable).filter_by(
            id=time_table_id).first()
        if update_time is None:
            raise NoResultFound('Time Table not found')

        update_time.day_of_the_week = time_to_update.day_of_the_week
        update_time.start_work = time_to_update.start_work
        update_time.end_work = time_to_update.end_work

        db_session.add(update_time)
        db_session.commit()
        db_session.refresh(update_time)
        return update_time
Ejemplo n.º 6
0
    def create(self, db_session: Session, community_to_create: CommunityCreate,
               user_id: int):
        info = services.vk_service.get_community_info(
            community_to_create.api_key, community_to_create.community_vk_id)
        community = Community(
            community_vk_id=community_to_create.community_vk_id,
            avatar_url=info["photo_200"],
            name=info["name"],
        )

        user = db_session.query(User).get(user_id)
        if user is not None:
            community.admins.append(user)

        db_session.add(community)
        db_session.commit()
        db_session.refresh(community)
        return community
Ejemplo n.º 7
0
	def create_user(self, db_session: Session, user_to_create: UserCreate):
		existing_user = self.get_by_username(db_session, user_to_create.username)
		if existing_user is not None:
			raise Exception('User already exists')
		
		new_user = User(
			username=user_to_create.username,
			first_name=user_to_create.first_name,
			last_name=user_to_create.last_name,
			is_admin=user_to_create.is_admin,
			vk_id=user_to_create.vk_id,
			avatar_url=user_to_create.avatar_url,
			email=user_to_create.email,
			phone=user_to_create.phone,
			password=user_to_create.password,
		)

		new_user.set_password(user_to_create.password)
		db_session.add(new_user)
		db_session.commit()
		db_session.refresh(new_user)
		return new_user