INFRA-3362 : Filters based on reporting teams and products (#428)
* INFRA-3362 : Filters based on reporting teams and products * INFRA-3362 : Add grouping in query * INFRA-3362 : Fix formatting * INFRA-3362 : Fix formatting
This commit is contained in:
@@ -385,6 +385,8 @@ func (r *Repository) GetAllIncidents(teamsIds, severityIds, statusIds []uint) (*
|
||||
}
|
||||
|
||||
func (r *Repository) FetchAllIncidentsPaginated(
|
||||
productIds []uint,
|
||||
reportingTeamIds []uint,
|
||||
TeamsId []uint,
|
||||
SeverityIds []uint,
|
||||
StatusIds []uint,
|
||||
@@ -399,6 +401,9 @@ func (r *Repository) FetchAllIncidentsPaginated(
|
||||
if len(TeamsId) != 0 {
|
||||
query = query.Where("team_id IN ?", TeamsId)
|
||||
}
|
||||
if len(reportingTeamIds) != 0 {
|
||||
query = query.Where("reporting_team_id IN ?", reportingTeamIds)
|
||||
}
|
||||
if len(SeverityIds) != 0 {
|
||||
query = query.Where("severity_id IN ?", SeverityIds)
|
||||
}
|
||||
@@ -414,6 +419,12 @@ func (r *Repository) FetchAllIncidentsPaginated(
|
||||
if len(to) != 0 {
|
||||
query = query.Where("created_at <= ?", to)
|
||||
}
|
||||
if len(productIds) != 0 {
|
||||
query = query.
|
||||
Joins("JOIN incident_products ON incident_products.incident_entity_id = incident.id").
|
||||
Where("incident_products.product_entity_id IN ?", productIds).
|
||||
Group("incident.id")
|
||||
}
|
||||
|
||||
var totalElements int64
|
||||
result := query.Count(&totalElements)
|
||||
|
||||
@@ -17,6 +17,8 @@ type IIncidentRepository interface {
|
||||
GetAllOpenIncidents() (*[]IncidentEntity, int, error)
|
||||
GetAllIncidents(teamsIds, severityIds, statusIds []uint) (*[]IncidentEntity, int, error)
|
||||
FetchAllIncidentsPaginated(
|
||||
productIds []uint,
|
||||
reportingTeamIds []uint,
|
||||
TeamsId []uint,
|
||||
SeverityIds []uint,
|
||||
StatusIds []uint,
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"houston/appcontext"
|
||||
"houston/logger"
|
||||
"houston/model/incident"
|
||||
"houston/model/log"
|
||||
"houston/model/severity"
|
||||
"houston/model/team"
|
||||
"houston/service/products"
|
||||
response "houston/service/response"
|
||||
common "houston/service/response/common"
|
||||
"net/http"
|
||||
@@ -17,14 +19,16 @@ import (
|
||||
)
|
||||
|
||||
type filterService struct {
|
||||
gin *gin.Engine
|
||||
db *gorm.DB
|
||||
gin *gin.Engine
|
||||
db *gorm.DB
|
||||
productService products.ProductService
|
||||
}
|
||||
|
||||
func NewFilterService(gin *gin.Engine, db *gorm.DB) *filterService {
|
||||
return &filterService{
|
||||
gin: gin,
|
||||
db: db,
|
||||
gin: gin,
|
||||
db: db,
|
||||
productService: appcontext.GetProductsService(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,13 +50,20 @@ func (f *filterService) GetFilters(c *gin.Context) {
|
||||
c.JSON(http.StatusBadRequest, common.ErrorResponse(err, http.StatusBadRequest, nil))
|
||||
}
|
||||
|
||||
productFilterData, err := f.GetProductFilterData()
|
||||
if err != nil {
|
||||
logger.Error("error in fetching product data", zap.Error(err))
|
||||
c.JSON(http.StatusBadRequest, common.ErrorResponse(err, http.StatusBadRequest, nil))
|
||||
}
|
||||
|
||||
teamFilterData, err := f.GetTeamFilterData(teamRespository)
|
||||
if err != nil {
|
||||
logger.Error("error in fetching team data", zap.Error(err))
|
||||
c.JSON(http.StatusBadRequest, common.ErrorResponse(err, http.StatusBadRequest, nil))
|
||||
}
|
||||
|
||||
filterResponses = append(filterResponses, *incidentStatusFilterData, *severityFilterData, *teamFilterData)
|
||||
filterResponses = append(filterResponses, *incidentStatusFilterData, *severityFilterData, *productFilterData)
|
||||
filterResponses = append(filterResponses, teamFilterData...)
|
||||
logger.Info("Exiting GetFilter function", zap.String("correlationId", correlationId))
|
||||
c.JSON(http.StatusOK, common.SuccessResponse(filterResponses, http.StatusOK))
|
||||
}
|
||||
@@ -112,7 +123,7 @@ func (f *filterService) GetSeverityFilterData(severityRepository *severity.Repos
|
||||
return &filterResponse, nil
|
||||
}
|
||||
|
||||
func (f *filterService) GetTeamFilterData(teamRepository *team.Repository) (*response.FilterResponse, error) {
|
||||
func (f *filterService) GetTeamFilterData(teamRepository *team.Repository) ([]response.FilterResponse, error) {
|
||||
priorityTeams := []int{1, 12, 16, 20, 24, 25, 28}
|
||||
var priorityTeamOptions []response.Options
|
||||
var otherTeamOptions []response.Options
|
||||
@@ -134,14 +145,44 @@ func (f *filterService) GetTeamFilterData(teamRepository *team.Repository) (*res
|
||||
})
|
||||
}
|
||||
}
|
||||
filterResponse := response.FilterResponse{
|
||||
FilterData: append(priorityTeamOptions, otherTeamOptions...),
|
||||
FilterKey: "team_ids",
|
||||
FilterName: "Incident Team",
|
||||
SelectionConfig: "MULTI_SELECT",
|
||||
|
||||
return []response.FilterResponse{
|
||||
{
|
||||
FilterData: append(priorityTeamOptions, otherTeamOptions...),
|
||||
FilterKey: "reporter_team_ids",
|
||||
FilterName: "Reporter Team",
|
||||
SelectionConfig: "MULTI_SELECT",
|
||||
},
|
||||
{
|
||||
FilterData: append(priorityTeamOptions, otherTeamOptions...),
|
||||
FilterKey: "team_ids",
|
||||
FilterName: "Responder Team",
|
||||
SelectionConfig: "MULTI_SELECT",
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (f *filterService) GetProductFilterData() (*response.FilterResponse, error) {
|
||||
allProducts, err := f.productService.GetAllProducts()
|
||||
if err != nil {
|
||||
logger.Error("error in fetching products", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
var productFilterData []response.Options
|
||||
|
||||
for _, productData := range allProducts {
|
||||
productFilterData = append(productFilterData, response.Options{
|
||||
Label: productData.ProductName,
|
||||
Value: strconv.Itoa(int(productData.ProductID)),
|
||||
})
|
||||
}
|
||||
|
||||
return &filterResponse, nil
|
||||
return &response.FilterResponse{
|
||||
FilterData: productFilterData,
|
||||
FilterKey: "product_ids",
|
||||
FilterName: "Product",
|
||||
SelectionConfig: "MULTI_SELECT",
|
||||
}, nil
|
||||
}
|
||||
|
||||
func contains(inputSlice []int, searchElement int) bool {
|
||||
|
||||
@@ -83,6 +83,8 @@ func NewIncidentService(
|
||||
|
||||
func (i *incidentService) GetIncidents(c *gin.Context) {
|
||||
IncidentId := c.Param("id")
|
||||
productIds := c.Query("product_ids")
|
||||
reporterTeamIds := c.Query("reporter_team_ids")
|
||||
TeamIds := c.Query("team_ids")
|
||||
SeverityIds := c.Query("severity_ids")
|
||||
Status := c.Query("statuses")
|
||||
@@ -116,14 +118,16 @@ func (i *incidentService) GetIncidents(c *gin.Context) {
|
||||
}
|
||||
|
||||
incidents, totalElements, err := i.GetAllIncidents(request.IncidentFilters{
|
||||
TeamIds: TeamIds,
|
||||
SeverityIds: SeverityIds,
|
||||
StatusIds: Status,
|
||||
PageSize: pageSize,
|
||||
PageNumber: pageNumber,
|
||||
IncidentName: IncidentName,
|
||||
From: From,
|
||||
To: To,
|
||||
ProductIds: productIds,
|
||||
ReporterTeamIds: reporterTeamIds,
|
||||
TeamIds: TeamIds,
|
||||
SeverityIds: SeverityIds,
|
||||
StatusIds: Status,
|
||||
PageSize: pageSize,
|
||||
PageNumber: pageNumber,
|
||||
IncidentName: IncidentName,
|
||||
From: From,
|
||||
To: To,
|
||||
}, i.incidentRepository)
|
||||
if err != nil {
|
||||
logger.Info("error in fetching incidents", zap.Error(err))
|
||||
@@ -252,9 +256,17 @@ func (i *incidentService) GetUserIdAndIdentityMappingOfAllIncidents(incidents []
|
||||
}
|
||||
|
||||
func (i *incidentService) GetAllIncidents(incidentFilters request.IncidentFilters, incidentRepository *incident.Repository) ([]incident.IncidentEntity, int, error) {
|
||||
var productIds []uint
|
||||
var reporterTeamIds []uint
|
||||
var TeamIds []uint
|
||||
var SeverityIds []uint
|
||||
var StatusIds []uint
|
||||
if incidentFilters.ProductIds != "" {
|
||||
productIds = i.SplitStringAndGetUintArray(incidentFilters.ProductIds)
|
||||
}
|
||||
if incidentFilters.ReporterTeamIds != "" {
|
||||
reporterTeamIds = i.SplitStringAndGetUintArray(incidentFilters.ReporterTeamIds)
|
||||
}
|
||||
if incidentFilters.TeamIds != "" {
|
||||
TeamIds = i.SplitStringAndGetUintArray(incidentFilters.TeamIds)
|
||||
}
|
||||
@@ -265,7 +277,7 @@ func (i *incidentService) GetAllIncidents(incidentFilters request.IncidentFilter
|
||||
StatusIds = i.SplitStringAndGetUintArray(incidentFilters.StatusIds)
|
||||
}
|
||||
return incidentRepository.FetchAllIncidentsPaginated(
|
||||
TeamIds, SeverityIds, StatusIds, incidentFilters.PageNumber, incidentFilters.PageSize, incidentFilters.IncidentName, incidentFilters.From, incidentFilters.To)
|
||||
productIds, reporterTeamIds, TeamIds, SeverityIds, StatusIds, incidentFilters.PageNumber, incidentFilters.PageSize, incidentFilters.IncidentName, incidentFilters.From, incidentFilters.To)
|
||||
}
|
||||
|
||||
func (i *incidentService) SplitStringAndGetUintArray(str string) []uint {
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
package service
|
||||
|
||||
type IncidentFilters struct {
|
||||
TeamIds string
|
||||
SeverityIds string
|
||||
StatusIds string
|
||||
PageSize int64
|
||||
PageNumber int64
|
||||
IncidentName string
|
||||
From string
|
||||
To string
|
||||
ProductIds string
|
||||
ReporterTeamIds string
|
||||
TeamIds string
|
||||
SeverityIds string
|
||||
StatusIds string
|
||||
PageSize int64
|
||||
PageNumber int64
|
||||
IncidentName string
|
||||
From string
|
||||
To string
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user