Files
houston-be/model/incident/entity.go
Vijay Joshi 804be01c2f INFRA-3467 : Private Houston Incidents (#445)
* INFRA-3467 : Private Houston Incidents

* INFRA-3627 : Minor self review

* INFRA-3627 : PR Review changes

INFRA-3627 : Minor changes

INFRA-3627 : UT fix

INFRA-3637 : Message changes

INFRA-3627 : Minor changes

INFRA-3627 : Constant fix

INFRA-3627 : Do not post SLA breach in public channels for private incidents
2024-08-08 19:20:04 +05:30

159 lines
5.1 KiB
Go

package incident
import (
"houston/model/product"
"houston/model/severity"
"houston/model/team"
"time"
"github.com/lib/pq"
"gorm.io/gorm"
)
type IncidentStatus string
const (
Investigating IncidentStatus = "Investigating"
Identified = "Identified"
Monitoring = "Monitoring"
Resolved = "Resolved"
Duplicated = "Duplicated"
)
const (
Responder IncidentRole = "Responder"
)
type IncidentRole string
const (
InvestigatingId uint = iota + 1 // iota starts assigning from 0, so incrementing to start at 1
IdentifiedId
MonitoringId
ResolvedId
DuplicateId
)
const (
Sev0Id uint = iota + 1 // iota starts assigning from 0, so incrementing to start at 1
Sev1Id
Sev2Id
Sev3Id
Sev4Id
)
// IncidentEntity all the incident created will go in this table
type IncidentEntity struct {
gorm.Model
Title string `gorm:"column:title"`
Description string `gorm:"column:description"`
Status uint `gorm:"column:status"`
SeverityId uint `gorm:"column:severity_id"`
IncidentName string `gorm:"column:incident_name"`
SlackChannel string `gorm:"column:slack_channel"`
DetectionTime *time.Time `gorm:"column:detection_time"`
StartTime time.Time `gorm:"column:start_time"`
EndTime *time.Time `gorm:"column:end_time"`
TeamId uint `gorm:"column:team_id"`
JiraLinks pq.StringArray `gorm:"column:jira_links;type:text[]"`
ConfluenceId *string `gorm:"column:confluence_id"`
SeverityTat time.Time `gorm:"column:severity_tat"`
RemindMeAt *time.Time `gorm:"column:remind_me_at"`
EnableReminder bool `gorm:"column:enable_reminder"`
CreatedBy string `gorm:"column:created_by"`
UpdatedBy string `gorm:"column:updated_by"`
MetaData JSON `gorm:"column:meta_data;type:jsonb"`
RCA string `gorm:"column:rca_text"`
ConferenceId string `gorm:"column:conference_id"`
ConferenceLink string `gorm:"column:conference_link"`
ReportingTeamId *uint `gorm:"column:reporting_team_id"`
Products []product.ProductEntity `gorm:"many2many:incident_products;"`
Team team.TeamEntity `gorm:"foreignKey:TeamId"`
Severity severity.SeverityEntity `gorm:"foreignKey:SeverityId"`
ReportingTeam team.TeamEntity `gorm:"foreignKey:ReportingTeamId"`
IsPrivate bool `gorm:"column:is_private"`
}
func (IncidentEntity) TableName() string {
return "incident"
}
func (i IncidentEntity) ToDTO() IncidentDTO {
var products []product.ProductDTO
for _, p := range i.Products {
products = append(products, *p.ToDTO())
}
return IncidentDTO{
ID: i.ID,
Title: i.Title,
Description: i.Description,
Status: i.Status,
SeverityId: i.SeverityId,
IncidentName: i.IncidentName,
SlackChannel: i.SlackChannel,
TeamId: i.TeamId,
JiraLinks: i.JiraLinks,
ConfluenceId: i.ConfluenceId,
CreatedAt: i.CreatedAt,
CreatedBy: i.CreatedBy,
RCA: i.RCA,
ConferenceId: i.ConferenceId,
ReportingTeamId: i.ReportingTeamId,
Products: products,
SeverityTat: i.SeverityTat,
Team: *(i.Team).ToDTO(),
Severity: i.Severity.ToDTO(),
ReportingTeam: *(i.ReportingTeam).ToDTO(),
IsPrivate: i.IsPrivate,
}
}
// IncidentRoleEntity this table will contain the role of the people assigned to the incident, mapping between incident
// and incident role entity will be one to many
type IncidentRoleEntity struct {
gorm.Model
IncidentId int `gorm:"column:incident_id"`
Role IncidentRole `gorm:"column:role"`
AssignedTo string `gorm:"column:assigned_to"`
AssignedBy string `gorm:"column:assigned_by"`
}
func (IncidentRoleEntity) TableName() string {
return "incident_role"
}
func (i IncidentRoleEntity) ToDTO() IncidentRoleDTO {
return IncidentRoleDTO{
IncidentId: i.IncidentId,
Role: i.Role,
AssignedTo: i.AssignedTo,
AssignedBy: i.AssignedBy,
}
}
// IncidentChannelEntity contains the channels where the incident is being tracked
type IncidentChannelEntity struct {
gorm.Model
IncidentId uint `gorm:"column:incident_id"`
SlackChannel string `gorm:"column:slack_channel"`
MessageTimeStamp string `gorm:"column:message_timestamp"`
IsArchived bool `gorm:"column:is_archived"`
}
func (IncidentChannelEntity) TableName() string {
return "incident_channel"
}
type IncidentTagEntity struct {
gorm.Model
IncidentId uint `gorm:"column:incident_id"`
TagId uint `gorm:"column:tag_id"`
TagValueIds pq.Int32Array `gorm:"column:tag_value_ids;type:integer[]"`
FreeTextValue *string `gorm:"column:free_text_value"`
}
func (IncidentTagEntity) TableName() string {
return "incident_tag"
}