mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-07 09:05:55 +00:00
Adjust some comments and handle error conditions in Handler.
This commit is contained in:
parent
5435886e7b
commit
06f387842b
2 changed files with 19 additions and 6 deletions
10
frame.go
10
frame.go
|
|
@ -439,19 +439,21 @@ func (f *Frame) CreateField(field *Field) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// GetFields list all the fields.
|
||||
// GetFields returns a list of all the fields in the frame.
|
||||
func (f *Frame) GetFields() (*FrameSchema, error) {
|
||||
f.mu.Lock()
|
||||
defer f.mu.Unlock()
|
||||
f.mu.RLock()
|
||||
defer f.mu.RUnlock()
|
||||
|
||||
// Ensure frame supports fields.
|
||||
// Ensure the frame supports fields.
|
||||
if !f.RangeEnabled() {
|
||||
return nil, ErrFrameFieldsNotAllowed
|
||||
}
|
||||
|
||||
err := f.loadSchema()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return f.schema, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
15
handler.go
15
handler.go
|
|
@ -119,7 +119,7 @@ func NewRouter(handler *Handler) *mux.Router {
|
|||
router.HandleFunc("/index/{index}/frame/{frame}/restore", handler.handlePostFrameRestore).Methods("POST")
|
||||
router.HandleFunc("/index/{index}/frame/{frame}/time-quantum", handler.handlePatchFrameTimeQuantum).Methods("PATCH")
|
||||
router.HandleFunc("/index/{index}/frame/{frame}/field/{field}", handler.handlePostFrameField).Methods("POST")
|
||||
router.HandleFunc("/index/{index}/frame/{frame}/fields", handler.handleGetFrameField).Methods("GET")
|
||||
router.HandleFunc("/index/{index}/frame/{frame}/fields", handler.handleGetFrameFields).Methods("GET")
|
||||
router.HandleFunc("/index/{index}/frame/{frame}/field/{field}", handler.handleDeleteFrameField).Methods("DELETE")
|
||||
router.HandleFunc("/index/{index}/frame/{frame}/views", handler.handleGetFrameViews).Methods("GET")
|
||||
router.HandleFunc("/index/{index}/frame/{frame}/view/{view}", handler.handleDeleteView).Methods("DELETE")
|
||||
|
|
@ -843,12 +843,22 @@ func (h *Handler) handleDeleteFrameField(w http.ResponseWriter, r *http.Request)
|
|||
}
|
||||
}
|
||||
|
||||
func (h *Handler) handleGetFrameField(w http.ResponseWriter, r *http.Request) {
|
||||
func (h *Handler) handleGetFrameFields(w http.ResponseWriter, r *http.Request) {
|
||||
indexName := mux.Vars(r)["index"]
|
||||
frameName := mux.Vars(r)["frame"]
|
||||
|
||||
index := h.Holder.index(indexName)
|
||||
if index == nil {
|
||||
http.Error(w, ErrIndexNotFound.Error(), http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
frame := index.frame(frameName)
|
||||
if frame == nil {
|
||||
http.Error(w, ErrFrameNotFound.Error(), http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
schema, err := frame.GetFields()
|
||||
if err == ErrFrameFieldsNotAllowed {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
|
|
@ -857,6 +867,7 @@ func (h *Handler) handleGetFrameField(w http.ResponseWriter, r *http.Request) {
|
|||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
// Encode response.
|
||||
if err := json.NewEncoder(w).Encode(getFrameFieldsResponse{Fields: schema.Fields}); err != nil {
|
||||
h.logger().Printf("response encoding error: %s", err)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue