Skip to content
This repository has been archived by the owner on Oct 18, 2024. It is now read-only.

Commit

Permalink
night update
Browse files Browse the repository at this point in the history
  • Loading branch information
MaziniiX committed Jun 24, 2024
1 parent b71c086 commit b0af84b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
18 changes: 9 additions & 9 deletions Django_api/airline/api_common/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,24 @@ def post(self, request, *args, **kwargs):
password = request.data.get('password')
user = authenticate(username=username, password=password)
if user:
user_id_bank = user.client.id
token, created = Token.objects.get_or_create(user=user)
asyncio.run(self.banque_account_create(user_id_bank))
return Response({'token': token.key})
self.banque_account_create(Client.user.id)
else:
return Response({'error': 'Invalid Credentials'}, status=status.HTTP_400_BAD_REQUEST)

async def banque_account_create(self, user_id_bank):
global nc
env = os.getenv('DJANGO_ENVIRONMENT', 'development')
user = os.getenv('NATS_USER', '')
password = os.getenv('NATS_PASSWORD', '')
user = os.getenv('NATS_USER', 'user')
password = os.getenv('NATS_PASSWORD', 'password')
if env == 'development':
nc = await nats.connect("nats://localhost:4222")
else:
nc = await nats.connect("nats://nats:4222",user=user,password=password)
try:
response = await nc.request(f"banque.creation",f"{request.data.get('username')}:1000",timeout=10)
response = await nc.request(f"banque.creation",f"{str(user_id_bank)}:1000",timeout=10)
response_data = response.data.decode()
data = response_data.split(",")
status=data[0]
Expand Down Expand Up @@ -329,16 +330,16 @@ class PaymentView(APIView):
async def valid_payment(self, user_reserv, price_seat):
global nc
env = os.getenv('DJANGO_ENVIRONMENT', 'development')
user = os.getenv('NATS_USER', '')
password = os.getenv('NATS_PASSWORD', '')
user = os.getenv('NATS_USER', 'user')
password = os.getenv('NATS_PASSWORD', 'password')
if env == 'development':
nc = await nats.connect("nats://localhost:4222")
else:
nc = await nats.connect("nats://nats:4222",user=user,password=password)
try:
client = user_reserv
if payment == "True":
response = await nc.request(f"banque.validation.{client}",str(price_seat),timeout=10)
response = await nc.request(f"banque.validation.{client}", str(price_seat), timeout=10)
response_data = response.data.decode()
data = response_data.split(",")
payment=data[0]
Expand All @@ -356,7 +357,7 @@ def post(self, request, *args, **kwargs):
client = get_object_or_404(User, id=client_id)
price_seat = booking.booking_type.price
# Simulate payment process. In a real scenario, you would integrate with a payment gateway.
payment_successful = self.valid_payment(client_id,price_seat) # This should be replaced with actual payment verification logic
payment_successful = asyncio.run(self.valid_payment(client_id,price_seat)) # This should be replaced with actual payment verification logic

if payment_successful:
booking.status = 'confirmed'
Expand All @@ -374,7 +375,6 @@ def post(self, request, *args, **kwargs):
return Response({'status': 'Payment successful and booking confirmed'}, status=status.HTTP_200_OK)
else:
return Response({'error': 'Payment failed'}, status=status.HTTP_400_BAD_REQUEST)


# new-2
class PaymentGatewayListView(generics.ListCreateAPIView):
Expand Down
4 changes: 2 additions & 2 deletions Docker-test/Frontend/Django/populate_db_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,9 @@ SELECT flight_number, departure::timestamp with time zone, arrival::timestamp wi
-- Insert booking_types
INSERT INTO booking_type (type, price)
SELECT type, price FROM (
SELECT 'Second Class' AS type, 100 AS price
SELECT 'Second Class' AS type, 100.00 AS price
WHERE NOT EXISTS (SELECT 1 FROM booking_type WHERE type = 'Second Class')
UNION ALL
SELECT 'First Class', 200
SELECT 'First Class', 200.00
WHERE NOT EXISTS (SELECT 1 FROM booking_type WHERE type = 'First Class')
) AS subquery;

0 comments on commit b0af84b

Please sign in to comment.