so://phie

verbal

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

blob: ae364e33f2d8efa29c396de031a7575d77861d58 (2295 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 account_id: i32,

21}

22

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

24pub struct Station {

25 pub id: i32,

26 pub uid: String,

27 pub name: String,

28 pub url: String,

29 pub icon: Option<String>,

30 pub homepage: Option<String>,

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

32 pub country: Option<String>,

33 pub state: Option<String>,

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

35 pub score: i32,

36 pub is_favorite: Option<bool>,

37 pub is_restricted: Option<bool>,

38 pub is_broken: Option<bool>,

39 pub is_no_track_info: Option<bool>,

40 // pub is_hidden: Option<bool>,

41}

42

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

44pub struct Favorite {

45 pub id: i32,

46 pub account_id: i32,

47 pub station_id: String,

48}

49

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

51pub struct Query {

52 pub name: String,

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

54 pub country: Option<String>,

55 pub language: Option<String>,

56 pub page: Option<i32>,

57}

58

59impl ToSql for Query {

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

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

62 writeln!(

63 sql,

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

65 self.name

66 )?;

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

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

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

70 if i > 0 {

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

72 }

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

74 }

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

76 }

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

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

79 }

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

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

82 }

83 Ok(sql)

84 }

85}

86

87#[derive(Debug, Clone, Deserialize)]

88pub struct StationId {

89 pub id: i32,

90}