@@ -138,6 +138,23 @@ def get(self, key, **kwargs):
138138 return self ._K_V_map [key ]
139139
140140
141+ class CategoryCache (BaseCachedWorkManagementRepository ):
142+ def sync (self , project : ProjectEntity ):
143+ response = self .work_management .list_project_categories (project .id )
144+ if not response .ok :
145+ raise AppException (response .error )
146+ categories = response .data
147+ self ._K_V_map [project .id ] = {
148+ "category_name_id_map" : {
149+ category .value : category .id for category in categories
150+ },
151+ "category_id_name_map" : {
152+ category .id : category .value for category in categories
153+ },
154+ }
155+ self ._update_cache_timestamp (project .id )
156+
157+
141158class RoleCache (BaseCachedWorkManagementRepository ):
142159 def sync (self , project : ProjectEntity ):
143160 response = self .work_management .list_workflow_roles (
@@ -221,6 +238,7 @@ def get(self, key, **kwargs):
221238
222239class CachedWorkManagementRepository :
223240 def __init__ (self , ttl_seconds : int , work_management ):
241+ self ._category_cache = CategoryCache (ttl_seconds , work_management )
224242 self ._role_cache = RoleCache (ttl_seconds , work_management )
225243 self ._status_cache = StatusCache (ttl_seconds , work_management )
226244 self ._project_custom_field_cache = CustomFieldCache (
@@ -236,6 +254,12 @@ def __init__(self, ttl_seconds: int, work_management):
236254 CustomFieldEntityEnum .TEAM ,
237255 )
238256
257+ def get_category_id (self , project , category_name : str ) -> int :
258+ data = self ._category_cache .get (project .id , project = project )
259+ if category_name in data ["category_name_id_map" ]:
260+ return data ["category_name_id_map" ][category_name ]
261+ raise AppException ("Invalid category provided." )
262+
239263 def get_role_id (self , project , role_name : str ) -> int :
240264 role_data = self ._role_cache .get (project .id , project = project )
241265 if role_name in role_data ["role_name_id_map" ]:
0 commit comments