Пример #1
0
 def on_get(self, req: Request, resp: Response, user_id: int):
     group_id = req.get_param('group_id')
     if not group_id:
         resp.json = RESP_ERR_JSON
         return
     user = req.session.query(User).filter(User.id == user_id).first()
     group = req.session.query(Group).filter(
         Group.id == int(group_id)).first()
     if not user or not group or user not in group.users:
         resp.json = RESP_ERR_JSON
         return
     members_info = [u.to_dict() for u in group.users]
     resp.json = {'members': members_info}
Пример #2
0
 def on_post(self, req: Request, resp: Response, user_id: int):
     group_id = req.get_param('group_id')
     user = req.session.query(User).filter(User.id == user_id).first()
     group = req.session.query(Group).filter(
         Group.id == int(group_id)).first()
     if not user or not group:
         resp.json = {'status': 1}
         return
     for m in user.memberships:
         if m.group.id == int(group_id):
             req.session.delete(m)
             break
     req.session.commit()
     resp.json = {'status': 0, 'group': group.to_dict()}
Пример #3
0
    def on_get(self, req: Request, resp: Response, q_args: Dict,
               anime_id: str) -> None:
        attr_args: List[str] = q_args['only_attr'] if q_args else None
        json_result: List = self.resource.get_anime(anime_id,
                                                    wanted_attr=attr_args)

        if not json_result:
            raise falcon.HTTPNotFound(
                title='Anime not Found',
                description=f'Anime with id: {anime_id} does not exist.',
            )

        resp.json = json_result
        resp.status = falcon.HTTP_200
Пример #4
0
    def on_get(self, req: Request, resp: Response, q_args: Dict) -> None:
        anime_title = q_args['to']
        limit = q_args['limit']
        offset = q_args['offset']
        genre = q_args['by_genre'] if 'by_genre' in q_args else None
        json_result: List[Dict] = self.resource.get_similar_anime(anime_title,
                                                                  limit,
                                                                  offset,
                                                                  genre=genre)

        if not json_result:
            raise falcon.HTTPNotFound(
                title='Animes not Found',
                description=
                f'No animes are similar to {anime_title} by {genre}',
            )

        resp.json = json_result
        resp.status = falcon.HTTP_200
Пример #5
0
    def on_get(self, req: Request, resp: Response) -> None:

        resp.json = self.resource.get_all_anime(limit=10)
        resp.status = falcon.HTTP_200