Skip to content
Snippets Groups Projects
Commit d4347f0c authored by Snorre Hareide Hansen's avatar Snorre Hareide Hansen
Browse files

reverted all changes from SplitPath

parent 822920d9
Branches
No related tags found
No related merge requests found
......@@ -10,7 +10,7 @@ import (
// Get a document
func (fs Firestore) GetDoc(path string) (Document, error) {
collection, id, subCollection, subId, _, err := SplitPath(path)
collection, id, subCollection, subId, err := SplitPath(path)
if err != nil {
return Document{}, err
}
......@@ -35,7 +35,7 @@ func (fs Firestore) GetDoc(path string) (Document, error) {
// Delete a document
func (fs Firestore) DeleteDoc(path string) error {
collection, id, subCollection, subId, _, err := SplitPath(path)
collection, id, subCollection, subId, err := SplitPath(path)
if err != nil {
return err
}
......@@ -55,7 +55,7 @@ func (fs Firestore) DeleteDoc(path string) error {
// Update a document
func (fs Firestore) UpdateDoc(path string, newValues map[string]interface{}) error {
collection, id, subCollection, subId, _, err := SplitPath(path)
collection, id, subCollection, subId, err := SplitPath(path)
if err != nil {
return err
}
......@@ -89,7 +89,7 @@ func (fs Firestore) GetDocsWhere(path string, conditionValues map[string]interfa
return []Document{}, errors.New("no conditions")
}*/
collection, id, subCollection, _, _, err := SplitPath(path)
collection, id, subCollection, _, err := SplitPath(path)
if err != nil {
return []Document{}, err
}
......@@ -142,7 +142,7 @@ func (fs Firestore) DeleteDocsWhere(path string, conditionValues map[string]inte
return errors.New("no conditions")
}
collection, id, subCollection, _, _, err := SplitPath(path)
collection, id, subCollection, _, err := SplitPath(path)
if err != nil {
return err
}
......@@ -195,7 +195,7 @@ func (fs Firestore) UpdateDocsWhere(path string, newValues map[string]interface{
return errors.New("no conditions")
}
collection, id, subCollection, _, _, err := SplitPath(path)
collection, id, subCollection, _, err := SplitPath(path)
if err != nil {
return err
}
......@@ -246,7 +246,7 @@ func (fs Firestore) UpdateDocsWhere(path string, newValues map[string]interface{
// Post document
func (fs Firestore) PostDoc(path string, values map[string]interface{}) error {
collection, id, subCollection, _, _, err := SplitPath(path)
collection, id, subCollection, _, err := SplitPath(path)
if err != nil {
return err
}
......@@ -268,7 +268,7 @@ func (fs Firestore) PostDoc(path string, values map[string]interface{}) error {
// Post a document with specified id
func (fs Firestore) PostDocId(path string, id string, values map[string]interface{}) error {
collection, docId, subCollection, _, _, err := SplitPath(path)
collection, docId, subCollection, _, err := SplitPath(path)
if err != nil {
return err
}
......@@ -290,7 +290,7 @@ func (fs Firestore) PostDocId(path string, id string, values map[string]interfac
// Increment one or more numeric fields of a document
func (fs Firestore) IncrementDocField(path string, fields map[string]interface{}) error {
collection, id, subCollection, subId, _, err := SplitPath(path)
collection, id, subCollection, subId, err := SplitPath(path)
if err != nil {
return err
}
......@@ -334,7 +334,7 @@ func (fs Firestore) GetPaginatedDocs(path string, pageNum int, pageSize int) ([]
return nil, errors.New("invalid pagination values")
}
collection, _, _, _, _, err := SplitPath(path)
collection, _, _, _, err := SplitPath(path)
if err != nil {
return nil, err
}
......@@ -373,7 +373,7 @@ func (fs Firestore) SearchDocs(path string, searchTerm string, pageNum int, page
return nil, errors.New("invalid pagination values")
}
collection, _, _, _, _, err := SplitPath(path)
collection, _, _, _, err := SplitPath(path)
if err != nil {
return nil, err
}
......
......@@ -6,30 +6,27 @@ import (
)
// Splits a path to a document, with a maximum of one subcollection
func SplitPath(path string) (string, string, string, string, string, error) {
func SplitPath(path string) (string, string, string, string, error) {
words := strings.Split(path, "/")
// Invalid path
if len(words) < 1 || len(words) > 5 {
return "", "", "", "", "", errors.New("invalid path")
return "", "", "", "", errors.New("invalid path")
}
if len(words) == 1 {
return words[0], "", "", "", "", nil
return words[0], "", "", "", nil
}
if len(words) == 2 {
return words[0], words[1], "", "", "", nil
return words[0], words[1], "", "", nil
}
if len(words) == 3 {
return words[0], words[1], words[2], "", "", nil
}
if len(words) == 4 {
return words[0], words[1], words[2], words[3], "", nil
return words[0], words[1], words[2], "", nil
}
return words[0], words[1], words[2], words[3], words[4], nil
return words[0], words[1], words[2], words[3], nil
}
// Delete a user's review for a game. Returns whether or not the review was deleted.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment