2023-01-04 19:40:52 +01:00
require " ecr "
include CrystalGauntlet
2023-01-04 10:49:34 +01:00
CrystalGauntlet . template_endpoints [ " /tools/song_search " ] = - > ( context : HTTP :: Server :: Context ) {
2023-01-04 12:55:59 +01:00
context . response . content_type = " text/html "
2023-01-04 19:40:52 +01:00
error = nil
songs = nil
body = context . request . body
if body
begin
params = URI :: Params . parse ( body . gets_to_end )
query = " % #{ params [ " query " ] } % "
2023-01-05 11:53:50 +01:00
songs = DATABASE . query_all ( " select song_data.id, song_authors.name, song_data.name from song_data join song_authors on song_authors.id = song_data.author_id where song_data.id = ? or song_authors.name like ? or song_data.name like ? " , params [ " query " ] , query , query , as : { Int32 , String , String } )
2023-01-04 19:40:52 +01:00
rescue error
2023-01-04 10:49:34 +01:00
ECR . embed ( " ./public/template/song_search.ecr " , context . response )
2023-01-04 19:40:52 +01:00
else
2023-01-04 10:49:34 +01:00
ECR . embed ( " ./public/template/song_search.ecr " , context . response )
2023-01-04 19:40:52 +01:00
end
2023-01-04 10:49:34 +01:00
else
ECR . embed ( " ./public/template/song_search.ecr " , context . response )
2023-01-04 19:40:52 +01:00
end
}