@@ -35,14 +35,16 @@ class SubmissionList(QueryTemplate):
3535 def __init__ (self ):
3636 super ().__init__ ()
3737 # Instance specific variables
38- self .question_id : int = None
3938 self .show_terminal : bool = False
4039 self .submission_download : bool = False
4140
42- self .data = None
43- self .params = {'offset' : 0 , 'limit' : 20 , 'lastKey' : None , 'questionSlug' : None }
41+ self ._question_id : int = None
42+ self ._data = None
43+ self ._params = {'offset' : 0 , 'limit' : 20 , 'lastKey' : None , 'questionSlug' : None }
44+ self ._data_fetched : bool = False
4445
45- def fetch_data (self , question_id : int = None ) -> Dict :
46+ def fetch_data (self , question_id ) -> Dict :
47+ # TODO: make the parameters usable
4648 """ Fetches the submission list data for the problem.
4749
4850 Args:
@@ -55,16 +57,20 @@ def fetch_data(self, question_id: int = None) -> Dict:
5557 with Loader ('Fetching submission list...' , '' ):
5658 if question_id is not None and question_id != self .question_id :
5759 self .question_id = question_id
58- self .params ['questionSlug' ] = ProblemInfo .get_title_slug (self .question_id )
60+
61+ if self .data_fetched :
62+ return self .data
5963
6064 graphql_query = GraphQLQuery (self .query , self .params )
6165 response = self .leet_API .post_query (graphql_query )
62- return response ['data' ]
66+ self .data = QuestionSubmisstionList .from_dict (response ['data' ])
67+ self .data_fetched = True
68+ return self .data
6369 except Exception as e :
6470 console .print (f"{ e .__class__ .__name__ } : { e } " , style = ALERT )
6571 sys .exit (1 )
6672
67- def _execute (self , args ):
73+ def _execute (self , args ) -> None :
6874 """ Executes the query with the given arguments and displays the result.
6975
7076 Args:
@@ -88,7 +94,7 @@ def _execute(self, args):
8894 except Exception as e :
8995 console .print (f"{ e .__class__ .__name__ } : { e } " , style = ALERT )
9096
91- def show (self ):
97+ def show (self ) -> None :
9298 """ Displays the query result in a table. """
9399
94100 table = LeetTable ()
@@ -105,7 +111,7 @@ def show(self):
105111 console .print (table )
106112
107113 @staticmethod
108- def fetch_accepted (submissions ):
114+ def fetch_accepted (submissions ) -> QuestionSubmisstionList . Submission :
109115 """ Fetches the latest accepted submission from the list of submissions.
110116
111117 Args:
@@ -115,7 +121,7 @@ def fetch_accepted(submissions):
115121 Submission: The latest accepted submission. If no accepted submissions are found, None is returned."""
116122 return next ((x for x in submissions if x .statusDisplay == 'Accepted' ), None )
117123
118- def show_code (self ):
124+ def show_code (self ) -> None :
119125 """ Displays the code of the latest accepted submission.
120126
121127 If no accepted submissions are found, an exception is raised. """
@@ -140,7 +146,7 @@ def show_code(self):
140146 except Exception as e :
141147 console .print (f"{ e .__class__ .__name__ } : { e } " , style = ALERT )
142148
143- def download_submission (self ):
149+ def download_submission (self ) -> None :
144150 """ Downloads the code of the latest accepted submission.
145151
146152 If no accepted submissions are found, an exception is raised.
@@ -166,7 +172,7 @@ def download_submission(self):
166172 except Exception as e :
167173 console .print (f"{ e .__class__ .__name__ } : { e } " , style = ALERT )
168174
169- def __parse_args (self , args ):
175+ def __parse_args (self , args ) -> None :
170176 """ Parses the arguments passed to the query.
171177
172178 Args:
@@ -181,5 +187,46 @@ def __parse_args(self, args):
181187 if getattr (args , 'download' ):
182188 self .submission_download = True
183189
190+ @property
191+ def data (self ):
192+ return self ._data
193+
194+ @data .setter
195+ def data (self , data : Dict ):
196+ self ._data = data
197+
198+ @property
199+ def params (self ):
200+ return self ._params
201+
202+ @params .setter
203+ def params (self , params : Dict ):
204+ self ._params = params
205+ self .data_fetched = False
206+
207+ @property
208+ def data_fetched (self ):
209+ return self ._data_fetched
210+
211+ @data_fetched .setter
212+ def data_fetched (self , data_fetched : bool ):
213+ self ._data_fetched = data_fetched
184214
185-
215+ @property
216+ def question_id (self ):
217+ return self ._question_id
218+
219+ @question_id .setter
220+ def question_id (self , question_id : int ):
221+ self ._question_id = question_id
222+ self .data_fetched = False
223+ self .params ['questionSlug' ] = ProblemInfo .get_title_slug (self .question_id )
224+
225+
226+ if __name__ == '__main__' :
227+ submissions = SubmissionList ()
228+ submissions .fetch_data (6536534 )
229+ submissions .show ()
230+
231+ submissions .fetch_data (2 )
232+ submissions .show ()
0 commit comments