-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
655 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
package apicollectionv1 | ||
|
||
type CollectionResponse struct { | ||
Name string `json:"name"` | ||
Total int `json:"total"` | ||
Indexes int `json:"indexes"` | ||
Name string `json:"name"` | ||
Total int `json:"total"` | ||
Indexes int `json:"indexes"` | ||
Defaults map[string]any `json:"defaults"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package apicollectionv1 | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"net/http" | ||
|
||
"github.com/fulldump/box" | ||
|
||
"github.com/fulldump/inceptiondb/service" | ||
) | ||
|
||
type setDefaultsInput map[string]any | ||
|
||
func setDefaults(ctx context.Context, w http.ResponseWriter, r *http.Request) error { | ||
|
||
s := GetServicer(ctx) | ||
collectionName := box.GetUrlParameter(ctx, "collectionName") | ||
col, err := s.GetCollection(collectionName) | ||
if err == service.ErrorCollectionNotFound { | ||
col, err = s.CreateCollection(collectionName) | ||
if err != nil { | ||
return err // todo: handle/wrap this properly | ||
} | ||
err = col.SetDefaults(newCollectionDefaults()) | ||
if err != nil { | ||
return err // todo: handle/wrap this properly | ||
} | ||
} | ||
if err != nil { | ||
return err // todo: handle/wrap this properly | ||
} | ||
|
||
defaults := col.Defaults | ||
|
||
err = json.NewDecoder(r.Body).Decode(&defaults) | ||
if err != nil { | ||
return err // todo: handle/wrap this properly | ||
} | ||
|
||
for k, v := range defaults { | ||
if v == nil { | ||
delete(defaults, k) | ||
} | ||
} | ||
|
||
if len(defaults) == 0 { | ||
defaults = nil | ||
} | ||
|
||
err = col.SetDefaults(defaults) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = json.NewEncoder(w).Encode(col.Defaults) | ||
if err != nil { | ||
return err // todo: handle/wrap this properly | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.