meegle/work_hour/
api.rs

1use super::types::*;
2use crate::client::{AuthType, Client};
3use crate::error::ApiResult;
4
5pub trait WorkHourApi {
6    /// 获取工作项的工时记录列表
7    /// 该接口仅在安装使用官方插件-[工时登记]时有效,用于获取指定空间和工作项类型下的指定工作项实例的工时记录详细信息
8    fn get_work_hour_records(
9        &self,
10        request: GetWorkHourRecordsRequest,
11        auth: AuthType,
12    ) -> impl std::future::Future<Output = ApiResult<GetWorkHourRecordsResponse>> + Send;
13
14    /// 创建实际工时
15    /// 该接口仅在安装使用官方插件-[工时登记]时有效,用于指定空间和工作项类型下的指定工作项实例下添加工时记录信息
16    fn create_work_hour_record(
17        &self,
18        request: CreateWorkHourRecordRequest,
19        auth: AuthType,
20    ) -> impl std::future::Future<Output = ApiResult<CreateWorkHourRecordResponse>> + Send;
21
22    /// 更新实际工时
23    /// 该接口仅在安装使用官方插件-[工时登记]时有效,用于更新指定空间和工作项类型下的指定工作项实例的某个操作者的多个工时记录
24    fn update_work_hour_record(
25        &self,
26        request: UpdateWorkHourRecordRequest,
27        auth: AuthType,
28    ) -> impl std::future::Future<Output = ApiResult<UpdateWorkHourRecordResponse>> + Send;
29
30    /// 删除工时记录
31    /// 该接口仅在安装并使用官方插件-[工时登记]时有效,用于删除指定空间和工作项类型下的指定工作项实例的某个操作者的多个工时记录
32    fn delete_work_hour_record(
33        &self,
34        request: DeleteWorkHourRecordRequest,
35        auth: AuthType,
36    ) -> impl std::future::Future<Output = ApiResult<DeleteWorkHourRecordResponse>> + Send;
37}
38
39impl WorkHourApi for Client {
40    async fn get_work_hour_records(
41        &self,
42        request: GetWorkHourRecordsRequest,
43        auth: AuthType,
44    ) -> ApiResult<GetWorkHourRecordsResponse> {
45        Ok(self
46            .post("work_item/man_hour/records", &request, auth)
47            .await?)
48    }
49
50    async fn create_work_hour_record(
51        &self,
52        request: CreateWorkHourRecordRequest,
53        auth: AuthType,
54    ) -> ApiResult<CreateWorkHourRecordResponse> {
55        Ok(self
56            .post(
57                &format!(
58                    "{}/work_item/{}/{}/work_hour_record",
59                    request.project_key, request.work_item_type_key, request.work_item_id
60                ),
61                &request,
62                auth,
63            )
64            .await?)
65    }
66
67    async fn update_work_hour_record(
68        &self,
69        request: UpdateWorkHourRecordRequest,
70        auth: AuthType,
71    ) -> ApiResult<UpdateWorkHourRecordResponse> {
72        Ok(self
73            .put(
74                &format!(
75                    "{}/work_item/{}/{}/work_hour_record",
76                    request.project_key, request.work_item_type_key, request.work_item_id
77                ),
78                &request,
79                auth,
80            )
81            .await?)
82    }
83
84    async fn delete_work_hour_record(
85        &self,
86        request: DeleteWorkHourRecordRequest,
87        auth: AuthType,
88    ) -> ApiResult<DeleteWorkHourRecordResponse> {
89        Ok(self
90            .delete_with_body(
91                &format!(
92                    "{}/work_item/{}/{}/work_hour_record",
93                    request.project_key, request.work_item_type_key, request.work_item_id
94                ),
95                &request,
96                auth,
97            )
98            .await?)
99    }
100}