lnu_elytra/method/
select_course.rs1use serde::{Deserialize, Serialize};
2
3use crate::{
4 Client,
5 error::{Error, R},
6};
7
8impl Client {
9 pub async fn select_course(
11 &self,
12 course_id: &str,
13 course_do_id: &str,
14 ) -> R<SelectCourseResponse> {
15 let xh = self
16 .stores
17 .get("xh_id")
18 .ok_or(Error::MissingField("xh_id"))?;
19
20 if xh.len() < 8 {
21 return Err(Error::InvalidXhId);
22 }
23
24 #[derive(Serialize, Debug)]
25 struct SelectCouresData<'a> {
26 jxb_ids: &'a str,
28 kch_id: &'a str,
29 qz: &'a str, njdm_id: &'a str,
31 zyh_id: &'a str,
32 }
33
34 let res = self
35 .post(&Client::SELECT_COURSE_URL)
36 .form(&SelectCouresData {
37 jxb_ids: course_do_id,
38 kch_id: course_id,
39 qz: "0",
40 njdm_id: &xh[0..4],
41 zyh_id: &xh[4..8],
42 })
43 .send()
44 .await?;
45
46 let res = res.json::<SelectCourseResponse>().await?;
47
48 Ok(res)
49 }
50}
51
52#[cfg_attr(
62 feature = "__pyo3",
63 cfg_attr(test, pyo3_stub_gen::derive::gen_stub_pyclass),
64 pyo3::pyclass(get_all)
65)]
66#[derive(Deserialize, Debug)]
67pub struct SelectCourseResponse {
68 pub flag: String,
69 pub msg: Option<String>,
70}
71
72impl SelectCourseResponse {
73 pub fn is_success(&self) -> bool {
74 self.flag == "1"
75 }
76
77 pub fn msg(&self) -> Option<&str> {
78 self.msg.as_deref()
79 }
80}