-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added endpoints for games and categories
- Loading branch information
1 parent
1e55e6a
commit 2eddf96
Showing
4 changed files
with
95 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from flask import Blueprint, request, jsonify | ||
from supabase import create_client, Client | ||
from dotenv import dotenv_values | ||
|
||
|
||
bp = Blueprint('category', __name__, url_prefix='/categories') | ||
|
||
config = dotenv_values("./.env") | ||
url: str = config.get('SUPABASE_URL') | ||
key: str = config.get('SUPABASE_KEY') | ||
supabase: Client = create_client(url, key) | ||
|
||
|
||
@bp.route('', methods=['POST', 'GET']) | ||
def post_get_categories(): | ||
if request.method == 'POST': | ||
data = request.get_json() | ||
try: | ||
new_category = supabase.table("Categories").insert(data).execute() | ||
return jsonify(new_category.data[0]) | ||
except Exception as e: | ||
return {"error": e.details} | ||
elif request.method == 'GET': | ||
query = supabase.table("Categories").select("*").execute() | ||
categories = query.data | ||
if not categories: | ||
return {"error": "No categories found"} | ||
return jsonify([category for category in categories]) | ||
|
||
|
||
@bp.route('/<category_id>', methods=['GET', 'PATCH', 'DELETE']) | ||
def get_patch_delete_category(category_id): | ||
query = supabase.table("Categories").select("*").eq("id", category_id).execute() | ||
category = query.data | ||
if not category: | ||
return {"error": "Category not found"} | ||
elif request.method == 'GET': | ||
return jsonify(category[0]) | ||
elif request.method == 'PATCH': | ||
data = request.get_json() | ||
updated_data = {'title': data['title']} | ||
updated_category = supabase.table("Categories").update(updated_data).eq("id", category_id).execute() | ||
return jsonify(updated_category.data[0]) | ||
elif request.method == 'DELETE': | ||
supabase.table("Categories").delete().eq("id", category_id).execute() | ||
return {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from flask import Blueprint, request, jsonify | ||
from supabase import create_client, Client | ||
from dotenv import dotenv_values | ||
|
||
|
||
bp = Blueprint('game', __name__, url_prefix='/games') | ||
|
||
config = dotenv_values("./.env") | ||
url: str = config.get('SUPABASE_URL') | ||
key: str = config.get('SUPABASE_KEY') | ||
supabase: Client = create_client(url, key) | ||
|
||
|
||
@bp.route('', methods=['POST', 'GET']) | ||
def post_get_games(): | ||
if request.method == 'POST': | ||
data = request.get_json() | ||
try: | ||
new_game = supabase.table("Games").insert(data).execute() | ||
return jsonify(new_game.data[0]) | ||
except Exception as e: | ||
return {"error": e.details} | ||
elif request.method == 'GET': | ||
query = supabase.table("Games").select("*").execute() | ||
games = query.data | ||
if not games: | ||
return {"error": "No games found"} | ||
return jsonify([game for game in games]) | ||
|
||
|
||
@bp.route('/<game_id>', methods=['GET', 'PATCH', 'DELETE']) | ||
def get_patch_delete_game(game_id): | ||
query = supabase.table("Games").select("*").eq("id", game_id).execute() | ||
game = query.data | ||
if not game: | ||
return {"error": "Game not found"} | ||
elif request.method == 'GET': | ||
return jsonify(game[0]) | ||
elif request.method == 'PATCH': | ||
data = request.get_json() | ||
updated_data = {'title': data['title']} | ||
updated_game = supabase.table("Games").update(updated_data).eq("id", game_id).execute() | ||
return jsonify(updated_game.data[0]) | ||
elif request.method == 'DELETE': | ||
supabase.table("Games").delete().eq("id", game_id).execute() | ||
return {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters