Skip to content

Commit

Permalink
fix: create spider issue
Browse files Browse the repository at this point in the history
  • Loading branch information
tikazyq committed Jun 14, 2024
1 parent 8015902 commit 5c8c119
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
16 changes: 9 additions & 7 deletions controllers/spider_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,7 @@ func PostSpider(c *gin.Context) {
}

// create folder
fsSvc, err := getSpiderFsSvc(c)
if err != nil {
HandleErrorInternalServerError(c, err)
return
}
err = fsSvc.CreateDir(".")
err = getSpiderFsSvcById(id).CreateDir(".")
if err != nil {
HandleErrorInternalServerError(c, err)
return
Expand Down Expand Up @@ -1106,6 +1101,12 @@ func getSpiderFsSvc(c *gin.Context) (svc interfaces.FsServiceV2, err error) {
return fsSvc, nil
}

func getSpiderFsSvcById(id primitive.ObjectID) interfaces.FsServiceV2 {
workspacePath := viper.GetString("workspace")
fsSvc := fs.NewFsServiceV2(filepath.Join(workspacePath, id.Hex()))
return fsSvc
}

func getSpiderGitClient(id primitive.ObjectID) (client *vcs.GitClient, err error) {
// git
g, err := service.NewModelServiceV2[models.GitV2]().GetById(id)
Expand Down Expand Up @@ -1281,10 +1282,11 @@ func upsertSpiderDataCollection(s *models.SpiderV2) (err error) {
if errors.Is(err, mongo2.ErrNoDocuments) {
// not exists, add new
dc = &models.DataCollectionV2{Name: s.ColName}
_, err = modelSvc.InsertOne(*dc)
dcId, err := modelSvc.InsertOne(*dc)
if err != nil {
return err
}
dc.SetId(dcId)
} else {
// error
return err
Expand Down
1 change: 1 addition & 0 deletions controllers/spider_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func TestCreateSpider(t *testing.T) {
require.Nil(t, err)
assert.False(t, response.Data.Id.IsZero())
assert.Equal(t, payload.Name, response.Data.Name)
assert.False(t, response.Data.ColId.IsZero())
}

func TestGetSpiderById(t *testing.T) {
Expand Down

0 comments on commit 5c8c119

Please sign in to comment.