/// Contains struct definitions regarding questions use crate::*; #[derive(Deserialize, Serialize, Clone, Debug)] pub struct QuestionDTO { pub id: u8, pub title: String, pub content: String, pub tags: Option>, } /// Question Data Transfer Object, a representation of the expected serialized JSON formated of questions regarding requests, responses, and our question json file impl QuestionDTO { pub fn to_entity(&self) -> (u8, Question) { ( self.id, Question { title: self.title.clone(), content: self.content.clone(), tags: self.tags.clone(), }, ) } } impl IntoResponse for &QuestionDTO { fn into_response(self) -> Response { (StatusCode::OK, Json(&self)).into_response() } } /// Question 'entity' used for in-memory interactions of questions by the store #[derive(Deserialize, Serialize, Clone, Debug)] pub struct Question { title: String, content: String, tags: Option>, } impl Question { pub fn _new(_id: u8, title: String, content: String, tags: Option>) -> Self { Question { title, content, tags, } } pub fn to_dto(&self, id: u8) -> QuestionDTO { QuestionDTO { id, title: self.title.clone(), content: self.content.clone(), tags: self.tags.clone(), } } } impl IntoResponse for &Question { fn into_response(self) -> Response { (StatusCode::OK, Json(&self)).into_response() } }