File tree 2 files changed +17
-0
lines changed
2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -118,6 +118,11 @@ impl KvStore {
118
118
Ok ( None )
119
119
}
120
120
121
+ /// Check if key exists in the cache
122
+ pub fn has_key ( & self , key : String ) -> bool {
123
+ self . index . contains_key ( & key)
124
+ }
125
+
121
126
/// Removes the given key.
122
127
pub fn remove ( & mut self , key : String ) -> Result < ( ) > {
123
128
// check if key exist in index and delete if from the log file
Original file line number Diff line number Diff line change @@ -85,6 +85,14 @@ impl<'a> ServiceProvider<'a> for Leetcode<'a> {
85
85
}
86
86
87
87
async fn list_problems ( & mut self , list : List ) -> Result < ( ) > {
88
+ if !self . is_user_logged_in ( ) {
89
+ print ! (
90
+ "{}" ,
91
+ Color :: Red ( "You need to login to list problems" ) . make( )
92
+ ) ;
93
+ return Ok ( ( ) ) ;
94
+ }
95
+
88
96
let problems_res = self . fetch_all_problems ( ) . await ?;
89
97
let mut probs: ProblemInfoSeq = vec ! [ ] ;
90
98
@@ -306,6 +314,10 @@ impl<'a> Leetcode<'a> {
306
314
} )
307
315
}
308
316
317
+ fn is_user_logged_in ( & self ) -> bool {
318
+ self . cache . has_key ( CacheKey :: Session . into ( ) )
319
+ }
320
+
309
321
fn cache_session ( & mut self , session : Session ) -> Result < ( ) > {
310
322
let session_str = serde_json:: to_string ( & session) ?;
311
323
self . cache . set ( CacheKey :: Session . into ( ) , session_str) ?;
You can’t perform that action at this time.
0 commit comments