TP-0000 | sev-proile (#37)
This commit is contained in:
committed by
GitHub Enterprise
parent
e6b3e3a269
commit
285c1c2794
@@ -126,6 +126,7 @@ func (s *Server) severityHandler() {
|
||||
severityHandler := service.NewSeverityService(s.gin, s.logger, s.db, slackClient)
|
||||
|
||||
s.gin.GET("/severities", severityHandler.GetSeverities)
|
||||
s.gin.GET("/severities/:id", severityHandler.GetSeverities)
|
||||
s.gin.POST("/severities", severityHandler.UpdateSeverities)
|
||||
}
|
||||
|
||||
|
||||
@@ -77,7 +77,6 @@ func (cip *CreateIncidentAction) CreateIncidentModalCommandProcessing(callback s
|
||||
err = cip.addDefaultUsersToIncident(*channelID, teamEntity, severityEntity)
|
||||
if err != nil {
|
||||
cip.logger.Error("[CIP] error while adding default users to incident", zap.Error(err))
|
||||
return
|
||||
}
|
||||
|
||||
cip.tagOncallToIncident(int(incidentEntity.TeamId), *channelID)
|
||||
@@ -90,6 +89,7 @@ func (cip *CreateIncidentAction) CreateIncidentModalCommandProcessing(callback s
|
||||
|
||||
func (cip *CreateIncidentAction) tagOncallToIncident(teamId int, channelId string) {
|
||||
teamEntity, err := cip.teamService.FindTeamById(uint(teamId))
|
||||
cip.slackbotClient.InviteUsersToConversation(channelId, teamEntity.OncallHandle)
|
||||
if err != nil {
|
||||
cip.logger.Error("error in fetching team err: %v", zap.Error(err))
|
||||
}
|
||||
@@ -100,7 +100,7 @@ func (cip *CreateIncidentAction) tagOncallToIncident(teamId int, channelId strin
|
||||
|
||||
func (cip *CreateIncidentAction) InviteOnCallPersonToIncident(channelId, ts string) {
|
||||
go func() {
|
||||
time.Sleep(2 * time.Second)
|
||||
time.Sleep(3 * time.Second)
|
||||
msg, _, _, _ := cip.client.GetConversationReplies(&slack.GetConversationRepliesParameters{
|
||||
ChannelID: channelId,
|
||||
Timestamp: ts,
|
||||
|
||||
@@ -341,7 +341,7 @@ func (i *incidentService) tagOncallToIncident(teamId int, channelId string) {
|
||||
|
||||
func (i *incidentService) InviteOnCallPersonToIncident(channelId, ts string) {
|
||||
go func() {
|
||||
time.Sleep(2 * time.Second)
|
||||
time.Sleep(3 * time.Second)
|
||||
msg, _, _, _ := i.socketModeClient.GetConversationReplies(&slack.GetConversationRepliesParameters{
|
||||
ChannelID: channelId,
|
||||
Timestamp: ts,
|
||||
|
||||
@@ -1,11 +1,26 @@
|
||||
package service
|
||||
|
||||
import "github.com/lib/pq"
|
||||
import (
|
||||
"houston/model/severity"
|
||||
|
||||
"github.com/lib/pq"
|
||||
)
|
||||
|
||||
type SeverityResponse struct {
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Sla int `json:"sla"`
|
||||
SlackUserIds pq.StringArray `json:"slackUserIds"`
|
||||
}
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Sla int `json:"sla"`
|
||||
SlackUserIds pq.StringArray `json:"slackUserIds"`
|
||||
Participants []UserResponse `json:"participants,omitempty"`
|
||||
}
|
||||
|
||||
func ConvertToSeverityResponse(severityEntity severity.SeverityEntity) SeverityResponse {
|
||||
return SeverityResponse{
|
||||
Id: severityEntity.ID,
|
||||
Name: severityEntity.Name,
|
||||
Description: severityEntity.Description,
|
||||
Sla: severityEntity.Sla,
|
||||
SlackUserIds: severityEntity.SlackUserIds,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
common "houston/service/response/common"
|
||||
utils "houston/service/utils"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
@@ -32,7 +33,44 @@ func NewSeverityService(gin *gin.Engine, logger *zap.Logger, db *gorm.DB, client
|
||||
}
|
||||
|
||||
func (s *severityService) GetSeverities(c *gin.Context) {
|
||||
sevId := c.Param("id")
|
||||
severityService := severity.NewSeverityRepository(s.logger, s.db)
|
||||
|
||||
if sevId != "" {
|
||||
SevId, err := strconv.Atoi(sevId)
|
||||
if err != nil {
|
||||
s.logger.Error("error in parsing sevId", zap.String("sevId", sevId), zap.Error(err))
|
||||
c.JSON(http.StatusBadRequest, common.ErrorResponse(err, http.StatusBadRequest, nil))
|
||||
return
|
||||
}
|
||||
sev, err := severityService.FindSeverityById(uint(SevId))
|
||||
if err != nil {
|
||||
s.logger.Error("error in fetching severity by id", zap.Any("SevId", SevId))
|
||||
c.JSON(http.StatusBadRequest, common.ErrorResponse(err, http.StatusBadRequest, nil))
|
||||
return
|
||||
}
|
||||
var userResponses []service.UserResponse
|
||||
for _, userId := range sev.SlackUserIds {
|
||||
usersInfo, err := s.client.GetUsersInfo(userId)
|
||||
if err != nil || len(*usersInfo) == 0 {
|
||||
s.logger.Error("error in getting user info", zap.String("userId", userId), zap.Error(err))
|
||||
c.JSON(http.StatusBadRequest, common.ErrorResponse(err, http.StatusBadRequest, nil))
|
||||
return
|
||||
}
|
||||
users := *usersInfo
|
||||
userResponses = append(userResponses, service.UserResponse{
|
||||
Id: users[0].ID,
|
||||
Name: users[0].Profile.RealName,
|
||||
Email: users[0].Profile.Email,
|
||||
Image: users[0].Profile.Image32,
|
||||
})
|
||||
}
|
||||
sevResponse := service.ConvertToSeverityResponse(*sev)
|
||||
sevResponse.Participants = userResponses
|
||||
c.JSON(http.StatusOK, common.SuccessResponse(sevResponse, http.StatusOK))
|
||||
return
|
||||
}
|
||||
|
||||
severityEntities, err := severityService.GetAllActiveSeverity()
|
||||
if err != nil {
|
||||
s.logger.Error("error in fetching severties", zap.Error(err))
|
||||
|
||||
Reference in New Issue
Block a user