melvin_ob/http_handler/http_request/
daily_map_post.rs1use super::daily_map::DailyMapResponse;
2use super::request_common::{
3 HTTPRequestMethod, HTTPRequestType, MultipartBodyHTTPRequestType,
4};
5use std::{io, path::Path};
6use std::path::PathBuf;
7
8#[derive(Debug)]
10pub(crate) struct DailyMapRequest {
11 image_path: PathBuf,
13}
14
15impl MultipartBodyHTTPRequestType for DailyMapRequest {
16 fn image_path(&self) -> &PathBuf { &self.image_path }
18}
19
20impl HTTPRequestType for DailyMapRequest {
21 type Response = DailyMapResponse;
23 fn endpoint(&self) -> &'static str { "/dailyMap" }
25 fn request_method(&self) -> HTTPRequestMethod { HTTPRequestMethod::Post }
27}
28
29impl DailyMapRequest {
30 pub(crate) fn new<P: AsRef<Path>>(image_path: P) -> Result<Self, io::Error> {
32 let path = image_path.as_ref();
33 if !path.exists() {
34 return Err(io::Error::new(
35 io::ErrorKind::NotFound,
36 "File path does not exist",
37 ));
38 }
39 if !path.is_file() {
40 return Err(io::Error::new(
41 io::ErrorKind::InvalidInput,
42 "Path is not a valid file",
43 ));
44 }
45 Ok(Self { image_path: path.to_path_buf() })
46 }
47}