async def post(self, *args, **kwargs) -> Response: json_body = await self.deserialize_body() team = Team() name = json_body.get('name') if name: team.name = name user_ids = json_body['users'] users = [] for user_id in user_ids: user = User.get_item(int(user_id)) if not user: raise UserNotFound users.append(user) team.users = users team.save() result = await self.serialize(data=team) return await self.to_response(result, status_code=201)
async def post(self, *args, **kwargs) -> Response: json_body = await self.deserialize_body() name = json_body.get('name') user_ids = json_body['users'] users = [] for user_id in user_ids: try: user = self.db_session.query(User).filter_by( id=int(user_id)).one() except NoResultFound: raise UserNotFound users.append(user) team = Team(name=name) team.users = users self.db_session.add(team) self.db_session.commit() result = await self.serialize(data=team) return await self.to_response(result, status_code=201)