A mobile app for listening to radio stations from around the globe
git clone git://soophie.de/verbal
61
},62
async loadRecommended() {63
for(const id of this.popular) {64
this.recommended.push(await http`get::/api/station`({ id }));64
this.recommended.push(await http`get::/api/station`(id));65
}66
},67
async loadFilters() {68
const countries = await http`get::/api/countries`();69
for(const {country} of countries) {70
this.countries.push(country);71
}68
this.countries = await http`get::/api/countries`();69
const languages = await http`get::/api/languages`();73
for(const {language} of languages) {74
this.languages.push(language.toUpperCase());75
}70
this.languages = languages.map(language => language.toUpperCase());71
},72
reset() {73
this.query = {
85
}87
#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]88
pub struct StationCountry {89
pub country: String,90
}88
pub struct Id(pub i32);90
#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]93
pub struct StationLanguage {94
pub language: String,95
}91
pub struct Country(pub String);97
#[derive(Debug, Clone, Deserialize)]98
pub struct StationId {99
pub id: i32,100
}93
#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]94
pub struct Language(pub String);96
#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]97
pub struct Tag(pub String);
5
use tide_sqlx::SQLxRequestExt;7
use crate::model;8
use crate::model::StationCountry;9
use crate::model::StationId;10
use crate::model::StationLanguage;8
use crate::model::Country;9
use crate::model::Id;10
use crate::model::Language;11
use crate::model::Tag;12
use crate::unwrap_option_or_throw;13
use crate::unwrap_result_or_throw;14
use crate::Response;
170
}172
pub async fn get_station(req: tide::Request<()>) -> tide::Result {172
let station_id = req.query::<StationId>()?;173
let station_id = req.query::<Id>()?;174
let account =175
unwrap_option_or_throw!(req.ext::<model::Account>(), "no account in request found!");176
let sql = format!(
195
AND station_status.is_hidden IS NOT true196
"#,197
account_id = account.id,197
station_id = station_id.id,198
station_id = station_id.0,199
);200
let mut conn = req.sqlx_conn::<Postgres>().await;201
let result = sqlx::query_as::<_, model::Station>(&sql)
216
"#,217
);218
let mut conn = req.sqlx_conn::<Postgres>().await;218
let result = sqlx::query_as::<_, StationCountry>(&sql)219
let result = sqlx::query_as::<_, Country>(&sql)220
.fetch_all(conn.acquire().await?)221
.await?;222
Response::with(result)
233
"#,234
);235
let mut conn = req.sqlx_conn::<Postgres>().await;235
let result = sqlx::query_as::<_, StationLanguage>(&sql)236
let result = sqlx::query_as::<_, Language>(&sql)237
.fetch_all(conn.acquire().await?)238
.await?;239
Response::with(result)240
}242
pub async fn get_tags(req: tide::Request<()>) -> tide::Result {243
let sql = format!(244
r#"245
SELECT246
UNNEST(tags) AS tag247
FROM station248
GROUP BY UNNEST(tags)249
ORDER BY COUNT(*) DESC;250
"#,251
);252
let mut conn = req.sqlx_conn::<Postgres>().await;253
let result = sqlx::query_as::<_, Tag>(&sql)254
.fetch_all(conn.acquire().await?)255
.await?;256
Response::with(result)
56
app.at("/api/station").get(route::get_station);57
app.at("/api/countries").get(route::get_countries);58
app.at("/api/languages").get(route::get_languages);59
app.at("/api/tags").get(route::get_tags);61
let address =62
unwrap_result_or_abort!(config.server.to_url(), "cannot parse server address!");