so://phie

verbal

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

blob: 053c8afbe7ced82554e8aa14202cb32ce96ce5bb (2742 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}

59

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

61pub struct Favorite {

62 pub id: i32,

63 pub account_id: i32,

64 pub station_id: String,

65}

66

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

68pub struct Query {

69 pub name: String,

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

71 pub country: Option<String>,

72 pub language: Option<String>,

73 pub page: Option<i32>,

74}

75

76impl ToSql for Query {

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

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

79 writeln!(

80 sql,

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

82 self.name

83 )?;

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

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

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

87 if i > 0 {

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

89 }

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

91 }

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

93 }

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

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

96 }

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

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

99 }

100 Ok(sql)

101 }

102}

103

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

105pub struct Value(pub String);