feat: set buyer as the authenticated user's username when adding a game

This commit is contained in:
Manuel Weiser 2024-09-02 11:47:29 +02:00
parent 7bf9763a95
commit b9dfa6adba

View File

@ -22,11 +22,12 @@ def add_game():
if not authenticate(): if not authenticate():
return jsonify({'message': 'Unauthorized access!'}), 401 return jsonify({'message': 'Unauthorized access!'}), 401
data = request.json data = request.json
buyer_username = g.user.username # Get the username from the authenticated user
new_game = Game( new_game = Game(
image=data['image'], image=data['image'],
title=data['title'], title=data['title'],
date=datetime.now().strftime('%Y-%m-%d'), # Set current date date=datetime.now().strftime('%Y-%m-%d'), # Set current date
buyer=data['buyer'], buyer=buyer_username, # Set buyer as the authenticated user's username
owned=data['owned'] owned=data['owned']
) )
db.session.add(new_game) db.session.add(new_game)