-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/SaltieRL/Distributed-Replays
- Loading branch information
Showing
60 changed files
with
1,422 additions
and
62 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
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
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
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,84 @@ | ||
from typing import List | ||
|
||
from flask import g, current_app | ||
|
||
from ...errors.errors import CalculatedError, TagNotFound | ||
from backend.database.objects import Tag as DBTag | ||
from backend.database.wrapper.tag_wrapper import TagWrapper, DBTagNotFound | ||
|
||
|
||
class Tag: | ||
def __init__(self, name: str, owner: str): | ||
self.name = name | ||
self.ownerId = owner | ||
|
||
@staticmethod | ||
def create_from_dbtag(tag: DBTag): | ||
return Tag(tag.name, tag.owner) | ||
|
||
@staticmethod | ||
def create(name: str) -> 'Tag': | ||
session = current_app.config['db']() | ||
|
||
# Check if tag exists | ||
try: | ||
dbtag = TagWrapper.get_tag(g.user.platformid, name, session) | ||
tag = Tag.create_from_dbtag(dbtag) | ||
session.close() | ||
return tag | ||
except DBTagNotFound: | ||
pass | ||
dbtag = TagWrapper.create_tag(session, g.user.platformid, name) | ||
tag = Tag.create_from_dbtag(dbtag) | ||
session.close() | ||
return tag | ||
|
||
@staticmethod | ||
def rename(current_name: str, new_name: str) -> 'Tag': | ||
session = current_app.config['db']() | ||
|
||
# Check if name already exists | ||
try: | ||
TagWrapper.get_tag(g.user.platformid, new_name, session) | ||
session.close() | ||
raise CalculatedError(409, f"Tag with name {new_name} already exists.") | ||
except DBTagNotFound: | ||
pass | ||
|
||
try: | ||
dbtag = TagWrapper.rename_tag(session, g.user.platformid, current_name, new_name) | ||
except DBTagNotFound: | ||
session.close() | ||
raise TagNotFound() | ||
tag = Tag.create_from_dbtag(dbtag) | ||
session.close() | ||
return tag | ||
|
||
@staticmethod | ||
def delete(name: str) -> None: | ||
try: | ||
TagWrapper.delete_tag(g.user.platformid, name) | ||
except DBTagNotFound: | ||
raise TagNotFound() | ||
|
||
@staticmethod | ||
def get_all() -> List['Tag']: | ||
session = current_app.config['db']() | ||
dbtags = TagWrapper.get_tags(session, g.user.platformid) | ||
tags = [Tag.create_from_dbtag(dbtag) for dbtag in dbtags] | ||
session.close() | ||
return tags | ||
|
||
@staticmethod | ||
def add_tag_to_game(name: str, replay_id: str) -> None: | ||
try: | ||
TagWrapper.add_tag_to_game(replay_id, g.user.platformid, name) | ||
except DBTagNotFound: | ||
raise TagNotFound() | ||
|
||
@staticmethod | ||
def remove_tag_from_game(name: str, replay_id: str) -> None: | ||
try: | ||
TagWrapper.remove_tag_from_game(replay_id, g.user.platformid, name) | ||
except DBTagNotFound: | ||
raise TagNotFound() |
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
Empty file.
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,9 @@ | ||
from ..errors.errors import CalculatedError | ||
|
||
|
||
def require_user(func): | ||
def wrapper_require_user(*args, **kwargs): | ||
if g.user is None: | ||
raise CalculatedError(404, "User is not logged in.") | ||
func(*args, **kwargs) | ||
return wrapper_require_user |
File renamed without changes.
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
Oops, something went wrong.