1
0
Fork 0

Return translations

This commit is contained in:
Alex Kotov 2023-02-18 18:09:20 +04:00
parent 77e3d97a19
commit 00983f0a6c
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
1 changed files with 32 additions and 0 deletions

32
main.rb
View File

@ -28,6 +28,7 @@ get '/words/:id' do
json({
primary_form: context.primary_form(word_id),
part_of_speech: context.part_of_speech_name(word_id),
translations: context.translations(word_id),
examples: context.examples(word_id),
})
end
@ -115,6 +116,37 @@ public
str unless str.empty?
end
def translations(word_id)
word_id = Integer word_id
values = @db_conn.exec_params(
(
<<~SQL
SELECT
translation_texts.value,
translation_texts.commentary
FROM words
INNER JOIN translations
ON translations.word_id = words.id
INNER JOIN translation_texts
ON translation_texts.translation_id = translations.id
WHERE
word_id = $1
AND
translation_texts.lang_id = $2
SQL
),
[word_id, user_lang_id],
).to_a
values.map do |row|
{
translation: String(row['value']).strip.freeze,
commentary: String(row['commentary']).strip.freeze,
}.freeze
end.freeze
end
##
# @return [Array<Array(String, String)>]
#