F
F
Finn the Boy2018-07-01 22:24:07
Java
Finn the Boy, 2018-07-01 22:24:07

Data access layer for multilingual DB?

Suppose there is a database with a similar structure:
5b392747e8bcf353740909.jpeg
The application that will work with the database is an API. API users can request posts like this: /posts/1/?language=en. As a result, the user should get a model like this:

{
    "id": 1,
    "category": {
        "id": 5,
        "name": "ru_category"
    },
    "title": "ru_title",
    "text": "ru_text",
    "created_at": "date"
}

If the requested translation does not exist, the API should return a default translation (for example, English).
What is the best way to implement the data access layer? One option is to implement repositories for entity tables and for translation tables. Then BlogPostsRepository will receive information about posts that do not need translation, and BlogPostTranslationsRepository will receive information about translations of posts.
To return the model discussed above, you will have to get information about the post, then information about the translations of the post (in the requested language + in the default language), then perform the same operations for the categories, then map it all to one model and give it to the user.
In this variant, too many operations confuse me. In the case when more tables are associated with posts (for example, comments, tags, etc.), there will be even more queries.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question