melvin_ob/http_handler/http_request/
objective_image_post.rs

1use super::objective_image::ObjectiveImageResponse;
2use super::request_common::{
3    HTTPRequestMethod, HTTPRequestType, MultipartBodyHTTPRequestType,
4};
5use std::{collections::HashMap, path::PathBuf};
6
7/// Request type for the /image endpoint -> POST.
8#[derive(Debug)]
9pub(crate) struct ObjectiveImageRequest {
10    /// The path where the image png file is stored.
11    image_path: PathBuf,
12    /// The objective id.
13    objective_id: usize,
14}
15
16impl MultipartBodyHTTPRequestType for ObjectiveImageRequest {
17    /// returns the path to the multipart image png file.
18    fn image_path(&self) -> &PathBuf { &self.image_path }
19}
20
21impl HTTPRequestType for ObjectiveImageRequest {
22    /// Type of the expected response.
23    type Response = ObjectiveImageResponse;
24    /// `str` object representing the specific endpoint.
25    fn endpoint(&self) -> &'static str { "/image" }
26    /// The corresponding HTTP Request Method.
27    fn request_method(&self) -> HTTPRequestMethod { HTTPRequestMethod::Post }
28    /// A `HashMap` containing the query param key value pairs
29    fn query_params(&self) -> HashMap<&str, String> {
30        let mut query = HashMap::new();
31        query.insert("objective_id", self.objective_id.to_string());
32        query
33    }
34}
35
36impl ObjectiveImageRequest {
37    /// Creates a new `ObjectiveImageRequest` from an id and a png file path.
38    pub fn new(objective_id: usize, image_path: PathBuf) -> Self {
39        Self { image_path, objective_id }
40    }
41}