예제 #1
0
    def get(self, uuid):
        log_info = dict(
            uuid=uuid,
            method='get',
        )

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

        logger.info(log_info)
        raise Return(entity)
예제 #2
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)
예제 #3
0
    def create_with_entity(self, entity):
        entity.validate()

        log_info = dict(
            uuid=entity.uuid,
            method='create_with_entity',
        )

        duplicates = yield self.check_duplicates(entity)
        if duplicates:
            log_info.update({'error': 'entity already exists'})
            logger.exception(log_info)
            raise EntityAlreadyExistsError(log_info.get('error'))

        new_created = yield self.store.create_from_entity(entity)
        logger.info(log_info)

        yield self.handle_added(new_created)
        raise Return(new_created)
예제 #4
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)