* INFRA-3664 : Make get users in conversation api more performant * INFRA-3664 : Add apis for incident user sync and get users in incident performance improvements * INFRA-3664 : Self review * INFRA-3664 : Add migration script * INFRA-3664 : Review comments * INFRA-3664 : Constant chanes * INFRA-3664 : Add rate limit constants * INFRA-3664 : Add rate limit constants * INFRA-3664 : Fix failing tests * INFRA-3664 : Add UT's
63 lines
1.9 KiB
Go
63 lines
1.9 KiB
Go
package handler
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"houston/common/metrics"
|
|
"houston/common/util"
|
|
"houston/service/incidentUser"
|
|
incidentUserRequest "houston/service/request/incidentUser"
|
|
common "houston/service/response/common"
|
|
"net/http"
|
|
"strconv"
|
|
)
|
|
|
|
type IncidentUserHandler struct {
|
|
gin *gin.Engine
|
|
service incidentUser.IncidentUserService
|
|
}
|
|
|
|
func NewIncidentUserHandler(
|
|
gin *gin.Engine,
|
|
incidentUserService incidentUser.IncidentUserService,
|
|
) *IncidentUserHandler {
|
|
return &IncidentUserHandler{
|
|
gin: gin,
|
|
service: incidentUserService,
|
|
}
|
|
}
|
|
|
|
func (handler *IncidentUserHandler) HandleGetIncidentUsers(c *gin.Context) {
|
|
incidentId, err := strconv.ParseUint(c.Query(INCIDENT_ID_QUERY), 10, 32)
|
|
if err != nil {
|
|
c.JSON(http.StatusBadRequest, common.ErrorResponse(err, http.StatusBadRequest, nil))
|
|
return
|
|
}
|
|
|
|
response, err := handler.service.GetIncidentUsersByIncidentId(uint(incidentId))
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, common.ErrorResponse(err, http.StatusInternalServerError, nil))
|
|
metrics.PublishHoustonFlowFailureMetrics(util.GET_INCIDENT_USERS, err.Error())
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, common.SuccessResponse(response, http.StatusOK))
|
|
}
|
|
|
|
func (handler *IncidentUserHandler) HandleSyncIncidentUsers(c *gin.Context) {
|
|
var syncIncidentUserRequest incidentUserRequest.SyncIncidentUserRequest
|
|
if err := c.ShouldBindJSON(&syncIncidentUserRequest); err != nil {
|
|
c.JSON(http.StatusBadRequest, common.ErrorResponse(err, http.StatusBadRequest, nil))
|
|
return
|
|
}
|
|
|
|
requestStatus, err := handler.service.SyncIncidentUsers(syncIncidentUserRequest)
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, common.ErrorResponse(err, http.StatusInternalServerError, nil))
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, common.SuccessResponse("Acknowledged request to sync incident-user data with request status ID: "+requestStatus.RequestID.String(), http.StatusOK))
|
|
}
|
|
|
|
const INCIDENT_ID_QUERY = "incident_id"
|