Skip to content

Commit

Permalink
create org auth if user does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
AlisoSouza committed Dec 20, 2024
1 parent a801116 commit ea20259
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions nexus/orgs/consumers/org_auth_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,32 @@

from nexus.orgs.org_dto import OrgAuthCreationDTO
from nexus.usecases.orgs.create import CreateOrgAuthUseCase
from nexus.usecases.users.create import CreateUserUseCase
from nexus.usecases.users.exceptions import UserDoesNotExists

from nexus.event_driven.parsers import JSONParser
from nexus.event_driven.consumer.consumers import EDAConsumer


class OrgAuthConsumer(EDAConsumer):
def consume(self, message: amqp.Message):
print(f"[OrgAuthConsumer] - Consuming a message. Body: {message.body}")
def create():
org_auth_creation = CreateOrgAuthUseCase()
org_auth_creation.create_org_auth_with_dto(org_auth_dto=org_auth_dto)
message.channel.basic_ack(message.delivery_tag)
print(f"[OrgAuthConsumer] - Org Auth created: {org_auth_dto.org_uuid}")
try:
print(f"[OrgAuthConsumer] - Consuming a message. Body: {message.body}")
body = JSONParser.parse(message.body)
org_auth_dto = OrgAuthCreationDTO(
org_uuid=body.get("organization_uuid"),
user_email=body.get("user_email"),
role=body.get("role")
)
org_auth_creation = CreateOrgAuthUseCase()
org_auth_creation.create_org_auth_with_dto(org_auth_dto=org_auth_dto)

message.channel.basic_ack(message.delivery_tag)
print(f"[OrgAuthConsumer] - Org Auth created: {org_auth_dto.org_uuid}")
create()
except UserDoesNotExists:
CreateUserUseCase().create_user(org_auth_dto.email)
create(org_auth_dto)
except Exception as exception:
capture_exception(exception)
message.channel.basic_reject(message.delivery_tag, requeue=False)
Expand Down

0 comments on commit ea20259

Please sign in to comment.