Skip to content

Commit

Permalink
feat: improve fetch impl of firebase service
Browse files Browse the repository at this point in the history
  • Loading branch information
theiskaa committed Dec 12, 2022
1 parent 7065a4a commit a002731
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions lib/services/firebase_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -631,18 +631,11 @@ func (s *FirebaseService) Fetch(remote ServiceRepo) ([]models.Node, []error) {
errors := []error{}

for _, node := range nodes {
if node.IsFolder() {
errors = append(errors, assets.CannotDoSth("fetch", node.Title, assets.NotAvailableForFirebase))
continue
}

if exists, err := s.IsNodeExists(node); err != nil {
errors = append(errors, assets.CannotDoSth("fetch", node.Title, err))
continue
} else if exists {
exists, _ := s.IsNodeExists(node)
if exists && !node.IsFolder() {
local, err := s.View(node.ToNote())
if err != nil {
errors = append(errors, err)
errors = append(errors, assets.CannotDoSth("fetch", node.Title, err))
continue
}

Expand All @@ -659,8 +652,22 @@ func (s *FirebaseService) Fetch(remote ServiceRepo) ([]models.Node, []error) {
continue
}

if node.IsFolder() && !exists {
if _, err := s.Mkdir(node.ToFolder()); err != nil {
errors = append(errors, assets.CannotDoSth("fetch", node.Title, err))
} else {
fetched = append(fetched, node)
}

continue
}

if exists {
continue
}

if _, err := s.Create(node.ToNote()); err != nil {
errors = append(errors, err)
errors = append(errors, assets.CannotDoSth("fetch", node.Title, err))
} else {
fetched = append(fetched, node)
}
Expand Down

0 comments on commit a002731

Please sign in to comment.