Files
houston-be/cmd/app/handler/rca_handler.go
Vijay Joshi ad96361d68 TP-49979 , TP-52174 : API to get resolution tags + resolve incident API + incident resolve entire flow refactor (#347)
* TP-49979 : Added API to get tags for resolving incident

* TP-49979 : Set up basic structure for resolve incident from UI

* TP-49979 : Complete till post rca flow

* TP-49979 : Complete till rca gen flow

* TP-52174 : rebase changes

* TP-52174 : Integrate with slack

* TP-52174 : fix error in flows

* TP-52174 : Segregate interface and impl

* TP-52174 : Fix ut failures

* TP-52174 : Fix resolve tag api error

* TP-52174 : Fix jira link bug

* TP-52174 : Remove nil

* TP-52174 : Rebase changes

* TP-52174 : Jira links table fix

* TP-52174 : Line length fix

* TP-52174 : Makefile changes

* TP-52174 : Basic bug fixes

* TP-52174 : Minor fixes

* TP-52174 : Add UT's for initial flows

* TP-52174 : Added all UT's

* TP-52174 : More PR review changes

* TP-52174 : Add UT's for incident jira and tag service

* TP-52174 : Fix jira link bug and batched create incident tags db call

* TP-52174 : Make auto archival severities configurable

* TP-52174 : Fix jira link in incident table issue
2024-02-01 15:23:15 +05:30

79 lines
2.2 KiB
Go

package handler
import (
"fmt"
"github.com/gin-gonic/gin"
"github.com/spf13/viper"
"go.uber.org/zap"
"houston/common/util"
"houston/logger"
rcaService "houston/service/rca/impl"
request "houston/service/request"
common "houston/service/response/common"
utils "houston/service/utils"
"net/http"
)
const (
rcaLogTag = "[rca_handler]"
)
type RcaHandler struct {
gin *gin.Engine
service *rcaService.RcaService
}
func NewRcaHandler(gin *gin.Engine, rcaService *rcaService.RcaService) *RcaHandler {
return &RcaHandler{
gin: gin,
service: rcaService,
}
}
func (handler *RcaHandler) HandlePostRca(c *gin.Context) {
var postRcaRequest request.PostRcaRequest
if err := c.ShouldBindJSON(&postRcaRequest); err != nil {
c.JSON(http.StatusInternalServerError, err)
return
}
if err := utils.ValidatePostRcaRequest(postRcaRequest); err != nil {
logger.Error(fmt.Sprintf("%s Received invalid request to post Rca", rcaLogTag), zap.Error(err))
c.JSON(http.StatusBadRequest, common.ErrorResponse(err, http.StatusBadRequest, nil))
return
}
err := handler.service.PostRcaToIncidentChannel(postRcaRequest)
if err != nil {
c.JSON(http.StatusBadRequest, common.ErrorResponse(err, http.StatusBadRequest, nil))
return
}
c.JSON(http.StatusOK, common.SuccessResponse("Message posted successfully!", http.StatusOK))
}
func (handler *RcaHandler) HandleGetConversationUrls(c *gin.Context) {
serviceToken := c.GetHeader(util.ServiceTokenHeader)
id := c.Param(util.IncidentIdParam)
if serviceToken != viper.GetString("MAVERICK_TO_HOUSTON_SERVICE_TOKEN") {
c.JSON(http.StatusUnauthorized, common.ErrorResponse(fmt.Errorf("invalid service token"), http.StatusUnauthorized, nil))
return
}
incidentID, err := utils.ValidateIdParameter(id)
if err != nil {
logger.Error(fmt.Sprintf("%s invalid incident id: %s", rcaLogTag, id), zap.Error(err))
c.JSON(http.StatusBadRequest, common.ErrorResponse(err, http.StatusBadRequest, nil))
return
}
preSignedUrl, err := handler.service.GetRcaInputPreSignedUrl(incidentID)
if err != nil {
c.JSON(http.StatusBadRequest, common.ErrorResponse(err, http.StatusBadRequest, nil))
return
}
c.JSON(http.StatusOK, common.SuccessResponse(preSignedUrl, http.StatusOK))
}