* TP-48197 : Implementation of RCA Service, repo, handler, validator and webhook for posting RCA to incident channel * Added unit tests * Added migration script" * PR Review Changes * Update migratrion
53 lines
1.2 KiB
Go
53 lines
1.2 KiB
Go
package handler
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/gin-gonic/gin"
|
|
"go.uber.org/zap"
|
|
"houston/logger"
|
|
"houston/service/rca"
|
|
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 *rca.RcaService
|
|
}
|
|
|
|
func NewRcaHandler(gin *gin.Engine, rcaService *rca.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))
|
|
}
|