TP-12345|adding slack topic while creating channel (#51)
* TP-12345|adding slack topic while creating channel * TP-12345|create incident request api update
This commit is contained in:
committed by
GitHub Enterprise
parent
15962a7379
commit
95c1c72771
@@ -10,14 +10,12 @@ import (
|
||||
)
|
||||
|
||||
type teamHandler struct {
|
||||
gin *gin.Engine
|
||||
logger *zap.Logger
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
func NewTeamHandler(gin *gin.Engine, logger *zap.Logger, db *gorm.DB) *teamHandler {
|
||||
return &teamHandler{
|
||||
gin: gin,
|
||||
logger: logger,
|
||||
db: db,
|
||||
}
|
||||
|
||||
@@ -64,6 +64,10 @@ func (cip *CreateIncidentAction) CreateIncidentModalCommandProcessing(callback s
|
||||
return
|
||||
}
|
||||
|
||||
topic := fmt.Sprintf("%s-%s(%s) Incident-%d | %s", teamEntity.Name, severityEntity.Name, severityEntity.Description, incidentEntity.ID, incidentEntity.Title)
|
||||
|
||||
cip.slackbotClient.SetChannelTopic(*channelID, topic)
|
||||
|
||||
go func() {
|
||||
// Post incident summary to Blaze Group channel and incident channel
|
||||
_, err := cip.postIncidentSummary(callback.View.PrivateMetadata, *channelID, incidentEntity, teamEntity,
|
||||
|
||||
@@ -61,6 +61,21 @@ func (s *Repository) FindSeverityById(severityId uint) (*SeverityEntity, error)
|
||||
return &severityEntity, nil
|
||||
}
|
||||
|
||||
func (s *Repository) FindSeverityByName(severityName string) (*SeverityEntity, error) {
|
||||
var severityEntity SeverityEntity
|
||||
|
||||
result := s.gormClient.Find(&severityEntity, "name = ?", severityName)
|
||||
if result.Error != nil {
|
||||
return nil, result.Error
|
||||
}
|
||||
|
||||
if result.RowsAffected == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return &severityEntity, nil
|
||||
}
|
||||
|
||||
func (s *Repository) Update(severityEntity *SeverityEntity) error {
|
||||
result := s.gormClient.Updates(severityEntity)
|
||||
if result.Error != nil {
|
||||
|
||||
@@ -42,6 +42,19 @@ func (r *Repository) FindTeamById(teamId uint) (*TeamEntity, error) {
|
||||
return &teamEntity, nil
|
||||
}
|
||||
|
||||
func (r *Repository) FindTeamByTeamName(teamName string) (*TeamEntity, error) {
|
||||
var teamEntity TeamEntity
|
||||
|
||||
result := r.gormClient.Find(&teamEntity, "name = ?", teamName)
|
||||
if result.Error != nil {
|
||||
return nil, result.Error
|
||||
} else if result.RowsAffected == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return &teamEntity, nil
|
||||
}
|
||||
|
||||
func (r *Repository) UpdateTeam(teamEntity *TeamEntity) error {
|
||||
result := r.gormClient.Updates(teamEntity)
|
||||
if result.Error != nil {
|
||||
|
||||
@@ -37,6 +37,17 @@ func (c *Client) CreateChannel(channelName string) (string, error) {
|
||||
return channel.ID, nil
|
||||
}
|
||||
|
||||
func (c *Client) SetChannelTopic(channelId, topic string) (string, error) {
|
||||
channel, err := c.socketModeClient.SetTopicOfConversation(channelId, topic)
|
||||
if err != nil {
|
||||
c.logger.Error("set topic on slack channel failed", zap.String("channel_id", channelId), zap.Error(err))
|
||||
return "", err
|
||||
}
|
||||
|
||||
c.logger.Info("set topic on slack channel successful", zap.String("channel_id", channelId), zap.String("channel_id", channel.ID))
|
||||
return "", nil
|
||||
}
|
||||
|
||||
func (c *Client) InviteUsersToConversation(channelId string, userId ...string) {
|
||||
_, err := c.socketModeClient.InviteUsersToConversation(channelId, userId...)
|
||||
if err != nil {
|
||||
|
||||
@@ -286,7 +286,10 @@ func (i *incidentService) CreateIncident(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
var incidentRequest = buildCreateIncidentRequest(createIncRequest)
|
||||
incidentRequest, err := i.buildCreateIncidentRequest(createIncRequest)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, err)
|
||||
}
|
||||
|
||||
// Save the incident to the database
|
||||
incidentEntity, err := i.incidentRepository.CreateIncident(incidentRequest)
|
||||
@@ -434,18 +437,28 @@ func (i *incidentService) createSlackChannel(incidentEntity *incident.IncidentEn
|
||||
return &channelID, nil
|
||||
}
|
||||
|
||||
func buildCreateIncidentRequest(createIncRequest request.CreateIncidentRequest) *incident.CreateIncidentRequest {
|
||||
func (i *incidentService) buildCreateIncidentRequest(createIncRequest request.CreateIncidentRequest) (*incident.CreateIncidentRequest, error) {
|
||||
var createIncidentRequest incident.CreateIncidentRequest
|
||||
teamEntity, err := i.teamRepository.FindTeamByTeamName(createIncRequest.TeamName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
severityEntity, err := i.severityRepository.FindSeverityByName(createIncRequest.SeverityName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
createIncidentRequest.Title = createIncRequest.Title
|
||||
createIncidentRequest.Description = createIncRequest.Description
|
||||
createIncidentRequest.Severity = createIncRequest.SeverityId
|
||||
createIncidentRequest.TeamId = createIncRequest.TeamId
|
||||
createIncidentRequest.Severity = fmt.Sprintf("%d", severityEntity.ID)
|
||||
createIncidentRequest.TeamId = fmt.Sprintf("%d", teamEntity.ID)
|
||||
createIncidentRequest.Status = incident.Investigating
|
||||
createIncidentRequest.CreatedBy = createIncRequest.CreatedBy
|
||||
createIncidentRequest.UpdatedBy = createIncRequest.CreatedBy
|
||||
createIncidentRequest.StartTime = time.Now()
|
||||
createIncidentRequest.EnableReminder = false
|
||||
return &createIncidentRequest
|
||||
return &createIncidentRequest, nil
|
||||
}
|
||||
|
||||
func (i *incidentService) UpdateIncident(c *gin.Context) {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package service
|
||||
|
||||
type CreateIncidentRequest struct {
|
||||
Title string `gorm:"column:title"`
|
||||
Description string `gorm:"column:description"`
|
||||
SeverityId string `gorm:"column:severityId"`
|
||||
TeamId string `gorm:"column:teamId"`
|
||||
CreatedBy string `gorm:"column:createdBy"`
|
||||
Title string `gorm:"column:title"`
|
||||
Description string `gorm:"column:description"`
|
||||
SeverityName string `gorm:"column:severityName"`
|
||||
TeamName string `gorm:"column:teamName"`
|
||||
CreatedBy string `gorm:"column:createdBy"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user