openlark_platform/admin/v1/badge_image/
create.rs1use openlark_core::{
5 SDKResult,
6 api::{ApiRequest, ApiResponseTrait, ResponseFormat},
7 config::Config,
8 http::Transport,
9 req_option::RequestOption,
10 validate_required,
11};
12use serde::{Deserialize, Serialize};
13
14pub struct CreateBadgeImageRequestBuilder {
16 image: String,
17 config: Config,
18}
19
20impl CreateBadgeImageRequestBuilder {
21 pub fn new(config: Config) -> Self {
23 Self {
24 image: String::new(),
25 config,
26 }
27 }
28
29 pub fn image(mut self, image: impl Into<String>) -> Self {
31 self.image = image.into();
32 self
33 }
34
35 pub async fn execute(self) -> SDKResult<CreateBadgeImageResponse> {
37 self.execute_with_options(RequestOption::default()).await
38 }
39
40 pub async fn execute_with_options(
42 self,
43 option: RequestOption,
44 ) -> SDKResult<CreateBadgeImageResponse> {
45 validate_required!(self.image, "图片不能为空");
46
47 let request_body = CreateBadgeImageRequest { image: self.image };
48 let api_request: ApiRequest<CreateBadgeImageResponse> =
49 ApiRequest::post("/open-apis/admin/v1/badge_images")
50 .body(serde_json::to_value(&request_body)?);
51
52 Transport::request_typed(api_request, &self.config, Some(option), "上传勋章图片").await
53 }
54}
55
56#[derive(Debug, Serialize)]
57struct CreateBadgeImageRequest {
58 image: String,
59}
60
61#[derive(Debug, Clone, Deserialize, Serialize)]
62pub struct CreateBadgeImageResponse {
64 pub image_id: String,
66 pub image_url: String,
68}
69
70impl ApiResponseTrait for CreateBadgeImageResponse {
71 fn data_format() -> ResponseFormat {
72 ResponseFormat::Data
73 }
74}
75
76#[deprecated(note = "renamed to CreateBadgeImageRequestBuilder, will be removed in v1.0 (#271)")]
78pub type CreateBadgeImageBuilder = CreateBadgeImageRequestBuilder;
79
80#[cfg(test)]
81mod tests {
82 use super::*;
83
84 #[test]
85 fn test_builder_basic() {
86 let config = openlark_core::config::Config::builder()
87 .app_id("test_app")
88 .app_secret("test_secret")
89 .build();
90 let request = CreateBadgeImageRequestBuilder::new(config.clone()).image("test".to_string());
91 let _ = request;
92 }
93}