Skip to content

Commit a78557f

Browse files
committed
updated
1 parent d18c1f6 commit a78557f

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

src/db.rs

+20-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
use crate::error::MyError;
2-
use crate::response::{FeedbackData, FeedbackListResponse, FeedbackResponse, SingleFeedbackResponse};
2+
use crate::response::{
3+
FeedbackData, FeedbackListResponse, FeedbackResponse, SingleFeedbackResponse,
4+
};
35
use crate::{
4-
error::MyError::*, model::FeedbackModel, schema::CreateFeedbackSchema, schema::UpdateFeedbackSchema,
6+
error::MyError::*, model::FeedbackModel, schema::CreateFeedbackSchema,
7+
schema::UpdateFeedbackSchema,
58
};
69
use chrono::prelude::*;
710
use futures::StreamExt;
@@ -46,7 +49,9 @@ impl DB {
4649
pub async fn fetch_feedbacks(&self, limit: i64, page: i64) -> Result<FeedbackListResponse> {
4750
let mut cursor = self
4851
.feedback_collection
49-
.find(doc! {}).limit(limit).skip(u64::try_from((page - 1) * limit).unwrap())
52+
.find(doc! {})
53+
.limit(limit)
54+
.skip(u64::try_from((page - 1) * limit).unwrap())
5055
.await
5156
.map_err(MongoQueryError)?;
5257

@@ -62,14 +67,17 @@ impl DB {
6267
})
6368
}
6469

65-
pub async fn create_feedback(&self, body: &CreateFeedbackSchema) -> Result<SingleFeedbackResponse> {
66-
let status = body.status.to_owned().unwrap_or(false);
70+
pub async fn create_feedback(
71+
&self,
72+
body: &CreateFeedbackSchema,
73+
) -> Result<SingleFeedbackResponse> {
74+
let status = body.status.to_owned().unwrap_or(String::from("pending"));
6775

6876
let document = self.create_feedback_document(body, status)?;
6977

7078
let options = IndexOptions::builder().unique(true).build();
7179
let index = IndexModel::builder()
72-
.keys(doc! {"title": 1})
80+
.keys(doc! {"feedback": 1})
7381
.options(options)
7482
.build();
7583

@@ -134,7 +142,11 @@ impl DB {
134142
}
135143
}
136144

137-
pub async fn edit_feedback(&self, id: &str, body: &UpdateFeedbackSchema) -> Result<SingleFeedbackResponse> {
145+
pub async fn edit_feedback(
146+
&self,
147+
id: &str,
148+
body: &UpdateFeedbackSchema,
149+
) -> Result<SingleFeedbackResponse> {
138150
let oid = ObjectId::from_str(id).map_err(|_| InvalidIDError(id.to_owned()))?;
139151

140152
let update = doc! {
@@ -192,7 +204,7 @@ impl DB {
192204
fn create_feedback_document(
193205
&self,
194206
body: &CreateFeedbackSchema,
195-
status: bool,
207+
status: String,
196208
) -> Result<bson::Document> {
197209
let serialized_data = bson::to_bson(body).map_err(MongoSerializeBsonError)?;
198210
let document = serialized_data.as_document().unwrap();

src/schema.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ pub struct FilterOptions {
66
pub limit: Option<usize>,
77
}
88

9-
#[derive(Deserialize, Debug)]
10-
pub struct ParamOptions {
11-
pub id: String,
12-
}
9+
// #[derive(Deserialize, Debug)]
10+
// pub struct ParamOptions {
11+
// pub id: String,
12+
// }
1313

1414
#[derive(Serialize, Deserialize, Debug)]
1515
pub struct CreateFeedbackSchema {
@@ -18,7 +18,7 @@ pub struct CreateFeedbackSchema {
1818
pub feedback: String,
1919
pub rating: i32,
2020
#[serde(skip_serializing_if = "Option::is_none")]
21-
pub status: Option<bool>,
21+
pub status: Option<String>,
2222
}
2323

2424
#[derive(Serialize, Deserialize, Debug)]
@@ -27,5 +27,6 @@ pub struct UpdateFeedbackSchema {
2727
pub email: Option<String>,
2828
pub feedback: Option<String>,
2929
pub rating: Option<i32>,
30+
#[serde(skip_serializing_if = "Option::is_none")]
3031
pub status: Option<String>,
31-
}
32+
}

0 commit comments

Comments
 (0)