Skip to content
This repository was archived by the owner on Feb 24, 2025. It is now read-only.

Commit e1d0ef5

Browse files
committed
feat: add the prototype of volunteer to devide members and itself
1 parent a2a235a commit e1d0ef5

File tree

6 files changed

+70
-150
lines changed

6 files changed

+70
-150
lines changed

Cargo.lock

Lines changed: 0 additions & 136 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ tracing-subscriber = { version = "0.3.18", features = [
5555
"regex",
5656
] }
5757
uuid = { version = "1.8.0", features = ["v1", "v4", "serde"] }
58-
xlsxwriter = "0.6.0"
5958
zerocopy = "0.7.32"
6059

6160
[profile.release]

src/models/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ pub mod groups;
44
pub mod notifications;
55
pub mod response;
66
pub mod users;
7+
pub mod volunteers;

src/models/volunteers.rs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
use crate::models::activities::datetime_or_u64;
2+
use bson::oid::ObjectId;
3+
use serde::{Deserialize, Serialize};
4+
use std::str::FromStr;
5+
6+
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)]
7+
pub enum VolunteerType {
8+
Mobile,
9+
Social,
10+
Practice,
11+
}
12+
13+
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)]
14+
pub enum VolunteerStatus {
15+
Pending,
16+
Effective,
17+
Refused,
18+
}
19+
20+
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)]
21+
#[serde(rename_all = "kebab-case")]
22+
pub enum VolunteerMode {
23+
OnCampus,
24+
OffCampus,
25+
SocialPractice,
26+
}
27+
28+
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)]
29+
pub enum VolunteerMemberStatus {
30+
Effective,
31+
Pending,
32+
Refused,
33+
Rejected,
34+
Draft,
35+
}
36+
37+
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
38+
pub struct VolunteerMember {
39+
pub _id: ObjectId,
40+
pub user: ObjectId,
41+
pub status: VolunteerMemberStatus,
42+
pub impression: Option<String>,
43+
pub duration: f64,
44+
pub mode: VolunteerMode,
45+
}
46+
47+
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
48+
pub struct Volunteer {
49+
pub _id: ObjectId,
50+
pub name: String,
51+
pub description: Option<String>,
52+
#[serde(rename = "type")]
53+
pub volunteer_type: VolunteerType,
54+
pub status: VolunteerStatus,
55+
#[serde(deserialize_with = "datetime_or_u64")]
56+
pub date: u64,
57+
pub creator: ObjectId,
58+
pub location: String,
59+
pub members: Vec<ObjectId>,
60+
}

src/utils/exports/convert.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1-
def to_excel(input_path: str, output_path: str):
2-
import pandas as pd
3-
pd.read_csv(input_path, encoding='utf-8').to_excel(output_path, index=False)
1+
def arrow_to_excel(
2+
arrow_batch,
3+
dest_path: str,
4+
):
5+
import polars as pl
6+
batch = pl.from_arrow(arrow_batch)
7+
batch.write_excel(dest_path)

src/utils/exports/csv_to_excel.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,8 @@ pub fn to_excel(input: String, output: String) -> PyResult<()> {
88
"Start to convert to excel {} to {} with python.",
99
input, output
1010
);
11-
let bound = PyModule::from_code_bound(
12-
py,
13-
r#"
14-
def to_excel(input_path: str, output_path: str):
15-
import pandas as pd
16-
pd.read_csv(input_path, encoding='utf-8').to_excel(output_path, index=False)
17-
"#,
18-
"",
19-
"",
20-
);
11+
let bound =
12+
PyModule::from_code_bound(py, include_str!("../../utils/exports/convert.py"), "", "");
2113
if let Err(_) = bound {
2214
return Err(pyo3::PyErr::new::<pyo3::exceptions::PyRuntimeError, _>(
2315
"Failed to get Python function",

0 commit comments

Comments
 (0)