Skip to content

Commit 6065389

Browse files
committed
📝 定义了所有系统模块下的路由。
1 parent 6dd0523 commit 6065389

File tree

8 files changed

+646
-4
lines changed

8 files changed

+646
-4
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
use anyhow::Result;
2+
use serde::{Deserialize, Serialize};
3+
4+
use axum::{extract::Query, http::StatusCode, response::IntoResponse};
5+
6+
use crate::middlewares::ExtractAuthInfo;
7+
use _utils::models::wrapper::Pagination;
8+
9+
/// 设备状态
10+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11+
pub enum Action {
12+
#[serde(rename = "LOGIN")]
13+
Login,
14+
}
15+
16+
/// 操作日志排序枚举
17+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
18+
pub enum ActionLogSort {
19+
#[serde(rename = "action-")]
20+
Action,
21+
#[serde(rename = "deviceId-")]
22+
DeviceId,
23+
#[serde(rename = "id-")]
24+
Id,
25+
#[serde(rename = "ipv4-")]
26+
Ipv4,
27+
#[serde(rename = "isError-")]
28+
IsError,
29+
#[serde(rename = "action+")]
30+
SortAction,
31+
#[serde(rename = "deviceId+")]
32+
SortDeviceId,
33+
#[serde(rename = "id+")]
34+
SortId,
35+
#[serde(rename = "ipv4+")]
36+
SortIpv4,
37+
#[serde(rename = "isError+")]
38+
SortIsError,
39+
#[serde(rename = "updateTime+")]
40+
SortUpdateTime,
41+
#[serde(rename = "updateTime-")]
42+
UpdateTime,
43+
}
44+
45+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
46+
#[serde(rename_all = "camelCase")]
47+
pub struct ActionLogParams {
48+
/// 设备状态
49+
pub action: Option<Action>,
50+
#[serde(flatten)]
51+
pub pagination: Option<Pagination>,
52+
/// 设备ID
53+
pub device_id: Option<String>,
54+
/// IPv4
55+
pub ipv4: Option<String>,
56+
/// 是否是错误日志
57+
pub is_error: Option<bool>,
58+
/// 排序
59+
pub sort: Option<Vec<ActionLogSort>>,
60+
/// 用户ID
61+
pub user_id: Option<i64>,
62+
}
63+
64+
/// 获取操作日志
65+
/// POST /action_log/list
66+
#[tracing::instrument(skip_all)]
67+
pub async fn list(
68+
ExtractAuthInfo(auth): ExtractAuthInfo,
69+
Query(query): Query<ActionLogParams>,
70+
) -> Result<impl IntoResponse, (StatusCode, String)> {
71+
Ok(())
72+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
use anyhow::Result;
2+
use chrono::{DateTime, Local};
3+
use serde::{Deserialize, Serialize};
4+
5+
use axum::{
6+
extract::{Json, Path},
7+
http::StatusCode,
8+
response::IntoResponse,
9+
};
10+
11+
use crate::middlewares::ExtractAuthInfo;
12+
13+
/// 获取指定槽位的最新存档
14+
/// GET /archive/last/{slot_index}
15+
#[tracing::instrument(skip_all)]
16+
pub async fn get_last(
17+
ExtractAuthInfo(auth): ExtractAuthInfo,
18+
Path(slot_index): Path<u64>,
19+
) -> Result<impl IntoResponse, (StatusCode, String)> {
20+
Ok(())
21+
}
22+
23+
/// 获取指定槽位的所有历史存档
24+
/// GET /archive/history/{slot_index}
25+
#[tracing::instrument(skip_all)]
26+
pub async fn get_history(
27+
ExtractAuthInfo(auth): ExtractAuthInfo,
28+
Path(slot_index): Path<u64>,
29+
) -> Result<impl IntoResponse, (StatusCode, String)> {
30+
Ok(())
31+
}
32+
33+
/// 获取所有槽位的历史存档
34+
/// GET /archive/all_history
35+
#[tracing::instrument(skip_all)]
36+
pub async fn get_all_history(
37+
ExtractAuthInfo(auth): ExtractAuthInfo,
38+
) -> Result<impl IntoResponse, (StatusCode, String)> {
39+
Ok(())
40+
}
41+
42+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
43+
#[serde(rename_all = "camelCase")]
44+
pub struct ArchiveSaveParams {
45+
pub time: DateTime<Local>,
46+
pub archive: String,
47+
pub history_index: u32,
48+
}
49+
50+
/// 新建存档槽位并将存档存入
51+
/// PUT /archive/{slot_index}/{name}
52+
#[tracing::instrument(skip_all)]
53+
pub async fn put(
54+
ExtractAuthInfo(auth): ExtractAuthInfo,
55+
Path((slot_index, name)): Path<(u64, String)>,
56+
Json(payload): Json<ArchiveSaveParams>,
57+
) -> Result<impl IntoResponse, (StatusCode, String)> {
58+
Ok(())
59+
}
60+
61+
/// 存档入指定槽位
62+
/// POST /archive/save/{slot_index}
63+
#[tracing::instrument(skip_all)]
64+
pub async fn save(
65+
ExtractAuthInfo(auth): ExtractAuthInfo,
66+
Path(slot_index): Path<u64>,
67+
Json(payload): Json<ArchiveSaveParams>,
68+
) -> Result<impl IntoResponse, (StatusCode, String)> {
69+
Ok(())
70+
}
71+
72+
/// 重命名指定槽位
73+
/// POST /archive/rename/{slot_index}/{new_name}
74+
#[tracing::instrument(skip_all)]
75+
pub async fn rename(
76+
ExtractAuthInfo(auth): ExtractAuthInfo,
77+
Path((slot_index, new_name)): Path<(u64, String)>,
78+
) -> Result<impl IntoResponse, (StatusCode, String)> {
79+
Ok(())
80+
}
81+
82+
/// 删除最近一次存档(恢复为上次存档)
83+
/// DELETE /archive/restore/{slot_index}
84+
#[tracing::instrument(skip_all)]
85+
pub async fn restore(
86+
ExtractAuthInfo(auth): ExtractAuthInfo,
87+
Path(slot_index): Path<u64>,
88+
) -> Result<impl IntoResponse, (StatusCode, String)> {
89+
Ok(())
90+
}
91+
92+
/// 删除存档槽位
93+
/// DELETE /archive/slot/{slot_index}
94+
#[tracing::instrument(skip_all)]
95+
pub async fn delete_slot(
96+
ExtractAuthInfo(auth): ExtractAuthInfo,
97+
Path(slot_index): Path<u64>,
98+
) -> Result<impl IntoResponse, (StatusCode, String)> {
99+
Ok(())
100+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
use anyhow::Result;
2+
use serde::{Deserialize, Serialize};
3+
4+
use axum::{extract::Json, http::StatusCode, response::IntoResponse};
5+
6+
use crate::middlewares::ExtractAuthInfo;
7+
use _utils::models::wrapper::Pagination;
8+
9+
/// 格式:字段+ 字段-
10+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11+
pub enum DeviceSort {
12+
#[serde(rename = "deviceId-")]
13+
DeviceId,
14+
#[serde(rename = "id-")]
15+
Id,
16+
#[serde(rename = "ipv4-")]
17+
Ipv4,
18+
#[serde(rename = "lastLoginTime-")]
19+
LastLoginTime,
20+
#[serde(rename = "deviceId+")]
21+
SortDeviceId,
22+
#[serde(rename = "id+")]
23+
SortId,
24+
#[serde(rename = "ipv4+")]
25+
SortIpv4,
26+
#[serde(rename = "lastLoginTime+")]
27+
SortLastLoginTime,
28+
#[serde(rename = "status+")]
29+
SortStatus,
30+
#[serde(rename = "updateTime+")]
31+
SortUpdateTime,
32+
#[serde(rename = "status-")]
33+
Status,
34+
#[serde(rename = "updateTime-")]
35+
UpdateTime,
36+
}
37+
38+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
39+
#[serde(rename_all = "camelCase")]
40+
pub struct DeviceListParams {
41+
#[serde(flatten)]
42+
pub pagination: Option<Pagination>,
43+
/// 设备ID
44+
pub device_id: Option<String>,
45+
/// IPv4
46+
pub ipv4: Option<String>,
47+
/// 排序
48+
pub sort: Option<Vec<DeviceSort>>,
49+
/// 设备状态
50+
pub status: Option<i64>,
51+
/// 用户ID
52+
pub user_id: i64,
53+
}
54+
55+
/// 获取用户设备
56+
/// POST /device/list
57+
#[tracing::instrument(skip_all)]
58+
pub async fn list(
59+
ExtractAuthInfo(auth): ExtractAuthInfo,
60+
Json(payload): Json<DeviceListParams>,
61+
) -> Result<impl IntoResponse, (StatusCode, String)> {
62+
Ok(())
63+
}
64+
65+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
66+
#[serde(rename_all = "camelCase")]
67+
pub struct DeviceUpdateParams {
68+
/// ID
69+
pub id: i64,
70+
pub status: Option<i64>,
71+
}
72+
73+
/// 更新用户设备信息
74+
/// POST /device/update
75+
#[tracing::instrument(skip_all)]
76+
pub async fn update(
77+
ExtractAuthInfo(auth): ExtractAuthInfo,
78+
Json(payload): Json<DeviceUpdateParams>,
79+
) -> Result<impl IntoResponse, (StatusCode, String)> {
80+
Ok(())
81+
}
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
use anyhow::Result;
2+
use serde::{Deserialize, Serialize};
3+
4+
use axum::{
5+
extract::{Json, Path},
6+
http::StatusCode,
7+
response::IntoResponse,
8+
};
9+
10+
use crate::middlewares::ExtractAuthInfo;
11+
use _utils::{models::wrapper::Pagination, types::AccessPolicyItemEnum};
12+
13+
/// 获取用户邀请列表的请求参数
14+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
15+
#[serde(rename_all = "camelCase")]
16+
pub struct InvitationListRequest {
17+
/// 邀请码
18+
pub code: Option<String>,
19+
#[serde(flatten)]
20+
pub pagination: Option<Pagination>,
21+
/// 排序
22+
pub sort: Option<Vec<InvitationSort>>,
23+
/// 用户名
24+
pub username: Option<String>,
25+
}
26+
27+
/// 邀请排序枚举
28+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
29+
pub enum InvitationSort {
30+
#[serde(rename = "createTime-")]
31+
CreateTime,
32+
#[serde(rename = "id-")]
33+
Id,
34+
#[serde(rename = "createTime+")]
35+
SortCreateTime,
36+
#[serde(rename = "id+")]
37+
SortId,
38+
#[serde(rename = "updateTime+")]
39+
SortUpdateTime,
40+
#[serde(rename = "username+")]
41+
SortUsername,
42+
#[serde(rename = "updateTime-")]
43+
UpdateTime,
44+
#[serde(rename = "username-")]
45+
Username,
46+
}
47+
48+
/// 新增/更新用户邀请的请求参数
49+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
50+
#[serde(rename_all = "camelCase")]
51+
pub struct InvitationUpdateRequest {
52+
/// 权限策略
53+
pub access_policy: Vec<AccessPolicyItemEnum>,
54+
/// 邀请码
55+
pub code: String,
56+
/// 备注
57+
pub remark: String,
58+
/// 角色列表
59+
pub role_id: i64,
60+
/// 用户名
61+
pub username: String,
62+
}
63+
64+
/// 使用用户邀请的请求参数
65+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
66+
#[serde(rename_all = "camelCase")]
67+
pub struct InvitationConsumeRequest {
68+
/// 邀请码
69+
pub code: String,
70+
/// 用户名
71+
pub username: String,
72+
}
73+
74+
/// 检查用户邀请数据的请求参数
75+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
76+
#[serde(rename_all = "camelCase")]
77+
pub struct InvitationInfoRequest {
78+
/// 邀请码
79+
pub code: String,
80+
}
81+
82+
/// 获取用户邀请列表
83+
/// POST /invitation/list
84+
#[tracing::instrument(skip_all)]
85+
pub async fn list(
86+
ExtractAuthInfo(auth): ExtractAuthInfo,
87+
Json(payload): Json<InvitationListRequest>,
88+
) -> Result<impl IntoResponse, (StatusCode, String)> {
89+
Ok(())
90+
}
91+
92+
/// 新增/更新用户邀请
93+
/// POST /invitation/update
94+
#[tracing::instrument(skip_all)]
95+
pub async fn update(
96+
ExtractAuthInfo(auth): ExtractAuthInfo,
97+
Json(payload): Json<InvitationUpdateRequest>,
98+
) -> Result<impl IntoResponse, (StatusCode, String)> {
99+
Ok(())
100+
}
101+
102+
/// 检查用户邀请数据
103+
/// POST /invitation/info
104+
#[tracing::instrument(skip_all)]
105+
pub async fn info(
106+
ExtractAuthInfo(auth): ExtractAuthInfo,
107+
Json(payload): Json<InvitationInfoRequest>,
108+
) -> Result<impl IntoResponse, (StatusCode, String)> {
109+
Ok(())
110+
}
111+
112+
/// 使用用户邀请
113+
/// POST /invitation/consume
114+
#[tracing::instrument(skip_all)]
115+
pub async fn consume(
116+
ExtractAuthInfo(auth): ExtractAuthInfo,
117+
Json(payload): Json<InvitationConsumeRequest>,
118+
) -> Result<impl IntoResponse, (StatusCode, String)> {
119+
Ok(())
120+
}
121+
122+
/// 删除用户邀请
123+
/// DELETE /invitation/{invitation_id}
124+
#[tracing::instrument(skip_all)]
125+
pub async fn delete(
126+
ExtractAuthInfo(auth): ExtractAuthInfo,
127+
Path(invitation_id): Path<u64>,
128+
) -> Result<impl IntoResponse, (StatusCode, String)> {
129+
Ok(())
130+
}

0 commit comments

Comments
 (0)