Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
2.2 kB
2
Indexable
Never
    def copy_shared_list(
            self,
            url_slug: UUID,
            name: Optional[str] = None,
            description: Optional[str] = None
    ):
        bin_url_slug = convert_uuid_to_bin(url_slug)
        records = tinyAPI.dsh().query(
            '''select insert(insert(insert(insert(
                        hex(concat(substr(venue_list_id, 5, 4), substr(venue_list_id, 3, 2), 
                        substr(venue_list_id, 1, 2), substr(venue_list_id, 9, 8))),
                        9, 0, '-'), 14, 0, '-'), 19, 0, '-'), 24, 0, '-') as venue_list_id, is_deleted from user_venue_list_slug
            where url_slug = %(url_slug)s
            ''',
            {
                'url_slug': bin_url_slug,
            }
        )

        print(records[0])
        if records[0]['is_deleted']:
            raise NotFoundError

        user_list = self.get_lists_by_user(list_id=records[0]['venue_list_id'])
        print(user_list)

        # # if there is no error start with copying
        # # first step create new list (use name and description or from list)

        new_list_id = self.create(name=name, description=description)
        venues = self.load_venues(list_id=records[0]['venue_list_id'])
        # # copy all venues to new list
        for i, venue in enumerate(venues):
            self.add_venue_to_lists(venue_id=venues[i]['id']['resy'], list_ids=[new_list_id])

        return new_list_id


   def create(
            self,
            name: str,
            description: Optional[str] = None,
            list_id: Optional[UUID] = None
    ) -> UUID:
        self.check_user_list_limit()
        list_id = list_id or uuid1()
        bin_list_id = convert_uuid_to_bin(list_id)
        if not self.user_id:
            raise multiple_list_error.UserNotVerifiedError
        tinyAPI.dsh().query(
            '''insert into user_venue_list (id, name, description, user_id) values
               (%(list_id)s, %(name)s, %(description)s, %(user_id)s)''',
            {
                'list_id': bin_list_id,
                'name': name,
                'description': description,
                'user_id': self.user_id
            }
        )
        tinyAPI.dsh().commit()
        return list_id