Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tick Climbs and Show Stats #72

Merged
merged 33 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
12dd4c5
Mark Attempts + Logout Button
gardaholm Jun 27, 2024
2507028
minor styling
gardaholm Jun 27, 2024
d7a1b92
updated bids
gardaholm Jun 30, 2024
d254fd0
updated views.py
gardaholm Jul 3, 2024
da4a5d0
Fix it
Jul 3, 2024
f8e7d5b
removed testing files
gardaholm Jul 3, 2024
4124ef3
Combined Menu on Results
gardaholm Jul 17, 2024
3869a2c
Added some Features
Jul 18, 2024
531419b
updated radio buttons
gardaholm Jul 18, 2024
52b55a1
Addded Save buttons
Jul 18, 2024
4e5d72d
Revert "updated radio buttons"
gardaholm Jul 18, 2024
d3c6d5e
Merge branch 'new-branch-name'
gardaholm Jul 18, 2024
9d7f553
updated fly + requirements
gardaholm Jul 18, 2024
c32723c
Your commit message here
Jul 18, 2024
c9417e5
Merge branch 'alerts'
gardaholm Jul 18, 2024
60dbe88
form updates
gardaholm Jul 18, 2024
8d99168
Remove from Logging Attempts
gardaholm Jul 21, 2024
9aaf434
Fixed CSS Problem on Menu Dropdown
gardaholm Aug 10, 2024
3d7aa68
minor cleanups
gardaholm Aug 12, 2024
c34e747
cleanup
gardaholm Aug 12, 2024
e732edf
Reverted fly.toml for climbdex
gardaholm Aug 12, 2024
b7be947
diffForSave camelCase
gardaholm Aug 19, 2024
a687ce7
Added some things
Aug 19, 2024
6a6e155
Added some things
Aug 19, 2024
1a35c2b
Added import request and chaged view.py
Aug 20, 2024
582f5bb
Back to start
Aug 22, 2024
9854444
Angle missmatch resolved
Aug 22, 2024
3656539
bid_count instead of attempt_id
gardaholm Aug 26, 2024
f150117
fixed overflow
gardaholm Aug 27, 2024
cf3a7ee
Your Attempts instead of Statistics
gardaholm Aug 27, 2024
bdc521c
mistake in overflow commit
gardaholm Aug 27, 2024
f4c7b51
Style and nomenclature updates
lemeryfertitta Aug 29, 2024
cb94194
Remove div-climb styling
lemeryfertitta Aug 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 62 additions & 28 deletions climbdex/api.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
from flask_parameter_validation import ValidateParameters, Query

import boardlib.api.aurora
import flask
import requests
import json
from flask import Flask, request, jsonify, Blueprint, json
gardaholm marked this conversation as resolved.
Show resolved Hide resolved
from flask_parameter_validation import ValidateParameters, Json, Query
import boardlib.api.aurora
import logging

import climbdex.db

blueprint = flask.Blueprint("api", __name__)
blueprint = Blueprint("api", __name__)

def parameter_error(e):
code = 400
name = str(type(e).__name__)
description = f"Parameters were missing and/or misconfigured. If the issue persists, please <a href=\"https://github.com/lemeryfertitta/Climbdex/issues/new?title={str(type(e).__name__)}: {str(e)} ({code})\" target='_blank'>report it</a> (code: {code})"

