add endpoints to get items by id
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 4s

This commit is contained in:
Thomas Peetz
2026-05-20 18:34:44 +02:00
parent 944420802f
commit bbc00ae2cc
10 changed files with 114 additions and 25 deletions
+21 -2
View File
@@ -1,4 +1,5 @@
from dataclasses import dataclass
from enum import Enum, auto
import logging
import logging.config
from logging import Logger
@@ -47,6 +48,22 @@ MAPPING: Dict[str, str] = {
"mail_account": "api/admin/mailaccounts",
}
class OptionType(Enum):
PARAM = auto()
ID = auto()
class Option:
def __init__(self, option_type: OptionType, value: str) -> None:
self.type: Optional[OptionType] = option_type
self.value: Optional[str] = value
def __str__(self) -> str:
if self.type is OptionType.PARAM:
return f"?{self.value}"
else:
return f"/{self.value}"
class EndPointNotAvailableException(Exception):
"""
@@ -101,11 +118,11 @@ class Server:
self.token = str(token)
self.token_type = str(token_type)
def request(self, log: Logger, table: str, param: Optional[str] = None):
def request(self, log: Logger, table: str, param: Optional[Option] = None):
if not param:
url: str = f"{self.url}/{MAPPING[table]}"
else:
url: str = f"{self.url}/{MAPPING[table]}?{param}"
url: str = f"{self.url}/{MAPPING[table]}{str(param)}"
headers: Dict[str, str] = {"Authorization": f"Bearer {self.token}"}
response = requests.get(url, headers=headers, timeout=self.timeout)
log.debug(f"Status: {response.status_code}")
@@ -158,6 +175,8 @@ def get_logger(level, config: str):
case 0:
logger.setLevel(logging.CRITICAL)
case 1:
logging.getLogger("requests").setLevel(logging.WARNING)
logging.getLogger("urllib3").setLevel(logging.WARNING)
logger.setLevel(logging.INFO)
case 2:
logger.setLevel(logging.DEBUG)