so://phie

verbal

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

blob: e1ac699360c13d93662b39c706e15da0273c999b (3047 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, Clone, Serialize, Deserialize, FromRow)]

62pub struct StationGroup {

63 pub id: i32,

64 pub name: String,

65 pub description: Option<String>,

66}

67

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

69pub struct Favorite {

70 pub id: i32,

71 pub account_id: i32,

72 pub station_id: String,

73}

74

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

76pub struct Query {

77 pub name: String,

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

79 pub country: Option<String>,

80 pub language: Option<String>,

81 pub page: Option<i32>,

82}

83

84impl ToSql for Query {

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

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

87 writeln!(

88 sql,

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

90 self.name

91 )?;

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

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

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

95 if i > 0 {

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

97 }

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

99 }

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

101 }

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

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

104 }

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

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

107 }

108 Ok(sql)

109 }

110}

111

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

113pub struct Value(pub String);

114

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

116pub struct AddAccount {

117 pub name: String,

118 pub language: String,

119}