1
1
use crate :: error:: MyError ;
2
- use crate :: response:: { FeedbackData , FeedbackListResponse , FeedbackResponse , SingleFeedbackResponse } ;
2
+ use crate :: response:: {
3
+ FeedbackData , FeedbackListResponse , FeedbackResponse , SingleFeedbackResponse ,
4
+ } ;
3
5
use crate :: {
4
- error:: MyError :: * , model:: FeedbackModel , schema:: CreateFeedbackSchema , schema:: UpdateFeedbackSchema ,
6
+ error:: MyError :: * , model:: FeedbackModel , schema:: CreateFeedbackSchema ,
7
+ schema:: UpdateFeedbackSchema ,
5
8
} ;
6
9
use chrono:: prelude:: * ;
7
10
use futures:: StreamExt ;
@@ -46,7 +49,9 @@ impl DB {
46
49
pub async fn fetch_feedbacks ( & self , limit : i64 , page : i64 ) -> Result < FeedbackListResponse > {
47
50
let mut cursor = self
48
51
. 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 ( ) )
50
55
. await
51
56
. map_err ( MongoQueryError ) ?;
52
57
@@ -62,14 +67,17 @@ impl DB {
62
67
} )
63
68
}
64
69
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" ) ) ;
67
75
68
76
let document = self . create_feedback_document ( body, status) ?;
69
77
70
78
let options = IndexOptions :: builder ( ) . unique ( true ) . build ( ) ;
71
79
let index = IndexModel :: builder ( )
72
- . keys ( doc ! { "title " : 1 } )
80
+ . keys ( doc ! { "feedback " : 1 } )
73
81
. options ( options)
74
82
. build ( ) ;
75
83
@@ -134,7 +142,11 @@ impl DB {
134
142
}
135
143
}
136
144
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 > {
138
150
let oid = ObjectId :: from_str ( id) . map_err ( |_| InvalidIDError ( id. to_owned ( ) ) ) ?;
139
151
140
152
let update = doc ! {
@@ -192,7 +204,7 @@ impl DB {
192
204
fn create_feedback_document (
193
205
& self ,
194
206
body : & CreateFeedbackSchema ,
195
- status : bool ,
207
+ status : String ,
196
208
) -> Result < bson:: Document > {
197
209
let serialized_data = bson:: to_bson ( body) . map_err ( MongoSerializeBsonError ) ?;
198
210
let document = serialized_data. as_document ( ) . unwrap ( ) ;
0 commit comments