so://phie

verbal

A mobile app for listening to radio stations from around the globe
git clone git://soophie.de/verbal

blob: b258ec9effa5a5818b32d030042ea07ea0c666e6 (2351 bytes)[doc][blame][raw]

1use serde::Deserialize;

2use serde::Serialize;

3use sqlx::FromRow;

4use std::fmt::Write;

5

6use crate::Result;

7use crate::ToSql;

8

9#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]

10pub struct Account {

11 pub id: i32,

12 pub name: Option<String>,

13 pub language: String,

14}

15

16#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]

17pub struct Device {

18 pub id: i32,

19 pub uid: String,

20 pub name: Option<String>,

21 pub account_id: i32,

22}

23

24#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]

25pub struct Station {

26 pub id: i32,

27 pub uid: String,

28 pub name: String,

29 pub url: String,

30 pub icon: Option<String>,

31 pub homepage: Option<String>,

32 pub tags: Option<Vec<String>>,

33 pub country: Option<String>,

34 pub state: Option<String>,

35 pub languages: Option<Vec<String>>,

36 pub score: i32,

37 pub is_favorite: Option<bool>,

38 pub is_restricted: Option<bool>,

39 pub is_broken: Option<bool>,

40 pub is_no_track_info: Option<bool>,

41 pub is_icon: Option<bool>,

42 // pub is_hidden: Option<bool>,

43}

44

45#[derive(Debug, Serialize, Deserialize, FromRow)]

46pub struct Favorite {

47 pub id: i32,

48 pub account_id: i32,

49 pub station_id: String,

50}

51

52#[derive(Debug, Default, Deserialize)]

53pub struct Query {

54 pub name: String,

55 pub tags: Option<Vec<String>>,

56 pub country: Option<String>,

57 pub language: Option<String>,

58 pub page: Option<i32>,

59}

60

61impl ToSql for Query {

62 fn to_sql(&self) -> Result<String> {

63 let mut sql = String::new();

64 writeln!(

65 sql,

66 "WHERE LOWER(station.name) LIKE LOWER('%{}%')",

67 self.name

68 )?;

69 if let Some(tags) = &self.tags {

70 write!(sql, "AND station.tags = array[")?;

71 for (i, tag) in tags.iter().enumerate() {

72 if i > 0 {

73 write!(sql, ", ")?;

74 }

75 write!(sql, "LOWER('{}')", tag)?;

76 }

77 writeln!(sql, "]")?;

78 }

79 if let Some(country) = &self.country {

80 writeln!(sql, "AND station.country = UPPER('{}')", country)?;

81 }

82 if let Some(language) = &self.language {

83 writeln!(sql, "AND station.languages = array[LOWER('{}')]", language)?;

84 }

85 Ok(sql)

86 }

87}

88

89#[derive(Debug, Clone, Serialize, FromRow)]

90pub struct Value(pub String);