mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-21 17:21:09 +01:00
feat: Update models to use DatabaseV2 instead of DataSourceV2
The code changes update the models and related functions to use the new DatabaseV2 struct instead of the deprecated DataSourceV2 struct. This change ensures consistency and clarity in the codebase.
This commit is contained in:
@@ -9,7 +9,7 @@ import (
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
func PostDataSource(c *gin.Context) {
|
||||
func PostDatabase(c *gin.Context) {
|
||||
// data source
|
||||
var payload struct {
|
||||
Name string `json:"name"`
|
||||
@@ -35,7 +35,7 @@ func PostDataSource(c *gin.Context) {
|
||||
u := GetUserFromContextV2(c)
|
||||
|
||||
// add data source to db
|
||||
dataSource := models.DataSourceV2{
|
||||
dataSource := models.DatabaseV2{
|
||||
Name: payload.Name,
|
||||
Type: payload.Type,
|
||||
Description: payload.Description,
|
||||
@@ -53,7 +53,7 @@ func PostDataSource(c *gin.Context) {
|
||||
}
|
||||
dataSource.SetCreated(u.Id)
|
||||
dataSource.SetUpdated(u.Id)
|
||||
id, err := service.NewModelServiceV2[models.DataSourceV2]().InsertOne(dataSource)
|
||||
id, err := service.NewModelServiceV2[models.DatabaseV2]().InsertOne(dataSource)
|
||||
if err != nil {
|
||||
HandleErrorInternalServerError(c, err)
|
||||
return
|
||||
@@ -68,7 +68,7 @@ func PostDataSource(c *gin.Context) {
|
||||
HandleSuccessWithData(c, dataSource)
|
||||
}
|
||||
|
||||
func PutDataSourceById(c *gin.Context) {
|
||||
func PutDatabaseById(c *gin.Context) {
|
||||
id, err := primitive.ObjectIDFromHex(c.Param("id"))
|
||||
if err != nil {
|
||||
HandleErrorInternalServerError(c, err)
|
||||
@@ -76,13 +76,13 @@ func PutDataSourceById(c *gin.Context) {
|
||||
}
|
||||
|
||||
// data source
|
||||
var dataSource models.DataSourceV2
|
||||
var dataSource models.DatabaseV2
|
||||
if err := c.ShouldBindJSON(&dataSource); err != nil {
|
||||
HandleErrorBadRequest(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
err = service.NewModelServiceV2[models.DataSourceV2]().ReplaceById(id, dataSource)
|
||||
err = service.NewModelServiceV2[models.DatabaseV2]().ReplaceById(id, dataSource)
|
||||
if err != nil {
|
||||
HandleErrorInternalServerError(c, err)
|
||||
return
|
||||
@@ -94,7 +94,7 @@ func PutDataSourceById(c *gin.Context) {
|
||||
}()
|
||||
}
|
||||
|
||||
func PostDataSourceChangePassword(c *gin.Context) {
|
||||
func PostDatabaseChangePassword(c *gin.Context) {
|
||||
id, err := primitive.ObjectIDFromHex(c.Param("id"))
|
||||
if err != nil {
|
||||
HandleErrorBadRequest(c, err)
|
||||
@@ -39,10 +39,10 @@ func GetResultList(c *gin.Context) {
|
||||
}
|
||||
|
||||
// data source
|
||||
ds, err := service.NewModelServiceV2[models2.DataSourceV2]().GetById(dsId)
|
||||
ds, err := service.NewModelServiceV2[models2.DatabaseV2]().GetById(dsId)
|
||||
if err != nil {
|
||||
if err.Error() == mongo2.ErrNoDocuments.Error() {
|
||||
ds = &models2.DataSourceV2{}
|
||||
ds = &models2.DatabaseV2{}
|
||||
} else {
|
||||
HandleErrorInternalServerError(c, err)
|
||||
return
|
||||
|
||||
@@ -56,21 +56,16 @@ func InitRoutes(app *gin.Engine) (err error) {
|
||||
groups := NewRouterGroups(app)
|
||||
|
||||
RegisterController(groups.AuthGroup, "/data/collections", NewControllerV2[models2.DataCollectionV2]())
|
||||
RegisterController(groups.AuthGroup, "/data-sources", NewControllerV2[models2.DataSourceV2]([]Action{
|
||||
RegisterController(groups.AuthGroup, "/databases", NewControllerV2[models2.DatabaseV2]([]Action{
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "",
|
||||
HandlerFunc: PostDataSource,
|
||||
HandlerFunc: PostDatabase,
|
||||
},
|
||||
{
|
||||
Method: http.MethodPut,
|
||||
Path: "/:id",
|
||||
HandlerFunc: PutDataSourceById,
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/:id/change-password",
|
||||
HandlerFunc: PostDataSourceChangePassword,
|
||||
HandlerFunc: PutDatabaseById,
|
||||
},
|
||||
}...))
|
||||
RegisterController(groups.AuthGroup, "/environments", NewControllerV2[models2.EnvironmentV2]())
|
||||
|
||||
@@ -699,7 +699,7 @@ func GetSpiderDataSource(c *gin.Context) {
|
||||
}
|
||||
|
||||
// data source
|
||||
ds, err := service.NewModelServiceV2[models2.DataSourceV2]().GetById(s.DataSourceId)
|
||||
ds, err := service.NewModelServiceV2[models2.DatabaseV2]().GetById(s.DataSourceId)
|
||||
if err != nil {
|
||||
if err.Error() == mongo2.ErrNoDocuments.Error() {
|
||||
HandleSuccess(c)
|
||||
@@ -736,7 +736,7 @@ func PostSpiderDataSource(c *gin.Context) {
|
||||
|
||||
// data source
|
||||
if !dsId.IsZero() {
|
||||
_, err = service.NewModelServiceV2[models2.DataSourceV2]().GetById(dsId)
|
||||
_, err = service.NewModelServiceV2[models2.DatabaseV2]().GetById(dsId)
|
||||
if err != nil {
|
||||
HandleErrorInternalServerError(c, err)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user