예제 #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 get_by_name(self, user_name):
        user = yield self.store.get_by_name(user_name)

        logger.info(dict(
            user_name=user_name,
            method='get_by_name',
            result_uuid=None if not user else user.uuid,
        ))
        raise Return(user)
예제 #3
0
    def get_by_id(self, title_id):
        title = yield self.store.get_by_id(title_id)

        logger.info(dict(
            title_id=title_id,
            method='get_by_id',
            result_uuid=None if not title else title.uuid,
        ))
        raise Return(title)
예제 #4
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)
예제 #5
0
    def get_by_name(self, tag_name):
        log_info = dict(
            tag_name=tag_name,
            method='get_by_name',
        )

        tag = yield self.store.get_by_name(tag_name)
        if not tag:
            log_info.update({'result': 'tag not found'})
            logger.info(log_info)
            raise Return(None)

        logger.info(log_info)
        raise Return(tag)
예제 #6
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)
예제 #7
0
    def get_by_name(self, star_name):
        log_info = dict(
            name=star_name,
            method='get_by_name',
        )

        star = yield self.store.get_by_name(star_name)
        if not star:
            log_info.update({'result': 'star not found'})
            logger.info(log_info)
            raise Return(None)

        logger.info(log_info)
        raise Return(star)
예제 #8
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()
예제 #9
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()
예제 #10
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)
예제 #11
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)
예제 #12
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)
예제 #13
0
 def get_recentlly_added_titles(self, n):
     titles = yield self.store.get_latest_created(n)
     logger.info(dict(count=n, method='get_recentlly_added_titles'))
     raise Return(titles)
예제 #14
0
 def get_all(self):
     entity = yield self.store.get_all()
     logger.info(dict(method='get_all'))
     raise Return(entity)