Skip to content

Commit bfa3732

Browse files
committed
Moved inline instead seperate function for inlcude relation
1 parent 55e5ce7 commit bfa3732

1 file changed

Lines changed: 9 additions & 15 deletions

File tree

rest-api/api/pkg/api/handler/vpcpeering.go

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,14 @@ func (gavph GetAllVpcPeeringHandler) Handle(c echo.Context) error {
611611
Offset: pageRequest.Offset,
612612
OrderBy: pageRequest.OrderBy,
613613
}
614-
includeRelations := vpcPeeringIncludeRelationsForTenantIDs(qIncludeRelations)
614+
includeRelations := qIncludeRelations
615+
if len(filterInput.VpcIDs) > 0 || len(filterInput.PeerTenantIDs) > 0 {
616+
for _, relation := range []string{cdbm.Vpc1RelationName, cdbm.Vpc2RelationName} {
617+
if !slices.Contains(includeRelations, relation) {
618+
includeRelations = append(includeRelations, relation)
619+
}
620+
}
621+
}
615622
vpcPeerings, total, err := vpcPeeringDAO.GetAll(ctx, nil, filterInput, vpcPeeringPageInput, includeRelations)
616623
if err != nil {
617624
logger.Error().Err(err).Msg("error retrieving VPC Peerings from DB")
@@ -710,8 +717,7 @@ func (gvph GetVpcPeeringHandler) Handle(c echo.Context) error {
710717

711718
// Get VPC Peering from DB by ID
712719
vpcPeeringDAO := cdbm.NewVpcPeeringDAO(gvph.dbSession)
713-
includeRelations := vpcPeeringIncludeRelationsForTenantIDs(qIncludeRelations)
714-
vpcPeering, err := vpcPeeringDAO.GetByID(ctx, nil, peeringUUID, includeRelations)
720+
vpcPeering, err := vpcPeeringDAO.GetByID(ctx, nil, peeringUUID, qIncludeRelations)
715721
if err != nil {
716722
if err == cdb.ErrDoesNotExist {
717723
return cutil.NewAPIErrorResponse(c, http.StatusNotFound, fmt.Sprintf("Could not find VPC Peering with ID: %s", peeringUUID.String()), nil)
@@ -999,15 +1005,3 @@ func (dvph DeleteVpcPeeringHandler) Handle(c echo.Context) error {
9991005

10001006
return c.NoContent(http.StatusNoContent)
10011007
}
1002-
1003-
// vpcPeeringIncludeRelationsForTenantIDs ensures Vpc1 and Vpc2 are loaded so
1004-
// vpc1TenantId and vpc2TenantId can be populated in the API response.
1005-
func vpcPeeringIncludeRelationsForTenantIDs(includeRelations []string) []string {
1006-
relations := slices.Clone(includeRelations)
1007-
for _, relation := range []string{cdbm.Vpc1RelationName, cdbm.Vpc2RelationName} {
1008-
if !slices.Contains(relations, relation) {
1009-
relations = append(relations, relation)
1010-
}
1011-
}
1012-
return relations
1013-
}

0 commit comments

Comments
 (0)