Return translations
This commit is contained in:
parent
77e3d97a19
commit
00983f0a6c
32
main.rb
32
main.rb
|
@ -28,6 +28,7 @@ get '/words/:id' do
|
||||||
json({
|
json({
|
||||||
primary_form: context.primary_form(word_id),
|
primary_form: context.primary_form(word_id),
|
||||||
part_of_speech: context.part_of_speech_name(word_id),
|
part_of_speech: context.part_of_speech_name(word_id),
|
||||||
|
translations: context.translations(word_id),
|
||||||
examples: context.examples(word_id),
|
examples: context.examples(word_id),
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
@ -115,6 +116,37 @@ public
|
||||||
str unless str.empty?
|
str unless str.empty?
|
||||||
end
|
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)>]
|
# @return [Array<Array(String, String)>]
|
||||||
#
|
#
|
||||||
|
|
Loading…
Reference in New Issue