diff --git a/internal/database/repositories.go b/internal/database/repositories.go index 7c77486..e5613ad 100644 --- a/internal/database/repositories.go +++ b/internal/database/repositories.go @@ -2,6 +2,7 @@ package database import ( "cybertron/models/db" + "gorm.io/gorm" ) @@ -19,3 +20,8 @@ func InitSourceMapRepository(dbClient *gorm.DB) *gorm.DB { dbClient.AutoMigrate(&db.SourceMap{}) return dbClient } + +func InitHoustonRepository(dbClient *gorm.DB) *gorm.DB { + dbClient.AutoMigrate(&db.Houston{}) + return dbClient +} diff --git a/internal/dependencies/dependencies.go b/internal/dependencies/dependencies.go index ace44d7..20ea4c2 100644 --- a/internal/dependencies/dependencies.go +++ b/internal/dependencies/dependencies.go @@ -53,6 +53,7 @@ type Repositories struct { ProjectRepository *gorm.DB ReleaseRepository *gorm.DB SourceMapRepository *gorm.DB + HoustonRepository *gorm.DB } func InitDependencies() *Dependencies { @@ -104,6 +105,7 @@ func initRepositories(dbClient *gorm.DB) *Repositories { ProjectRepository: database.InitProjectRepository(dbClient), ReleaseRepository: database.InitReleaseRepository(dbClient), SourceMapRepository: database.InitSourceMapRepository(dbClient), + HoustonRepository: database.InitHoustonRepository(dbClient), } } diff --git a/models/db/houston.go b/models/db/houston.go index 23ea561..8594ec3 100644 --- a/models/db/houston.go +++ b/models/db/houston.go @@ -1,6 +1,6 @@ package db type Houston struct { - ID int `json:"id" gorm:"autoIncrement:true"` - houstonID string `json:"houstonID"` + ErrorId string `json:"errorId"` + HoustonID int `json:"houstonID"` } diff --git a/pkg/houstonClient/houstonClient.go b/pkg/houstonClient/houstonClient.go index f4a93c2..c528ce9 100644 --- a/pkg/houstonClient/houstonClient.go +++ b/pkg/houstonClient/houstonClient.go @@ -76,6 +76,7 @@ type CreateHoustonRequest struct { ResponderTeamId int `json:"responderTeamId"` ProductIds []int `json:"productIds"` CreatedBy string `json:"createdBy"` + ErrorID string `json:"errorId"` } type ProductsResponse struct { diff --git a/service/HoustonService.go b/service/HoustonService.go index a49c2d3..b8e3014 100644 --- a/service/HoustonService.go +++ b/service/HoustonService.go @@ -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 }