mirror of
https://github.com/ddworken/hishtory.git
synced 2025-06-24 14:01:46 +02:00
Add back in the bootstrap handler since I realized it is still useful to provide some amount of history at first install immediately
This commit is contained in:
parent
da30659f64
commit
8a018b71b8
@ -85,6 +85,23 @@ func apiSubmitHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
func apiEBootstrapHandler(w http.ResponseWriter, r *http.Request) {
|
||||
userId := r.URL.Query().Get("user_id")
|
||||
deviceId := r.URL.Query().Get("device_id")
|
||||
updateUsageData(userId, deviceId)
|
||||
tx := GLOBAL_DB.Where("user_id = ?", userId)
|
||||
var historyEntries []*shared.EncHistoryEntry
|
||||
result := tx.Find(&historyEntries)
|
||||
if result.Error != nil {
|
||||
panic(fmt.Errorf("DB query error: %v", result.Error))
|
||||
}
|
||||
resp, err := json.Marshal(historyEntries)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
w.Write(resp)
|
||||
}
|
||||
|
||||
func apiQueryHandler(w http.ResponseWriter, r *http.Request) {
|
||||
userId := r.URL.Query().Get("user_id")
|
||||
deviceId := r.URL.Query().Get("device_id")
|
||||
|
@ -97,6 +97,19 @@ func TestESubmitThenQuery(t *testing.T) {
|
||||
if !data.EntryEquals(decEntry, entry) {
|
||||
t.Fatalf("DB data is different than input! \ndb =%#v\ninput=%#v", *dbEntry, entry)
|
||||
}
|
||||
|
||||
// Bootstrap handler should return 2 entries, one for each device
|
||||
w = httptest.NewRecorder()
|
||||
searchReq = httptest.NewRequest(http.MethodGet, "/?user_id="+data.UserId("key")+"&device_id="+devId1, nil)
|
||||
apiEBootstrapHandler(w, searchReq)
|
||||
res = w.Result()
|
||||
defer res.Body.Close()
|
||||
respBody, err = ioutil.ReadAll(res.Body)
|
||||
shared.Check(t, err)
|
||||
shared.Check(t, json.Unmarshal(respBody, &retrievedEntries))
|
||||
if len(retrievedEntries) != 2 {
|
||||
t.Fatalf("Expected to retrieve 2 entries, found %d", len(retrievedEntries))
|
||||
}
|
||||
}
|
||||
|
||||
func TestDumpRequestAndResponse(t *testing.T) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user