so://phie

verbal

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

blob: f37ba1f063f10dfde7fcfe58f54d685a9ebfa65b (3114 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 is_favorite: Option<bool>,

35 pub is_icon: Option<bool>,

36}

37

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

39pub struct StationDetail {

40 pub id: i32,

41 pub uid: Option<String>,

42 pub name: String,

43 pub url: String,

44 pub description: Option<String>,

45 pub icon: Option<String>,

46 pub homepage: Option<String>,

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

48 pub country: Option<String>,

49 pub state: Option<String>,

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

51 pub score: i32,

52 pub is_favorite: Option<bool>,

53 pub is_restricted: Option<bool>,

54 pub is_broken: Option<bool>,

55 pub is_no_track_info: Option<bool>,

56 pub is_icon: Option<bool>,

57 pub playtime: Option<i32>,

58 pub color: Option<String>,

59 pub group_id: Option<i32>,

60 pub likes: i64,

61}

62

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

64pub struct StationGroup {

65 pub id: i32,

66 pub name: String,

67 pub description: Option<String>,

68}

69

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

71pub struct Favorite {

72 pub id: i32,

73 pub account_id: i32,

74 pub station_id: String,

75}

76

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

78pub struct Query {

79 pub name: String,

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

81 pub country: Option<String>,

82 pub language: Option<String>,

83 pub page: Option<i32>,

84}

85

86impl ToSql for Query {

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

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

89 writeln!(

90 sql,

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

92 self.name

93 )?;

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

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

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

97 if i > 0 {

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

99 }

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

101 }

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

103 }

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

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

106 }

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

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

109 }

110 Ok(sql)

111 }

112}

113

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

115pub struct Value(pub String);

116

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

118pub struct AddAccount {

119 pub name: String,

120 pub language: String,

121}