async def method_post( self, request: Request, body: dict, session: DBSession, *args, **kwargs ) -> BaseHTTPResponse: # DTO объект request_model = RequestCreateUserDto(body) try: hashed_password = generate_hash(request_model.password) secret_word = generate_hash(request_model.secret_word) except GeneratePasswordHashException as error: raise SanicPasswordHashException(str(error)) try: # экземпляр базы данных db_user = user_queries.create_user(session, request_model, hashed_password, secret_word) session.commit_session() # ошибка уникальности, то есть подразумевается, что такой пользователь # уже существует в базе except DBUserAlreadyExistsException: return await self.make_response_json(status=409, message='User already exists') except (DBIntegrityException, DBDataException) as error: raise SanicDBException(str(error)) response_model = ResponseGetUserDto(db_user) return await self.make_response_json( body=response_model.dump(), status=201 )
async def method_post(self, request: Request, body: dict, session, *args, **kwargs) -> BaseHTTPResponse: request_model = RequestCreateUserDto(body) try: hashed_password = generate_hash(request_model.password) except GeneratePasswordHashException as e: raise SanicPasswordHashException(str(e)) try: db_user = user_queries.create_user(session, request_model, hashed_password) except DBUserExistsException: raise SanicUserConflictException('Login is busy') try: session.commit_session() except (DBDataException, DBIntegrityException) as e: raise SanicDBException(str(e)) response_model = ResponseUserDto(db_user) return await self.make_response_json(body=response_model.dump(), status=201)
async def method_post(self, request: Request, body: dict, session, *args, **kwargs) -> BaseHTTPResponse: request_model = RequestCreateUserDto(body) db_user = user_queries.create_user(session, request_model) try: session.commit_session() except DBIntegrityException: return await self.make_response_json( body={"Error message": "such a login exists"}, status=409) response_model = ResponseUserDto(db_user) return await self.make_response_json(body=response_model.dump(), status=201)
async def method_post(self, request: Request, body: dict, session: DBSession, *args, **kwargs) -> BaseHTTPResponse: request_model = RequestCreateUserDto(body) try: hashed_password = generate_hash(request_model.password) user_queries.create_user(session=session, user=request_model, hashed_password=hashed_password) session.commit_session() except GeneratePasswordHashException as error: raise SanicPasswordHashException(str(error)) except DBLoginExistsException: raise SanicLoginExistsException('login exits') except (DBDataError, DBIntegrityError) as error: raise SanicDBException(str(error)) return await self.make_response_json(status=201)