notificationlib/enums/
notification_type.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
use serde::Deserialize;
use serde::Serialize;
use std::str;
use strum_macros::EnumString;
#[cfg(feature = "diesel")]
use {
    diesel::backend::Backend,
    diesel::deserialize::FromSql,
    diesel::pg::Pg,
    diesel::serialize::{IsNull, Output, ToSql},
    diesel::types::Varchar,
    diesel::{deserialize, not_none, serialize},
    diesel::{AsExpression, FromSqlRow},
    std::io::Write,
};

#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, EnumString)]
#[cfg_attr(feature = "diesel", derive(AsExpression, FromSqlRow))]
#[cfg_attr(feature = "diesel", sql_type = "Varchar")]
pub enum NotificationType {
    BehaviourRecord,
    CanteenOrderStatusChange,
    ChildAbsent,
    CourseApproved,
    CourseProgramApproved,
    CourseProgramRejected,
    CourseRejected,
    CurriculumApproved,
    CurriculumRejected,
    EmergencyReport,
    EventSendLocation,
    EventUpdateSessionAccess,
    EventVisitSection,
    FormRequest,
    IncidentReport,
    InventoryStuffRequest,
    InvoiceRefund,
    LessonPlanApproved,
    LessonPlanRejected,
    MedicBooking,
    Payment,
    QuizAnswer,
    QuizPlayStatusChange,
    QuizStarted,
    QuizStopped,
    SecuritySummon,
    TestApproved,
    TestGameAccepted,
    TestGameInvitation,
    TutorLessonApproved,
    TutorLessonRejected,
    TutorNewExercise,
    TutorNewOrder,
    TutorOrderApproved,
    TutorOrderRejected,
    Other,
}

#[cfg(feature = "diesel")]
impl ToSql<Varchar, Pg> for NotificationType {
    fn to_sql<W: Write>(&self, out: &mut Output<W, Pg>) -> serialize::Result {
        match *self {
            NotificationType::CourseProgramApproved => out.write_all(b"CourseProgramApproved")?,
            NotificationType::CourseApproved => out.write_all(b"CourseApproved")?,
            NotificationType::InventoryStuffRequest => out.write_all(b"InventoryStuffRequest")?,
            NotificationType::FormRequest => out.write_all(b"FormRequest")?,
            NotificationType::QuizPlayStatusChange => out.write_all(b"QuizPlayStatusChange")?,
            NotificationType::TutorNewExercise => out.write_all(b"TutorNewExercise")?,
            NotificationType::BehaviourRecord => out.write_all(b"BehaviourRecord")?,
            NotificationType::LessonPlanApproved => out.write_all(b"LessonPlanApproved")?,
            NotificationType::LessonPlanRejected => out.write_all(b"LessonPlanRejected")?,
            NotificationType::CurriculumApproved => out.write_all(b"CurriculumApproved")?,
            NotificationType::TestApproved => out.write_all(b"TestApproved")?,
            NotificationType::ChildAbsent => out.write_all(b"ChildAbsent")?,
            NotificationType::CourseRejected => out.write_all(b"CourseRejected")?,
            NotificationType::CourseProgramRejected => out.write_all(b"CourseProgramRejected")?,
            NotificationType::TutorOrderApproved => out.write_all(b"TutorOrderApproved")?,
            NotificationType::TutorNewOrder => out.write_all(b"TutorNewOrder")?,
            NotificationType::QuizStarted => out.write_all(b"QuizStarted")?,
            NotificationType::QuizStopped => out.write_all(b"QuizStopped")?,
            NotificationType::TestGameAccepted => out.write_all(b"TestGameAccepted")?,
            NotificationType::CurriculumRejected => out.write_all(b"CurriculumRejected")?,
            NotificationType::TutorLessonApproved => out.write_all(b"TutorLessonApproved")?,
            NotificationType::TutorLessonRejected => out.write_all(b"TutorLessonRejected")?,
            NotificationType::TutorOrderRejected => out.write_all(b"TutorOrderRejected")?,
            NotificationType::InvoiceRefund => out.write_all(b"InvoiceRefund")?,
            NotificationType::Payment => out.write_all(b"Payment")?,
            NotificationType::MedicBooking => out.write_all(b"MedicBooking")?,
            NotificationType::EventUpdateSessionAccess => out.write_all(b"EventUpdateSessionAccess")?,
            NotificationType::EventVisitSection => out.write_all(b"EventVisitSection")?,
            NotificationType::EventSendLocation => out.write_all(b"EventSendLocation")?,
            NotificationType::CanteenOrderStatusChange => out.write_all(b"CanteenOrderStatusChange")?,
            NotificationType::TestGameInvitation => out.write_all(b"TestGameInvitation")?,
            NotificationType::QuizAnswer => out.write_all(b"QuizAnswer")?,
            NotificationType::SecuritySummon => out.write_all(b"SecuritySummon")?,
            NotificationType::EmergencyReport => out.write_all(b"EmergencyReport")?,
            NotificationType::IncidentReport => out.write_all(b"IncidentReport")?,
            NotificationType::Other => out.write_all(b"Other")?,
        }
        Ok(IsNull::No)
    }
}

