feat: add edit_game endpoint to allow users to update game title and image
This commit is contained in:
parent
874e190eba
commit
bdb693c361
@ -1,5 +1,5 @@
|
|||||||
from flask import Blueprint, request, jsonify, g
|
from flask import Blueprint, request, jsonify, g
|
||||||
from models import db, User
|
from models import db, User, Game
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
import jwt
|
import jwt
|
||||||
from werkzeug.security import generate_password_hash, check_password_hash
|
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.delete(user)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return jsonify({'message': 'User deleted!'}), 200
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user