mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Add and fix API v2 and db
* Add basic role routes * Add API v2 404 handler * Add API v2 home handler pointing to the wiki * Add tons more todos * Add get_*_columns and get_*_column functions for many db models * Modify and add tons of model and controller functions
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
import logging
|
||||
import datetime
|
||||
import typing as t
|
||||
from peewee import (
|
||||
ForeignKeyField,
|
||||
CharField,
|
||||
@ -9,6 +10,7 @@ from peewee import (
|
||||
IntegerField,
|
||||
FloatField,
|
||||
)
|
||||
from playhouse.shortcuts import model_to_dict
|
||||
|
||||
from app.classes.shared.main_models import DatabaseShortcuts
|
||||
from app.classes.models.base_model import BaseModel
|
||||
@ -162,6 +164,24 @@ class HelperServers:
|
||||
except IndexError:
|
||||
return {}
|
||||
|
||||
@staticmethod
|
||||
def get_server_columns(
|
||||
server_id: t.Union[str, int], column_names: t.List[str]
|
||||
) -> t.List[t.Any]:
|
||||
columns = [getattr(Servers, column) for column in column_names]
|
||||
return model_to_dict(
|
||||
Servers.select(*columns).where(Servers.server_id == server_id).get(),
|
||||
only=columns,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_server_column(server_id: t.Union[str, int], column_name: str) -> t.Any:
|
||||
column = getattr(Servers, column_name)
|
||||
return model_to_dict(
|
||||
Servers.select(column).where(Servers.server_id == server_id).get(),
|
||||
only=[column],
|
||||
)[column_name]
|
||||
|
||||
# **********************************************************************************
|
||||
# Servers Methods
|
||||
# **********************************************************************************
|
||||
|
Reference in New Issue
Block a user