#[cfg(feature = "diesel")]
impl FromSql<Varchar, Pg> for NotificationType {
    fn from_sql(bytes: Option<&<Pg as Backend>::RawValue>) -> deserialize::Result<Self> {
        match not_none!(bytes) {
            b"CourseApproved" => Ok(NotificationType::CourseApproved),
            b"CourseProgramApproved" => Ok(NotificationType::CourseProgramApproved),
            b"InventoryStuffRequest" => Ok(NotificationType::InventoryStuffRequest),
            b"FormRequest" => Ok(NotificationType::FormRequest),
            b"QuizPlayStatusChange" => Ok(NotificationType::QuizPlayStatusChange),
            b"TutorNewExercise" => Ok(NotificationType::TutorNewExercise),
            b"BehaviourRecord" => Ok(NotificationType::BehaviourRecord),
            b"LessonPlanApproved" => Ok(NotificationType::LessonPlanApproved),
            b"LessonPlanRejected" => Ok(NotificationType::LessonPlanRejected),
            b"CurriculumApproved" => Ok(NotificationType::CurriculumApproved),
            b"TestApproved" => Ok(NotificationType::TestApproved),
            b"ChildAbsent" => Ok(NotificationType::ChildAbsent),
            b"CourseRejected" => Ok(NotificationType::CourseRejected),
            b"CourseProgramRejected" => Ok(NotificationType::CourseProgramRejected),
            b"TutorOrderApproved" => Ok(NotificationType::TutorOrderApproved),
            b"TutorNewOrder" => Ok(NotificationType::TutorNewOrder),
            b"QuizStarted" => Ok(NotificationType::QuizStarted),
            b"QuizStopped" => Ok(NotificationType::QuizStopped),
            b"TestGameAccepted" => Ok(NotificationType::TestGameAccepted),
            b"CurriculumRejected" => Ok(NotificationType::CurriculumRejected),
            b"TutorLessonApproved" => Ok(NotificationType::TutorLessonApproved),
            b"TutorLessonRejected" => Ok(NotificationType::TutorLessonRejected),
            b"TutorOrderRejected" => Ok(NotificationType::TutorOrderRejected),
            b"InvoiceRefund" => Ok(NotificationType::InvoiceRefund),
            b"Payment" => Ok(NotificationType::Payment),
            b"MedicBooking" => Ok(NotificationType::MedicBooking),
            b"EventUpdateSessionAccess" => Ok(NotificationType::EventUpdateSessionAccess),
            b"EventVisitSection" => Ok(NotificationType::EventVisitSection),
            b"EventSendLocation" => Ok(NotificationType::EventSendLocation),
            b"CanteenOrderStatusChange" => Ok(NotificationType::CanteenOrderStatusChange),
            b"TestGameInvitation" => Ok(NotificationType::TestGameInvitation),
            b"QuizAnswer" => Ok(NotificationType::QuizAnswer),
            b"SecuritySummon" => Ok(NotificationType::SecuritySummon),
            b"EmergencyReport" => Ok(NotificationType::EmergencyReport),
            b"IncidentReport" => Ok(NotificationType::IncidentReport),
            b"Other" => Ok(NotificationType::Other),
            _ => Err("Unrecognized enum variant".into()),
        }
    }
}