Skip to content

Commit d1f81fe

Browse files
authored
Support uploading files in the support tickets endpoints (#989)
1 parent 644a685 commit d1f81fe

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

wp_api/src/wp_com/endpoint/support_tickets_endpoint.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ use wp_derive_request_builder::WpDerivedRequest;
1212

1313
#[derive(WpDerivedRequest)]
1414
enum SupportTicketsRequest {
15-
#[post(url = "/mobile-support/conversations", params = &CreateSupportTicketParams, output = SupportConversation)]
15+
#[post(url = "/mobile-support/conversations", params = &CreateSupportTicketParams, output = SupportConversation, multipart = true)]
1616
CreateSupportTicket,
1717
#[get(url = "/mobile-support/conversations", output = Vec<SupportConversationSummary>)]
1818
GetSupportConversationList,
1919
#[get(url = "/mobile-support/conversations/<conversation_id>", output = SupportConversation)]
2020
GetSupportConversation,
21-
#[post(url = "/mobile-support/conversations/<conversation_id>", params = &AddMessageToSupportConversationParams, output = SupportConversation)]
21+
#[post(url = "/mobile-support/conversations/<conversation_id>", params = &AddMessageToSupportConversationParams, output = SupportConversation, multipart = true)]
2222
AddMessageToSupportConversation,
2323
}
2424

wp_api/src/wp_com/support_tickets.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ impl RequiresMultipartForm for CreateSupportTicketParams {
3030
.enumerate()
3131
.map(|(i, file_path)| {
3232
(
33-
// TODO: The backend is not ready yet. This name may need to be changed.
3433
format!("attachment_{i}"),
3534
MultipartFormFile {
3635
file_path: file_path.clone(),
@@ -172,10 +171,30 @@ pub struct SupportAgentIdentity {
172171
#[derive(Debug, PartialEq, Eq, Serialize, uniffi::Record)]
173172
pub struct AddMessageToSupportConversationParams {
174173
pub message: String,
174+
#[serde(skip)]
175175
#[uniffi(default = [])]
176176
pub attachments: Vec<String>,
177177
}
178178

179+
impl RequiresMultipartForm for AddMessageToSupportConversationParams {
180+
fn multipart_form_files(&self) -> HashMap<String, MultipartFormFile> {
181+
self.attachments
182+
.iter()
183+
.enumerate()
184+
.map(|(i, file_path)| {
185+
(
186+
format!("attachment_{i}"),
187+
MultipartFormFile {
188+
file_path: file_path.clone(),
189+
mime_type: None,
190+
file_name: None,
191+
},
192+
)
193+
})
194+
.collect()
195+
}
196+
}
197+
179198
impl_as_query_value_for_new_type!(ConversationId);
180199
uniffi::custom_newtype!(ConversationId, u64);
181200
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]

0 commit comments

Comments
 (0)