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

@@ -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
}

View File

@@ -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),
}
}

View File

@@ -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"`
}

View File

@@ -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 {

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
}