response = {
response = {
"error": True,
"code": code,
"name": name,
Expand All @@ -27,6 +23,7 @@ def parameter_error(e):

@blueprint.errorhandler(Exception)
def handle_exception(e):
logging.error(f"Unhandled exception: {str(e)}", exc_info=True)
response = e.get_response()
response.data = json.dumps({
"error": True,
Expand All @@ -38,29 +35,24 @@ def handle_exception(e):
logging.error(response.data)
return response



@blueprint.route("/api/v1/<board_name>/layouts")
def layouts(board_name):
return flask.jsonify(climbdex.db.get_data(board_name, "layouts"))

return jsonify(climbdex.db.get_data(board_name, "layouts"))

@blueprint.route("/api/v1/<board_name>/layouts/<layout_id>/sizes")
def sizes(board_name, layout_id):
return flask.jsonify(
return jsonify(
climbdex.db.get_data(board_name, "sizes", {"layout_id": int(layout_id)})
)


@blueprint.route("/api/v1/<board_name>/layouts/<layout_id>/sizes/<size_id>/sets")
def sets(board_name, layout_id, size_id):
return flask.jsonify(
return jsonify(
climbdex.db.get_data(
board_name, "sets", {"layout_id": int(layout_id), "size_id": int(size_id)}
)
)


@blueprint.route("/api/v1/search/count")
@ValidateParameters(parameter_error)
def resultsCount(
Expand All @@ -72,7 +64,7 @@ def resultsCount(
minRating: float = Query(),
size: int = Query(),
):
return flask.jsonify(climbdex.db.get_search_count(flask.request.args))
return jsonify(climbdex.db.get_search_count(request.args))

@blueprint.route("/api/v1/search")
@ValidateParameters(parameter_error)
Expand All @@ -85,30 +77,72 @@ def search(
minRating: float = Query(),
size: int = Query(),
):
return flask.jsonify(climbdex.db.get_search_results(flask.request.args))

return jsonify(climbdex.db.get_search_results(request.args))

@blueprint.route("/api/v1/<board_name>/beta/<uuid>")
def beta(board_name, uuid):
return flask.jsonify(climbdex.db.get_data(board_name, "beta", {"uuid": uuid}))

return jsonify(climbdex.db.get_data(board_name, "beta", {"uuid": uuid}))

@blueprint.route("/api/v1/login/", methods=["POST"])
def login():
try:
login_details = boardlib.api.aurora.login(
flask.request.json["board"],
flask.request.json["username"],
flask.request.json["password"],
request.json["board"],
request.json["username"],
request.json["password"],
)
return flask.jsonify(
return jsonify(
{"token": login_details["token"], "user_id": login_details["user_id"]}
)
except requests.exceptions.HTTPError as e:
if e.response.status_code == requests.codes.unprocessable_entity:
return (
flask.jsonify({"error": "Invalid username/password combination"}),
jsonify({"error": "Invalid username/password combination"}),
e.response.status_code,
)
else:
return flask.jsonify({"error": str(e)}), e.response.status_code
return jsonify({"error": str(e)}), e.response.status_code

@blueprint.route("/api/v1/save_ascent", methods=["POST"])
@ValidateParameters(parameter_error)
def api_save_ascent(
board: str = Json(),
climb_uuid: str = Json(),
angle: int = Json(),
is_mirror: bool = Json(),
attempt_id: int = Json(),
bid_count: int = Json(),
quality: int = Json(),
difficulty: int = Json(),
is_benchmark: bool = Json(),
comment: str = Json(),
climbed_at: str = Json(),
):
try:
login_cookie = request.cookies.get(f"{board}_login")
if not login_cookie:
return jsonify({"error": "Login required"}), 401

login_info = json.loads(login_cookie)
token = login_info["token"]
user_id = login_info["user_id"]

result = boardlib.api.aurora.save_ascent(
board=board,
token=token,
user_id=user_id,
climb_uuid=climb_uuid,
angle=angle,
is_mirror=is_mirror,
attempt_id=attempt_id,
gardaholm marked this conversation as resolved.
Show resolved Hide resolved
bid_count=bid_count,
quality=quality,
difficulty=difficulty,
is_benchmark=is_benchmark,
comment=comment,
climbed_at=climbed_at
)
return jsonify(result)
except Exception as e:
logging.error(f"Error in save_ascent: {str(e)}", exc_info=True)
return jsonify({"error": str(e)}), 500
1 change: 1 addition & 0 deletions climbdex/static/js/boardSelection.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ loginForm.addEventListener("submit", function (event) {
const modal = bootstrap.Modal.getInstance("#div-modal");
modal.hide();
populateLoginForm(boardName);
location.reload();
}
});
});
Expand Down
Loading