@@ -37,6 +37,8 @@ type GroupRepo interface {
3737 Update (ctx context.Context , orgID uuid.UUID , groupID uuid.UUID , opts * UpdateGroupOpts ) (* Group , error )
3838 // FindByOrgAndID finds a group by its organization ID and group ID.
3939 FindByOrgAndID (ctx context.Context , orgID uuid.UUID , groupID uuid.UUID ) (* Group , error )
40+ // FindByOrgAndName finds a group by its organization ID and group name.
41+ FindByOrgAndName (ctx context.Context , orgID uuid.UUID , name string ) (* Group , error )
4042 // FindGroupMembershipByGroupAndID finds a group membership by group ID and user ID.
4143 FindGroupMembershipByGroupAndID (ctx context.Context , groupID uuid.UUID , userID uuid.UUID ) (* GroupMembership , error )
4244 // SoftDelete soft-deletes a group by marking it as deleted.
@@ -831,6 +833,7 @@ func (uc *GroupUseCase) UpdateMemberMaintainerStatus(ctx context.Context, orgID
831833
832834// ValidateGroupIdentifier validates and resolves the group ID or name to a group ID.
833835// Returns an error if both are nil or if the resolved group does not exist.
836+ // TODO: change to return the group since this is very inefficient in some cases
834837func (uc * GroupUseCase ) ValidateGroupIdentifier (ctx context.Context , orgID uuid.UUID , groupID * uuid.UUID , groupName * string ) (uuid.UUID , error ) {
835838 if groupID == nil && groupName == nil {
836839 return uuid .Nil , NewErrValidationStr ("either group ID or group name must be provided" )
@@ -841,19 +844,10 @@ func (uc *GroupUseCase) ValidateGroupIdentifier(ctx context.Context, orgID uuid.
841844 }
842845
843846 // If group ID is not provided, try to find the group by name
844- groups , _ , err := uc .groupRepo .List (ctx , orgID , & ListGroupOpts { Name : * groupName }, pagination . NewDefaultOffsetPaginationOpts () )
847+ group , err := uc .groupRepo .FindByOrgAndName (ctx , orgID , * groupName )
845848 if err != nil {
846- return uuid .Nil , fmt .Errorf ("failed to list groups : %w" , err )
849+ return uuid .Nil , fmt .Errorf ("failed to find group : %w" , err )
847850 }
848851
849- if len (groups ) == 0 {
850- return uuid .Nil , NewErrNotFound ("group" )
851- }
852-
853- // If the group name is not unique, return an error
854- if len (groups ) > 1 {
855- return uuid .Nil , NewErrValidationStr ("group name is not unique" )
856- }
857-
858- return groups [0 ].ID , nil
852+ return group .ID , nil
859853}
0 commit comments