Files
cybertron/service/sourceMap.go
2024-08-05 18:57:50 +05:30

57 lines
1.3 KiB
Go

package service
import (
"cybertron/models/db"
"net/http"
"time"
"gorm.io/gorm"
)
type SourceMapService struct {
dbClient *gorm.DB
}
func NewSourceMapService(dbClient *gorm.DB) *SourceMapService {
return &SourceMapService{
dbClient: dbClient,
}
}
func (s *SourceMapService) GetSourceMap() db.SourceMap {
//fetching SourceMap from a client API
sourceMap := db.SourceMap{
Model: gorm.Model{
ID: 1,
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
DeletedAt: gorm.DeletedAt{},
},
ReleaseReferenceId: "some-release-ref-id",
ProjectReferenceId: "some-project-ref-id",
SourceMapZipUrl: "http://example.com/sourcemap.zip",
}
return sourceMap
}
func (s *SourceMapService) StoreSourceMap(c *gin.Context) {
var sourceMap db.SourceMap
if err := c.ShouldBindJSON(&sourceMap); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
result := s.dbClient.Create(&db.SourceMap{
ReleaseReferenceId: sourceMap.ReleaseReferenceId,
ProjectReferenceId: sourceMap.ProjectReferenceId,
SourceMapZipUrl: sourceMap.SourceMapZipUrl,
})
if result.Error != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to store source map"})
return
}
c.JSON(http.StatusOK, gin.H{"status": "Source map stored successfully"})
}