"""Core views.""" from flask import g from flask.views import MethodView from auth.auth_view import AuthorizedView from core.schemas import HealthCheckResponseModel from core.service import HealthCheckService from services.territory.territories_repository import TerritoriesRepository from services.currencies_repository import CurrenciesRepository from services.labels_repository import LabelsRepository from services.dictionaries import DictionaryRepository class BasicHealthCheckView(MethodView): """Basic application health check.""" def get(self): """Perform basic health check. Returns: HTTP 200: If application is alive and responds. """ return HealthCheckResponseModel() class HealthCheckView(MethodView): """Application health check.""" service = HealthCheckService() def get(self): """Perform health check. Returns: HTTP 200: If application is alive and connects to the database. Raises: HTTP 500: If application cannot connect to the database. """ self.service.check_database_connection() return HealthCheckResponseModel() class TerritoryListView(AuthorizedView): """Endpoint for retrieving list of territories.""" territories_repository = TerritoriesRepository() def get(self): """Retrieve list of territories. Returns: HTTP 200: JSON with list of territories. Raises: HTTP 401: If user is not authenticated. """ return self.territories_repository.get_all_territories() class CurrencyListView(AuthorizedView): """Endpoint for retrieving list of currencies.""" currencies_repository = CurrenciesRepository() def get(self): """Retrieve list of currencies. Returns: HTTP 200: JSON with list of currencies. Raises: HTTP 401: If user is not authenticated. """ return self.currencies_repository.get_all_currencies() class LabelListView(AuthorizedView): """Endpoint for retrieving list of all labels.""" labels_repository = LabelsRepository() def get(self): """Retrieve list of all labels. Returns: HTTP 200: JSON containing list of all labels. Raises: HTTP 401: If user is not authenticated. """ return self.labels_repository.get_all_labels() class UserLabelListView(AuthorizedView): """Endpoint for retrieving list of labels available to user.""" labels_repository = LabelsRepository() def get(self): """Retrieve list of labels available to user. Returns: HTTP 200: JSON containing list of labels. Raises: HTTP 401: If user is not authenticated. """ return self.labels_repository.get_all_labels_for_user(user_id=g.user_id) class CountryCodes(AuthorizedView): territories_repository = TerritoriesRepository() def get(self): return self.territories_repository.get_all_territory_codes() class RecordTypesView(AuthorizedView): repository = DictionaryRepository() def get(self): return self.repository.get_record_types() class ReleaseTypesView(AuthorizedView): repository = DictionaryRepository() def get(self): return self.repository.get_release_types() class GenresView(AuthorizedView): repository = DictionaryRepository() def get(self): return self.repository.get_genres()