third commit

This commit is contained in:
aman.singh
2024-09-12 13:18:04 +05:30
parent 1f79e1d4cf
commit 7a5ebbc580
5 changed files with 27 additions and 3 deletions

View File

@@ -1,6 +1,7 @@
package service
import (
"cybertron/models/db"
"cybertron/pkg/houstonClient"
"cybertron/pkg/kafka/producer"
"cybertron/pkg/log"
@@ -26,6 +27,7 @@ type CreateHoustonRequest struct {
ResponderTeamId int `json:"responderTeamId"`
ProductIds []int `json:"productIds"`
CreatedBy string `json:"createdBy"`
ErrorID string `json:"errorId"`
}
func NewHoustonService(logger *log.Logger, dbClient *gorm.DB, kafkaProducer producer.KProducer, houstonClient houstonClient.HoustonClientInterface) *HoustonService {
@@ -71,8 +73,18 @@ func (houstonService *HoustonService) CreateHouston(c *gin.Context) {
return
}
result := houstonService.dbClient.Create(&db.Houston{
ErrorId: request.ErrorID,
HoustonID: response.Data.ID,
})
if result.Error != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": result.Error.Error(), "message": "Failed to create project"})
return
}
// Send the response body back to the client
c.JSON(http.StatusBadRequest, gin.H{
c.JSON(http.StatusOK, gin.H{
"message": "Incident created successfully",
"data": response.Data,
})
@@ -136,6 +148,9 @@ func validateCreateHoustonRequest(request CreateHoustonRequest) []string {
if request.CreatedBy == "" {
missingFields = append(missingFields, "createdBy")
}
if request.ErrorID == "" {
missingFields = append(missingFields, "errorId")
}
return missingFields
}