@@ -326,6 +326,53 @@ func (s *WorkspaceService) GetStatuses(workspaceID int) ([]models.Status, error)
326326 return statuses , nil
327327}
328328
329+ // GetItemTypes retrieves item types available for a workspace via its configuration set.
330+ // If the workspace has a config set with item types defined, only those are returned.
331+ // If no config set exists, all item types are returned.
332+ func (s * WorkspaceService ) GetItemTypes (workspaceID int ) ([]ItemTypeResult , error ) {
333+ rows , err := s .db .Query (`
334+ SELECT DISTINCT it.id, it.name, it.description, it.icon, it.color,
335+ it.hierarchy_level, it.sort_order, it.is_default
336+ FROM item_types it
337+ WHERE NOT EXISTS (
338+ SELECT 1 FROM workspace_configuration_sets wcs
339+ JOIN configuration_set_item_types csit ON wcs.configuration_set_id = csit.configuration_set_id
340+ WHERE wcs.workspace_id = ?
341+ )
342+ OR EXISTS (
343+ SELECT 1 FROM workspace_configuration_sets wcs
344+ JOIN configuration_set_item_types csit ON wcs.configuration_set_id = csit.configuration_set_id
345+ WHERE wcs.workspace_id = ? AND csit.item_type_id = it.id
346+ )
347+ ORDER BY it.hierarchy_level, it.sort_order, it.name
348+ ` , workspaceID , workspaceID )
349+ if err != nil {
350+ return nil , fmt .Errorf ("failed to get workspace item types: %w" , err )
351+ }
352+ defer rows .Close ()
353+
354+ var types []ItemTypeResult
355+ for rows .Next () {
356+ var t ItemTypeResult
357+ var description , icon , color sql.NullString
358+ err := rows .Scan (& t .ID , & t .Name , & description , & icon , & color ,
359+ & t .HierarchyLevel , & t .SortOrder , & t .IsDefault )
360+ if err != nil {
361+ continue
362+ }
363+ t .Description = description .String
364+ t .Icon = icon .String
365+ t .Color = color .String
366+ types = append (types , t )
367+ }
368+
369+ if types == nil {
370+ types = []ItemTypeResult {}
371+ }
372+
373+ return types , nil
374+ }
375+
329376// GetRepository returns the underlying workspace repository for advanced operations.
330377func (s * WorkspaceService ) GetRepository () * repository.WorkspaceRepository {
331378 return s .repo
0 commit comments