third commit
This commit is contained in:
@@ -2,6 +2,7 @@ package database
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"cybertron/models/db"
|
"cybertron/models/db"
|
||||||
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -19,3 +20,8 @@ func InitSourceMapRepository(dbClient *gorm.DB) *gorm.DB {
|
|||||||
dbClient.AutoMigrate(&db.SourceMap{})
|
dbClient.AutoMigrate(&db.SourceMap{})
|
||||||
return dbClient
|
return dbClient
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func InitHoustonRepository(dbClient *gorm.DB) *gorm.DB {
|
||||||
|
dbClient.AutoMigrate(&db.Houston{})
|
||||||
|
return dbClient
|
||||||
|
}
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ type Repositories struct {
|
|||||||
ProjectRepository *gorm.DB
|
ProjectRepository *gorm.DB
|
||||||
ReleaseRepository *gorm.DB
|
ReleaseRepository *gorm.DB
|
||||||
SourceMapRepository *gorm.DB
|
SourceMapRepository *gorm.DB
|
||||||
|
HoustonRepository *gorm.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
func InitDependencies() *Dependencies {
|
func InitDependencies() *Dependencies {
|
||||||
@@ -104,6 +105,7 @@ func initRepositories(dbClient *gorm.DB) *Repositories {
|
|||||||
ProjectRepository: database.InitProjectRepository(dbClient),
|
ProjectRepository: database.InitProjectRepository(dbClient),
|
||||||
ReleaseRepository: database.InitReleaseRepository(dbClient),
|
ReleaseRepository: database.InitReleaseRepository(dbClient),
|
||||||
SourceMapRepository: database.InitSourceMapRepository(dbClient),
|
SourceMapRepository: database.InitSourceMapRepository(dbClient),
|
||||||
|
HoustonRepository: database.InitHoustonRepository(dbClient),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package db
|
package db
|
||||||
|
|
||||||
type Houston struct {
|
type Houston struct {
|
||||||
ID int `json:"id" gorm:"autoIncrement:true"`
|
ErrorId string `json:"errorId"`
|
||||||
houstonID string `json:"houstonID"`
|
HoustonID int `json:"houstonID"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ type CreateHoustonRequest struct {
|
|||||||
ResponderTeamId int `json:"responderTeamId"`
|
ResponderTeamId int `json:"responderTeamId"`
|
||||||
ProductIds []int `json:"productIds"`
|
ProductIds []int `json:"productIds"`
|
||||||
CreatedBy string `json:"createdBy"`
|
CreatedBy string `json:"createdBy"`
|
||||||
|
ErrorID string `json:"errorId"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ProductsResponse struct {
|
type ProductsResponse struct {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package service
|
package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"cybertron/models/db"
|
||||||
"cybertron/pkg/houstonClient"
|
"cybertron/pkg/houstonClient"
|
||||||
"cybertron/pkg/kafka/producer"
|
"cybertron/pkg/kafka/producer"
|
||||||
"cybertron/pkg/log"
|
"cybertron/pkg/log"
|
||||||
@@ -26,6 +27,7 @@ type CreateHoustonRequest struct {
|
|||||||
ResponderTeamId int `json:"responderTeamId"`
|
ResponderTeamId int `json:"responderTeamId"`
|
||||||
ProductIds []int `json:"productIds"`
|
ProductIds []int `json:"productIds"`
|
||||||
CreatedBy string `json:"createdBy"`
|
CreatedBy string `json:"createdBy"`
|
||||||
|
ErrorID string `json:"errorId"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHoustonService(logger *log.Logger, dbClient *gorm.DB, kafkaProducer producer.KProducer, houstonClient houstonClient.HoustonClientInterface) *HoustonService {
|
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
|
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
|
// Send the response body back to the client
|
||||||
c.JSON(http.StatusBadRequest, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"message": "Incident created successfully",
|
"message": "Incident created successfully",
|
||||||
"data": response.Data,
|
"data": response.Data,
|
||||||
})
|
})
|
||||||
@@ -136,6 +148,9 @@ func validateCreateHoustonRequest(request CreateHoustonRequest) []string {
|
|||||||
if request.CreatedBy == "" {
|
if request.CreatedBy == "" {
|
||||||
missingFields = append(missingFields, "createdBy")
|
missingFields = append(missingFields, "createdBy")
|
||||||
}
|
}
|
||||||
|
if request.ErrorID == "" {
|
||||||
|
missingFields = append(missingFields, "errorId")
|
||||||
|
}
|
||||||
return missingFields
|
return missingFields
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user