51 lines
1.4 KiB
Python
51 lines
1.4 KiB
Python
import json
|
|
import sqlite3
|
|
from dataclasses import dataclass
|
|
from pathlib import Path
|
|
|
|
import typer
|
|
|
|
VALID_SEVERITIES = frozenset({"low", "medium", "high", "critical"})
|
|
|
|
|
|
class InvalidIncidentError(ValueError):
|
|
"""Niepoprawne dane wejściowe incydentu."""
|
|
|
|
|
|
class IncidentNotFoundError(KeyError):
|
|
"""Nie znaleziono incydentu o podanym ID."""
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class Incident:
|
|
id: int
|
|
title: str
|
|
severity: str
|
|
status: str
|
|
|
|
|
|
class IncidentStore:
|
|
def __init__(self, db_path: Path) -> None:
|
|
self._db_path = db_path
|
|
|
|
def init_schema(self) -> None:
|
|
_ = sqlite3
|
|
raise NotImplementedError("Utwórz tabelę incidents (id, title, severity, status)")
|
|
|
|
def add(self, title: str, severity: str) -> Incident:
|
|
raise NotImplementedError("Zwaliduj title i severity, zapisz w SQLite i zwróć Incident")
|
|
|
|
def list_incidents(self, severity: str | None = None) -> list[Incident]:
|
|
raise NotImplementedError("Zwróć incydenty (opcjonalnie przefiltrowane po severity)")
|
|
|
|
def resolve(self, incident_id: int) -> Incident:
|
|
raise NotImplementedError("Zmień status na 'resolved' lub rzuć IncidentNotFoundError")
|
|
|
|
def stats(self) -> dict[str, int]:
|
|
raise NotImplementedError("Zwróć {'open': X, 'resolved': Y}")
|
|
|
|
|
|
def build_cli(db_path: Path) -> typer.Typer:
|
|
_ = (json, db_path, typer.Typer)
|
|
raise NotImplementedError("Zarejestruj podkomendy add, list, resolve, stats wypisujące JSON")
|