Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor TextSearchResource #513

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions ebl/corpus/web/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,10 @@
from ebl.corpus.web.manuscripts import ManuscriptsResource
from ebl.corpus.web.texts import (
TextResource,
TextSearchResource,
TextsResource,
TextsAllResource,
)
from ebl.corpus.web.unplaced_lines import UnplacedLinesResource
from ebl.transliteration.application.transliteration_query_factory import (
TransliterationQueryFactory,
)


def create_corpus_routes(api: falcon.App, context: Context):
Expand All @@ -39,9 +35,6 @@ def create_corpus_routes(api: falcon.App, context: Context):

texts = TextsResource(corpus)
text = TextResource(corpus)
text_search = TextSearchResource(
corpus, TransliterationQueryFactory(context.sign_repository)
)
chapters = ChaptersResource(corpus)
chapters_display = ChaptersDisplayResource(corpus, context.custom_cache)
chapters_line = LineResource(corpus, context.custom_cache)
Expand All @@ -64,7 +57,6 @@ def create_corpus_routes(api: falcon.App, context: Context):
chapter_url = text_url + "/chapters/{stage}/{name}"

api.add_route("/texts", texts)
api.add_route("/textsearch", text_search)
api.add_route(text_url, text)

api.add_route(chapter_url, chapters)
Expand Down
27 changes: 1 addition & 26 deletions ebl/corpus/web/texts.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import falcon

from ebl.corpus.application.corpus import Corpus
from ebl.corpus.web.chapter_info_schema import (
ChapterInfosPaginationSchema,
)

from ebl.corpus.web.text_schema import ApiTextSchema
from ebl.corpus.web.text_utils import create_text_id
from ebl.errors import DataError
fsimonjetz marked this conversation as resolved.
Show resolved Hide resolved
from ebl.transliteration.application.transliteration_query_factory import (
TransliterationQueryFactory,
)


class TextsResource:
Expand All @@ -31,25 +25,6 @@ def on_get(
resp.media = ApiTextSchema().dump(text)


class TextSearchResource:
def __init__(
self, corpus: Corpus, transliteration_query_factory: TransliterationQueryFactory
):
self._corpus = corpus
self._transliteration_query_factory = transliteration_query_factory

def on_get(self, req: falcon.Request, resp: falcon.Response) -> None:
query = self._transliteration_query_factory.create(
req.params["transliteration"]
)
try:
pagination_index = int(req.params["paginationIndex"])
except ValueError as error:
raise DataError("Pagination Index has to be a number") from error
chapters = self._corpus.search_transliteration(query, pagination_index)
resp.media = ChapterInfosPaginationSchema().dump(chapters)


class TextsAllResource:
def __init__(
self,
Expand Down
31 changes: 1 addition & 30 deletions ebl/tests/corpus/test_texts_route.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import falcon

from ebl.corpus.application.schemas import TextSchema
from ebl.corpus.domain.chapter_info import ChapterInfo
from ebl.corpus.web.chapter_info_schema import ChapterInfoSchema
from ebl.tests.corpus.support import allow_references, allow_signs
from ebl.tests.factories.corpus import ChapterFactory, TextFactory
from ebl.transliteration.domain.transliteration_query import TransliterationQuery
from ebl.transliteration.application.signs_visitor import SignsVisitor
from ebl.tests.factories.corpus import TextFactory


def create_dto(text):
Expand Down Expand Up @@ -53,27 +48,3 @@ def test_listing_texts(client, bibliography, text_repository):

assert get_result.status == falcon.HTTP_OK
assert get_result.json == [create_dto(first_text), create_dto(second_text)]


def test_searching_texts(client, bibliography, sign_repository, signs, text_repository):
allow_signs(signs, sign_repository)
chapter = ChapterFactory.build()
allow_references(chapter, bibliography)
text_repository.create_chapter(chapter)

get_result = client.simulate_get("/textsearch?transliteration=ku&paginationIndex=0")

assert get_result.status == falcon.HTTP_OK
assert get_result.json == {
"chapterInfos": [
ChapterInfoSchema().dump(
ChapterInfo.of(
chapter,
TransliterationQuery(
string="KU", visitor=SignsVisitor(sign_repository)
),
)
)
],
"totalCount": 1,
}
Loading