NTP-40086 | Using GenericFilter (#480)

* NTP-24894 | Text change in slack modal.

* NTP-24894 | Adding more constant teamTypes.

* NTP-24894 | Added functions to allow for teamType update.

* NTP-24894 | Added validation in addTeamRequest.

* NTP-24894 | Comment resolution and new functions (#477)

* NTP-24894 | Added filter on Reporting teams.

* NTP-24894 | Added new function for all teams fetch in team service.

* NTP-24894 | sending all teams in response for slack modal.

* NTP-24894 | Added tests for UpdateTeam flow.

* NTP-24894 | Fixing logic and using util.

* NTP-24894 | Using enum-map for teamType validation.

* NTP-24894 | Variable name change.

* NTP-24894 | Adding teamType to TeamDTOs when fetching using productid.

* NTP-24894 | Revisions in function for team population.

* NTP-24894 | Removed unneeded function.

* NTP-24894 | Removed unneeded interface of function

* NTP-24894 | Updated test scripts.

* NTP-24894 | Logic changes, modal text change.

* NTP-24894 | Using ID for first occurence, updated tests.

* NTP-40086 | Selective filtering based on Product.

* NTP-40086 | Updated tests for incident_orch.

* NTP-40086 | replaced with constants.

* NTP-24894 | Moved functions to teamService.

* NTP-40086 | added new function in repo for filtering during fetch.

* NTP-40086 | Removed unused function.

* NTP-40086 | added tests and removed interface of previously removed fuc.

* NTP-40086 | Added direct filtering function during data fetch from repo.

* NTP-40086 | Refactoring and adding more tests.

* NTP-24894 | Text changed in incident summary.

* NTP-40086 | Refactoring function.

* NTP-40086 | Editting team service for unused functions.

* NTP-40086 | Added new util function for generic intersection.

* NTP-40086 | Text changed at multiple places.

* NTP-40086 | Text change.

* NTP-40086 | text change.

* NTP-40086 | Added flags for reporter teams fetch.

* NTP-240086 | changes in test.

* NTP-40086 | Using GenericFilter instead of query based filtering.
This commit is contained in:
Amitesh Vijaykumar Magar
2025-02-21 19:26:20 +05:30
committed by GitHub
parent ab14dcffa5
commit 47193fe64e
5 changed files with 33 additions and 42 deletions

View File

@@ -147,6 +147,23 @@ func GenericIntersection[T any, K comparable](s1, s2 []T, keyExtractor func(T) K
return intersect
}
func GenericFilter[T any, K comparable](s1 []T, s2 []K, keyExtractor func(T) K) []T {
set := make(map[K]struct{})
var filteredList []T
for _, v := range s2 {
set[v] = struct{}{}
}
for _, v := range s1 {
if _, exists := set[keyExtractor(v)]; exists {
filteredList = append(filteredList, v)
}
}
return filteredList
}
// Contains checks if the given string exists on the slice of string and returns boolean
func Contains[S ~[]E, E comparable](s S, v E) bool {
return slices.Contains(s, v)

View File

@@ -133,7 +133,7 @@ func (i *incidentOrchestratorImpl) GetResponderTeamsForUpdate(
productIDs = append(productIDs, p.ID)
}
}
teamsOfProducts, err := i.getTeamsOfProducts(productIDs, true)
teamsOfProducts, err := i.getTeamsOfProducts(productIDs)
if err != nil {
return nil
}
@@ -184,20 +184,19 @@ func (i *incidentOrchestratorImpl) getReportingAndResponderTeams(
teamsOfUser = append(teamsOfUser, *defaultTeam)
}
teamsOfProducts, err := i.getTeamsOfProducts(productIDs, false)
teamsOfProducts, err := i.getTeamsOfProducts(productIDs)
if err != nil {
return nil, err
}
sort.Sort(sortListOfTeamDTOByName(teamsOfProducts.Teams))
sort.Sort(sortListOfTeamDTOByName(teamsOfUser))
teamsForReporting, err := i.getTeamsOfProducts(productIDs, true)
if err != nil {
return nil, err
}
var reportingTeams []team.TeamDTO
reportingTeams = append(reportingTeams, teamsForReporting.Teams...)
reportingTeams = append(reportingTeams, teamsOfProducts.Teams...)
reportingTeams = util.GenericFilter(reportingTeams,
[]string{string(util.CXTeam), string(util.BusinessFunctionTeam)},
func(t team.TeamDTO) string { return t.TeamType })
reportingTeams = util.RemoveDuplicates(reportingTeams, "ID").([]team.TeamDTO)
var defaultSelectedReportingTeam *team.TeamDTO = nil
commonTeams := util.GenericIntersection(reportingTeams, teamsOfUser, func(t team.TeamDTO) uint { return t.ID })
@@ -294,17 +293,8 @@ func (i *incidentOrchestratorImpl) getTeamByUserDTO(userDTO *user2.UserDTO) []te
return teams
}
func (i *incidentOrchestratorImpl) getTeamsOfProducts(productIDs []uint, fetchReporterTeams bool) (*response.ProductAndUserTeams, error) {
defaultProduct, err := i.productsService.GetDefaultProduct()
if err != nil {
return nil, err
}
if fetchReporterTeams {
productIDs = append(productIDs, defaultProduct.ProductID)
productIDs = util.RemoveDuplicate(productIDs)
}
productTeamDTO, err := i.productTeamService.GetProductTeamsByProductIDs(productIDs, defaultProduct)
func (i *incidentOrchestratorImpl) getTeamsOfProducts(productIDs []uint) (*response.ProductAndUserTeams, error) {
productTeamDTO, err := i.productTeamService.GetProductTeamsByProductIDs(productIDs)
if err != nil {
logger.Error(fmt.Sprintf("%s Error in fetching product teams", logTag), zap.Error(err))
}

View File

@@ -91,9 +91,7 @@ func (suite *IncidentOrchestratorSuite) TestIncidentOrchestratorImpl_GetReportin
suite.teamUserServiceMock.GetTeamsByUserIdMock.Expect(uint(1)).Return(tu, nil)
var p = product.ProductDTO{ProductID: 1, ProductName: "test"}
var teams = []team.TeamDTO{{ID: 1, Name: "test", TeamType: string(util.CXTeam)}}
defaultProduct := &product.ProductDTO{ProductID: 1, ProductName: "test"}
suite.productServiceMock.GetDefaultProductMock.Expect().Return(defaultProduct, nil)
suite.productTeamsServiceMock.GetProductTeamsByProductIDsMock.Expect([]uint{1}, defaultProduct).Return(
suite.productTeamsServiceMock.GetProductTeamsByProductIDsMock.Expect([]uint{1}).Return(
[]products_teams.ProductTeamsDTO{{Product: p, Teams: teams}}, nil,
)
_, err := suite.service.GetReportingAndResponderTeams("test", []uint{1})
@@ -105,9 +103,7 @@ func (suite *IncidentOrchestratorSuite) TestIncidentOrchestratorImpl_GetReportin
func (suite *IncidentOrchestratorSuite) TestIncidentOrchestratorImpl_GetReportingAndResponderTeamsWithInvalidEmailID() {
suite.userServiceMock.GetHoustonUserByEmailIdMock.Expect("invalid").Return(nil, errors.New("invalid email id"))
suite.teamServiceMock.GetTeamByNameMock.Expect("Others").Return(&team.TeamEntity{Model: gorm.Model{ID: 1}, Name: "Others", TeamType: string(util.BusinessFunctionTeam)}, nil)
defaultProduct := &product.ProductDTO{ProductID: 1, ProductName: "test"}
suite.productServiceMock.GetDefaultProductMock.Expect().Return(defaultProduct, nil)
suite.productTeamsServiceMock.GetProductTeamsByProductIDsMock.Expect([]uint{1}, defaultProduct).Return(nil, errors.New("invalid product id"))
suite.productTeamsServiceMock.GetProductTeamsByProductIDsMock.Expect([]uint{1}).Return(nil, errors.New("invalid product id"))
_, err := suite.service.GetReportingAndResponderTeams("invalid", []uint{1})
if err != nil {
suite.Fail("Get Reporting And Responder Teams With Invalid EmailID Failed", err)
@@ -118,10 +114,8 @@ func (suite *IncidentOrchestratorSuite) TestIncidentOrchestratorImpl_GetReportin
suite.userServiceMock.GetHoustonUserByEmailIdMock.Expect("test").Return(&user.UserDTO{ID: 1}, nil)
var tu []teamUser.TeamUserDTO
tu = append(tu, teamUser.TeamUserDTO{ID: 1, Team: team.TeamDTO{ID: 1, Name: "Others", TeamType: string(util.CXTeam)}})
defaultProduct := &product.ProductDTO{ProductID: 1, ProductName: "test"}
suite.productServiceMock.GetDefaultProductMock.Expect().Return(defaultProduct, nil)
suite.teamUserServiceMock.GetTeamsByUserIdMock.Expect(uint(1)).Return(tu, nil)
suite.productTeamsServiceMock.GetProductTeamsByProductIDsMock.Expect([]uint{1}, defaultProduct).Return(nil, errors.New("invalid product id"))
suite.productTeamsServiceMock.GetProductTeamsByProductIDsMock.Expect([]uint{1}).Return(nil, errors.New("invalid product id"))
suite.teamServiceMock.GetTeamByNameMock.Expect("Others").Return(&team.TeamEntity{Model: gorm.Model{ID: 1}, Name: "Others", TeamType: string(util.CXTeam)}, nil)
_, err := suite.service.GetReportingAndResponderTeams("test", []uint{1})
if err != nil {

View File

@@ -9,7 +9,7 @@ type ProductTeamsService interface {
AddProductTeamMapping(productID, teamID uint) (uint, error)
GetAllProductTeamsMapping() ([]products_teams.ProductTeamsMappingDTO, error)
GetProductTeamMappingByProductID(productID uint) (*products_teams.ProductTeamsMappingDTO, error)
GetProductTeamsByProductIDs(productIDs []uint, defaultProduct *product.ProductDTO) ([]products_teams.ProductTeamsDTO, error)
GetProductTeamsByProductIDs(productIDs []uint) ([]products_teams.ProductTeamsDTO, error)
GetProductsByTeamId(teamIDs ...uint) []product.ProductDTO
DeleteProductTeamMapping(productID, teamID uint) error
}

View File

@@ -4,7 +4,6 @@ import (
"errors"
"fmt"
"gorm.io/gorm"
"houston/common/util"
"houston/logger"
"houston/model/product"
"houston/model/products_teams"
@@ -52,25 +51,16 @@ func (service *productsTeamsServiceImpl) GetProductTeamMappingByProductID(
}
func (service *productsTeamsServiceImpl) GetProductTeamsByProductIDs(
productIDs []uint, defaultProduct *product.ProductDTO,
productIDs []uint,
) ([]products_teams.ProductTeamsDTO, error) {
var productTeamsDTOs []products_teams.ProductTeamsDTO
var filterTeams = true
for _, productID := range productIDs {
filterTeams = filterTeams && (productID != defaultProduct.ProductID)
}
for _, productID := range productIDs {
var productTeamsDTO *products_teams.ProductTeamsDTO
var err error
if filterTeams {
productTeamsDTO, err = service.repo.GetProductTeamsByProductIDAndTeamTypes(productID,
[]string{string(util.CXTeam), string(util.BusinessFunctionTeam)})
} else {
productTeamsDTO, err = service.repo.GetProductTeamsByProductID(productID)
}
productTeamsDTO, err = service.repo.GetProductTeamsByProductID(productID)
if err != nil {
logger.Error(
fmt.Sprintf(