summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2017-05-06 15:52:00 +0200
committerChristian Pointner <equinox@spreadspace.org>2017-05-06 15:52:00 +0200
commit19dd75f66d33759a999559f0124da9db3d26975a (patch)
treeac6b2df3d5bd4904ae13a50fd4e44c91d5561bc3
parentimplemented bulk receiver for updates via web interfaces (not working yet) (diff)
remove get sources/:id web api point
-rw-r--r--src/hub/src/spreadspace.org/sfive/s5srvWeb.go25
-rw-r--r--src/hub/src/spreadspace.org/sfive/s5store.go28
-rw-r--r--src/hub/src/spreadspace.org/sfive/s5store_test.go20
-rw-r--r--src/hub/src/spreadspace.org/sfive/s5typesStore.go5
4 files changed, 19 insertions, 59 deletions
diff --git a/src/hub/src/spreadspace.org/sfive/s5srvWeb.go b/src/hub/src/spreadspace.org/sfive/s5srvWeb.go
index 662e08d..4f2276e 100644
--- a/src/hub/src/spreadspace.org/sfive/s5srvWeb.go
+++ b/src/hub/src/spreadspace.org/sfive/s5srvWeb.go
@@ -78,30 +78,6 @@ func (srv Server) webGetSourcesList(c web.C, w http.ResponseWriter, r *http.Requ
fmt.Fprintf(w, "%s", jsonString)
}
-func (srv Server) webGetSource(c web.C, w http.ResponseWriter, r *http.Request) {
- const resourceName = "source"
- id, err := strconv.ParseInt(c.URLParams["id"], 10, 64)
- if err != nil {
- http.Error(w, fmt.Sprintf("invalid id: %s: %v", resourceName, err), http.StatusBadRequest)
- return
- }
- value, err := srv.store.GetSource(int(id))
- if err != nil {
- if err == ErrNotFound {
- http.Error(w, fmt.Sprintf("failed to retrieve %s: %v", resourceName, err), http.StatusNotFound)
- } else {
- http.Error(w, fmt.Sprintf("failed to retrieve %s: %v", resourceName, err), http.StatusInternalServerError)
- }
- return
- }
- jsonString, err := json.Marshal(value)
- if err != nil {
- http.Error(w, fmt.Sprintf("failed to marshal %s: %v", resourceName, err), http.StatusInternalServerError)
- return
- }
- fmt.Fprintf(w, "%s", jsonString)
-}
-
func (srv Server) webGetUpdateList(c web.C, w http.ResponseWriter, r *http.Request) {
const resourceName = "updates"
from := 0
@@ -237,7 +213,6 @@ func (srv Server) ServeWeb() {
goji.Get("/healthz", srv.webHealthz)
goji.Get("/hubs", srv.webGetHubsList)
goji.Get("/sources", srv.webGetSourcesList)
- goji.Get("/sources/:id", srv.webGetSource)
goji.Get("/updates", srv.webGetUpdateList)
goji.Get("/updates/:id", srv.webGetUpdate)
goji.Post("/updates", srv.webPostUpdate)
diff --git a/src/hub/src/spreadspace.org/sfive/s5store.go b/src/hub/src/spreadspace.org/sfive/s5store.go
index a59166f..46db278 100644
--- a/src/hub/src/spreadspace.org/sfive/s5store.go
+++ b/src/hub/src/spreadspace.org/sfive/s5store.go
@@ -317,12 +317,12 @@ func (st Store) setLastUpdateForUuid(tx *bolt.Tx, uuid string, duId int) error {
func (st Store) appendItem(tx *bolt.Tx, update DataUpdateFull) (duId int, err error) {
du := NewDataUpdateDb(update)
+ src := NewSourceDb(update)
- srcUuid := update.SourceHubUuid
- if du.SourceHubId, err = st.insertNewHub(tx, srcUuid); err != nil {
+ if du.SourceHubId, err = st.insertNewHub(tx, update.SourceHubUuid); err != nil {
return
}
- if du.SourceId, err = st.insertNewSource(tx, NewSourceDb(update)); err != nil {
+ if du.SourceId, err = st.insertNewSource(tx, src); err != nil {
return
}
if duId, err = st.insertDataUpdate(tx, du); err != nil {
@@ -332,11 +332,11 @@ func (st Store) appendItem(tx *bolt.Tx, update DataUpdateFull) (duId int, err er
return
}
- if srcUuid != "" {
- err = st.setLastUpdateForUuid(tx, srcUuid, du.SourceHubDataUpdateId)
+ if update.SourceHubUuid != "" {
+ err = st.setLastUpdateForUuid(tx, update.SourceHubUuid, du.SourceHubDataUpdateId)
}
- if fwdUuid := update.ForwardHubUuid; fwdUuid != "" {
- err = st.setLastUpdateForUuid(tx, fwdUuid, update.ForwardHubDataUpdateId)
+ if update.ForwardHubUuid != "" {
+ err = st.setLastUpdateForUuid(tx, update.ForwardHubUuid, update.ForwardHubDataUpdateId)
}
return
}
@@ -381,7 +381,7 @@ func (st Store) getSource(tx *bolt.Tx, id int) (res sourceDb, err error) {
jsonData := b.Get(itob(id))
if jsonData == nil {
- err = ErrNotFound
+ err = ErrSourceNotFound
return
}
if err = json.Unmarshal(jsonData, &res); err != nil {
@@ -531,18 +531,6 @@ func (st Store) GetHubs() (res []string, err error) {
return
}
-func (st Store) GetSource(id int) (res SourceId, err error) {
- err = st.db.View(func(tx *bolt.Tx) error {
- src, err := st.getSource(tx, id)
- if err != nil {
- return err
- }
- res.CopyFromSourceDb(src)
- return nil
- })
- return
-}
-
func (st Store) GetSources() (res []SourceId, err error) {
res = []SourceId{}
err = st.db.View(func(tx *bolt.Tx) error {
diff --git a/src/hub/src/spreadspace.org/sfive/s5store_test.go b/src/hub/src/spreadspace.org/sfive/s5store_test.go
index 07adc47..09bd7dd 100644
--- a/src/hub/src/spreadspace.org/sfive/s5store_test.go
+++ b/src/hub/src/spreadspace.org/sfive/s5store_test.go
@@ -741,8 +741,13 @@ func TestGetSources(t *testing.T) {
}
defer store.Close()
- if _, err := store.GetSource(17); err != ErrNotFound {
- t.Fatalf("fetching not exisiting source should return not-found, error=%v", err)
+ // check if source list is empty
+ srcList, err := store.GetSources()
+ if err != nil {
+ t.Fatalf("fetching sources failed: %v", err)
+ }
+ if len(srcList) != 0 {
+ t.Fatalf("wrong number of sources: %d, expected 0", len(srcList))
}
// generate/append some data
@@ -751,17 +756,8 @@ func TestGetSources(t *testing.T) {
t.Fatalf("unexpected error: %v", err)
}
- // fetch first source
- src, err := store.GetSource(1)
- if err != nil {
- t.Fatalf("fetching source failed: %v", err)
- }
- if !reflect.DeepEqual(data[0].SourceId, src) {
- t.Fatalf("failed to fetch source\nactual: %v\nexpected: %v\n", src, data[0].SourceId)
- }
-
// fetch all the sources
- srcList, err := store.GetSources()
+ srcList, err = store.GetSources()
if err != nil {
t.Fatalf("fetching sources failed: %v", err)
}
diff --git a/src/hub/src/spreadspace.org/sfive/s5typesStore.go b/src/hub/src/spreadspace.org/sfive/s5typesStore.go
index bba4433..41fb29a 100644
--- a/src/hub/src/spreadspace.org/sfive/s5typesStore.go
+++ b/src/hub/src/spreadspace.org/sfive/s5typesStore.go
@@ -41,8 +41,9 @@ import (
)
var (
- ErrNotFound = errors.New("not found")
- ErrReadOnly = errors.New("store is in read-only mode")
+ ErrNotFound = errors.New("date-update entry not found")
+ ErrSourceNotFound = errors.New("source entry not found")
+ ErrReadOnly = errors.New("store is in read-only mode")
)
const (