<gh_stars>1-10
from .models import Server
from .repositories import ServerRepository
from functools import cache
from typing import Iterator


class ServerService:
    def __init__(self, server_repository: ServerRepository) -> None:
        self._repository: ServerRepository = server_repository

    @cache
    def get_servers(self) -> Iterator[Server]:
        return self._repository.get_all()

    def get_server_by_address(self, server_address: str) -> Server:
        return self._repository.get_by_address(server_address)

    def create_server(self, server_address: str, json: str) -> Server:
        return self._repository.add(server_address, json)

    def delete_server_by_address(self, server_address: str) -> None:
        return self._repository.delete_by_address(server_address)

    def get_random_server(self) -> Server:
        return self._repository.get_random()

from .models import Server
from .repositories import ServerRepository
from functools import cache
from typing import Iterator


class ServerService:
    def __init__(self, server_repository: ServerRepository) -> None:
        self._repository: ServerRepository = server_repository

    @cache
    def get_servers(self) -> Iterator[Server]:
        return self._repository.get_all()

    def get_server_by_address(self, server_address: str) -> Server:
        return self._repository.get_by_address(server_address)

    def create_server(self, server_address: str, json: str) -> Server:
        return self._repository.add(server_address, json)

    def delete_server_by_address(self, server_address: str) -> None:
        return self._repository.delete_by_address(server_address)

    def get_random_server(self) -> Server:
        return self._repository.get_random()