@@ -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.
@@ -833,6 +835,7 @@ func (uc *GroupUseCase) UpdateMemberMaintainerStatus(ctx context.Context, orgID
833835
834836// ValidateGroupIdentifier validates and resolves the group ID or name to a group ID.
835837// Returns an error if both are nil or if the resolved group does not exist.
838+ // TODO: change to return the group since this is very inefficient in some cases
836839func (uc * GroupUseCase ) ValidateGroupIdentifier (ctx context.Context , orgID uuid.UUID , groupID * uuid.UUID , groupName * string ) (uuid.UUID , error ) {
837840 if groupID == nil && groupName == nil {
838841 return uuid .Nil , NewErrValidationStr ("either group ID or group name must be provided" )
@@ -843,19 +846,10 @@ func (uc *GroupUseCase) ValidateGroupIdentifier(ctx context.Context, orgID uuid.
843846 }
844847
845848 // If group ID is not provided, try to find the group by name
846- groups , _ , err := uc .groupRepo .List (ctx , orgID , & ListGroupOpts { Name : * groupName }, pagination . NewDefaultOffsetPaginationOpts () )
849+ group , err := uc .groupRepo .FindByOrgAndName (ctx , orgID , * groupName )
847850 if err != nil {
848- return uuid .Nil , fmt .Errorf ("failed to list groups : %w" , err )
851+ return uuid .Nil , fmt .Errorf ("failed to find group : %w" , err )
849852 }
850853
851- if len (groups ) == 0 {
852- return uuid .Nil , NewErrNotFound ("group" )
853- }
854-
855- // If the group name is not unique, return an error
856- if len (groups ) > 1 {
857- return uuid .Nil , NewErrValidationStr ("group name is not unique" )
858- }
859-
860- return groups [0 ].ID , nil
854+ return group .ID , nil
861855}
0 commit comments