so://phie

verbal

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

blob: 86e3b54f0d2dc05798e261732852035e58efae12 (2885 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 country: Option<String>,

32 pub state: Option<String>,

33 pub is_favorite: Option<bool>,

34 pub is_icon: Option<bool>,

35}

36

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

38pub struct StationDetail {

39 pub id: i32,

40 pub uid: String,

41 pub name: String,

42 pub url: String,

43 pub description: Option<String>,

44 pub icon: Option<String>,

45 pub homepage: Option<String>,

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

47 pub country: Option<String>,

48 pub state: Option<String>,

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

50 pub score: i32,

51 pub is_favorite: Option<bool>,

52 pub is_restricted: Option<bool>,

53 pub is_broken: Option<bool>,

54 pub is_no_track_info: Option<bool>,

55 pub is_icon: Option<bool>,

56 pub playtime: Option<i32>,

57 pub color: Option<String>,

58 pub group_id: Option<i32>,

59}

60

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

62pub struct Favorite {

63 pub id: i32,

64 pub account_id: i32,

65 pub station_id: String,

66}

67

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

69pub struct Query {

70 pub name: String,

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

72 pub country: Option<String>,

73 pub language: Option<String>,

74 pub page: Option<i32>,

75}

76

77impl ToSql for Query {

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

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

80 writeln!(

81 sql,

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

83 self.name

84 )?;

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

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

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

88 if i > 0 {

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

90 }

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

92 }

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

94 }

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

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

97 }

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

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

100 }

101 Ok(sql)

102 }

103}

104

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

106pub struct Value(pub String);

107

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

109pub struct AddAccount {

110 pub name: String,

111 pub language: String,

112}