Return new inflections
This commit is contained in:
parent
9cc8e71d1c
commit
bbbc030e67
34
main.rb
34
main.rb
|
@ -32,7 +32,8 @@ get '/words/:id' do
|
|||
part_of_speech: context.part_of_speech_name(word_id),
|
||||
commentary: word_info[:commentary],
|
||||
translations: context.translations(word_id),
|
||||
inflections: word_info[:inflections],
|
||||
inflections_old: word_info[:inflections],
|
||||
inflections: context.inflections(word_id),
|
||||
examples: context.examples(word_id),
|
||||
})
|
||||
end
|
||||
|
@ -168,6 +169,37 @@ public
|
|||
end.freeze
|
||||
end
|
||||
|
||||
def inflections(word_id)
|
||||
word_id = Integer word_id
|
||||
|
||||
result = @db_conn.exec_params(
|
||||
(
|
||||
<<~SQL
|
||||
SELECT inflections.descr, word_forms.value
|
||||
FROM words
|
||||
INNER JOIN parts
|
||||
ON parts.id = words.part_id
|
||||
INNER JOIN inflections
|
||||
ON inflections.part_id = parts.id
|
||||
LEFT JOIN word_forms
|
||||
ON word_forms.inflection_id = inflections.id
|
||||
WHERE words.id = $1 AND word_forms.word_id = $1
|
||||
SQL
|
||||
),
|
||||
[word_id],
|
||||
).to_a
|
||||
|
||||
result.map do |row|
|
||||
descr = String(row['descr']).strip.freeze
|
||||
value = String(row['value']).strip.freeze
|
||||
|
||||
{
|
||||
descr: descr,
|
||||
value: value,
|
||||
}
|
||||
end.freeze
|
||||
end
|
||||
|
||||
def examples(word_id)
|
||||
word_id = Integer word_id
|
||||
|
||||
|
|
Loading…
Reference in New Issue