示例#1
0
    def add_tag(self, title_uuid, tag_uuid, add=True):
        title_uuid = is_valid_uuid_string(title_uuid)
        tag_uuid = is_valid_uuid_string(tag_uuid)

        title = yield self.store.get(title_uuid)

        if not title:
            raise ResourceNotFoundError('Title not found')

        tag_list = list(title.tags)
        if add is True:
            if tag_uuid not in tag_list:
                tag_list.append(tag_uuid)
        else:
            if tag_uuid in tag_list:
                tag_list.remove(tag_uuid)

        update_dict = {'tags': tag_list}
        self.store.update(title_uuid, update_dict)

        logger.info(dict(
            title_uuid=title_uuid,
            tag_uuid=tag_uuid,
            add=add,
            method='add_tag',
        ))
        raise Return()
示例#2
0
    def like_star(self, user_uuid, star_uuid, like):
        user_uuid = is_valid_uuid_string(user_uuid)
        star_uuid = is_valid_uuid_string(star_uuid)

        update_dict = {'liked_stars': {}}
        update_dict['liked_stars'][star_uuid] = like
        self.store.update(user_uuid, update_dict)

        logger.info(dict(
            user_uuid=user_uuid,
            star_uuid=star_uuid,
            like=like,
            method='like_star',
        ))
        raise Return()
示例#3
0
    def like_title(self, user_uuid, title_uuid, like):
        user_uuid = is_valid_uuid_string(user_uuid)
        title_uuid = is_valid_uuid_string(title_uuid)

        update_dict = {'liked_titles': {}}
        update_dict['liked_titles'][title_uuid] = like
        self.store.update(user_uuid, update_dict)

        logger.info(dict(
            user_uuid=user_uuid,
            title_uuid=title_uuid,
            like=like,
            method='like_title',
        ))
        raise Return()
    def test_is_valid_uuid_string(self):
        assert is_valid_uuid_string(self.valid_uuid) == self.valid_uuid

        try:
            is_valid_uuid_string('not a valid uuid')
        except Invalid:
            pass
        else:
            raise AssertionError('Expected test to raise Invalid.')

        try:
            is_valid_uuid_string([])
        except Invalid:
            pass
        else:
            raise AssertionError('Expected test to raise Invalid.')
示例#5
0
    def get_all_by_tag(self, tag_uuid):
        tag_uuid = is_valid_uuid_string(tag_uuid)

        log_info = dict(
            tag_uuid=tag_uuid,
            method='get_all_by_tag',
        )

        titles = yield self.store.get_all_by_tag(tag_uuid)
        logger.info(log_info)
        raise Return(titles)
示例#6
0
    def get_tags_by_title(self, title_uuid):
        log_info = dict(
            uuid=title_uuid,
            method='get_tags_by_title',
        )

        title_uuid = is_valid_uuid_string(title_uuid)

        title = yield self.store.get(title_uuid)
        if not title:
            log_info.update({'error': 'title not found'})
            logger.exception(log_info)
            raise ResourceNotFoundError(log_info.get('error'))

        tag_list = list(getattr(title, 'tags'))

        tags = yield self.tag_store.get_all_by_uuids(tag_list)
        logger.info(log_info)
        raise Return(tags)
示例#7
0
    def get_all_liked_stars(self, user_uuid):
        log_info = dict(
            user_uuid=user_uuid,
            method='get_all_liked_stars',
        )

        user_uuid = is_valid_uuid_string(user_uuid)

        user = yield self.store.get(user_uuid)
        if not user:
            log_info.update({'error': 'user not found'})
            logger.exception(log_info)
            raise ResourceNotFoundError(log_info.get('error'))

        if not user.liked_stars:
            star_uuids = []
        else:
            star_uuids = list(filter(lambda uuid: user.liked_stars[uuid], user.liked_stars))

        stars = yield self.star_store.get_all_by_uuids(star_uuids)

        logger.info(log_info)
        raise Return(stars)
示例#8
0
 def get(cls, uuid):
     uuid = is_valid_uuid_string(uuid)
     logger.info("Accessed {} with UUID".format(uuid))
     q = cls.query().filter_by(uuid=uuid)
     return q.first()