so://phie

verbal

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

blob: 66024ea1f3e81e3374722a36aff974651257506f (3067 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 pub likes: i64,

60}

61

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

63pub struct StationGroup {

64 pub id: i32,

65 pub name: String,

66 pub description: Option<String>,

67}

68

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

70pub struct Favorite {

71 pub id: i32,

72 pub account_id: i32,

73 pub station_id: String,

74}

75

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

77pub struct Query {

78 pub name: String,

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

80 pub country: Option<String>,

81 pub language: Option<String>,

82 pub page: Option<i32>,

83}

84

85impl ToSql for Query {

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

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

88 writeln!(

89 sql,

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

91 self.name

92 )?;

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

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

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

96 if i > 0 {

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

98 }

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

100 }

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

102 }

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

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

105 }

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

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

108 }

109 Ok(sql)

110 }

111}

112

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

114pub struct Value(pub String);

115

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

117pub struct AddAccount {

118 pub name: String,

119 pub language: String,

120}