feat: add edit_game endpoint to allow users to update game title and image

This commit is contained in:
Manuel Weiser 2024-09-02 11:42:20 +02:00
parent 874e190eba
commit bdb693c361

View File

@ -1,5 +1,5 @@
from flask import Blueprint, request, jsonify, g
from models import db, User
from models import db, User, Game
from datetime import datetime, timedelta
import jwt
from werkzeug.security import generate_password_hash, check_password_hash
@ -99,3 +99,17 @@ def delete_user(user_id):
db.session.delete(user)
db.session.commit()
return jsonify({'message': 'User deleted!'}), 200
@user_bp.route('/games/<int:game_id>', methods=['PUT'])
def edit_game(game_id):
if not authenticate():
return jsonify({'message': 'Unauthorized access!'}), 401
data = request.json
game = Game.query.get(game_id)
if not game:
return jsonify({'message': 'Game not found!'}), 404
game.title = data.get('title', game.title)
game.image = data.get('image', game.image)
db.session.commit()
return jsonify({'message': 'Game updated!'}), 200