1use super::{IClass, IClassError, Response};
4use serde::Deserialize;
5use std::fmt;
6
7#[derive(Clone, Debug, Deserialize)]
9pub struct CheckInResult {
10 #[serde(rename = "stuSignId")]
13 pub id: String,
14 #[serde(
16 rename = "stuSignStatus",
17 deserialize_with = "super::util::deserialize_str_to_bool"
18 )]
19 pub status: bool,
20}
21
22impl IClass {
23 pub async fn check_in_by_uuid(
33 &self,
34 schedule_uuid: &str,
35 timestamp: u128,
36 ) -> Result<CheckInResult, IClassError> {
37 let user_session = self.get_user_session()?;
39 let url = self.api_root.join("app/course/stu_scan_sign.action")?;
40 let response: Response<CheckInResult> = self
41 .client
42 .get(url)? .header("sessionId", &user_session.session_id)?
44 .query(&[
45 ("timeTableId", schedule_uuid),
46 ("timestamp", ×tamp.to_string()),
47 ("id", user_session.id.as_str()),
48 ])?
49 .send()
50 .await?
51 .json()
52 .await?;
53 let check_in_result = response.into_result()?;
54
55 Ok(check_in_result)
56 }
57
58 pub async fn check_in_by_id(
68 &self,
69 schedule_id: &str,
70 timestamp: u128,
71 ) -> Result<CheckInResult, IClassError> {
72 let user_session = self.get_user_session()?;
74 let url = self.api_root.join("app/course/stu_scan_sign.action")?;
75 let response: Response<CheckInResult> = self
76 .client
77 .get(url)? .header("sessionId", &user_session.session_id)?
79 .query(&[
80 ("courseSchedId", schedule_id),
81 ("timestamp", ×tamp.to_string()),
82 ("id", user_session.id.as_str()),
83 ])?
84 .send()
85 .await?
86 .json()
87 .await?;
88 let check_in_result = response.into_result()?;
89
90 Ok(check_in_result)
91 }
92}
93
94impl fmt::Display for CheckInResult {
95 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
96 let Self { id, status } = self;
97 let status = if *status {
98 "🟢 Success"
99 } else {
100 "🔴 Failed"
101 };
102 write!(f, "{status} (#{id})")
103 }
104}