so://phie

verbal

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

blob: 53f9d63c5223b524a3aadfe4f78dd4edfb8b63cc (3174 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 is_favorite: Option<bool>,

55 pub is_restricted: Option<bool>,

56 pub is_broken: Option<bool>,

57 pub is_no_track_info: Option<bool>,

58 pub is_icon: Option<bool>,

59 pub playtime: Option<i32>,

60 pub color: Option<String>,

61 pub group_id: Option<i32>,

62 pub likes: i64,

63}

64

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

66pub struct StationGroup {

67 pub id: i32,

68 pub name: String,

69 pub description: Option<String>,

70}

71

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

73pub struct Favorite {

74 pub id: i32,

75 pub account_id: i32,

76 pub station_id: String,

77}

78

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

80pub struct Query {

81 pub name: String,

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

83 pub country: Option<String>,

84 pub language: Option<String>,

85 pub page: Option<i32>,

86}

87

88impl ToSql for Query {

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

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

91 writeln!(

92 sql,

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

94 self.name

95 )?;

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

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

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

99 if i > 0 {

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

101 }

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

103 }

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

105 }

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

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

108 }

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

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

111 }

112 Ok(sql)

113 }

114}

115

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

117pub struct Value(pub String);

118

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

120pub struct AddAccount {

121 pub name: String,

122 pub language: String,

123}