so://phie

verbal

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

blob: 1f6f162937eda416b1e4481dc43921ca3cfee176 (3200 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 pub playtime: Option<i64>,

15}

16

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

18pub struct Device {

19 pub id: i32,

20 pub uid: String,

21 pub name: Option<String>,

22 pub account_id: i32,

23}

24

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

26pub struct Station {

27 pub id: i32,

28 pub uid: Option<String>,

29 pub name: String,

30 pub url: String,

31 pub icon: Option<String>,

32 pub country: Option<String>,

33 pub state: Option<String>,

34 pub city: Option<String>,

35 pub is_favorite: Option<bool>,

36 pub is_icon: Option<bool>,

37}

38

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

40pub struct StationDetail {

41 pub id: i32,

42 pub uid: Option<String>,

43 pub name: String,

44 pub url: String,

45 pub description: Option<String>,

46 pub icon: Option<String>,

47 pub homepage: Option<String>,

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

49 pub country: Option<String>,

50 pub state: Option<String>,

51 pub city: Option<String>,

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

53 pub score: i32,

54 pub utc: Option<i32>,

55 pub is_favorite: Option<bool>,

56 pub is_restricted: Option<bool>,

57 pub is_broken: Option<bool>,

58 pub is_no_track_info: Option<bool>,

59 pub is_icon: Option<bool>,

60 pub playtime: Option<i32>,

61 pub color: Option<String>,

62 pub group_id: Option<i32>,

63 pub likes: i64,

64}

65

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

67pub struct StationGroup {

68 pub id: i32,

69 pub name: String,

70 pub description: Option<String>,

71}

72

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

74pub struct Favorite {

75 pub id: i32,

76 pub account_id: i32,

77 pub station_id: String,

78}

79

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

81pub struct Query {

82 pub name: String,

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

84 pub country: Option<String>,

85 pub language: Option<String>,

86 pub page: Option<i32>,

87}

88

89impl ToSql for Query {

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

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

92 writeln!(

93 sql,

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

95 self.name

96 )?;

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

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

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

100 if i > 0 {

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

102 }

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

104 }

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

106 }

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

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

109 }

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

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

112 }

113 Ok(sql)

114 }

115}

116

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

118pub struct Value(pub String);

119

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

121pub struct AddAccount {

122 pub name: String,

123 pub language: String,

124}