Updating API
This commit is contained in:
parent
f041f0443e
commit
91c206cd96
@ -51,7 +51,7 @@ func runMetrics() {
|
||||
|
||||
data, err := json.Marshal(totalJson)
|
||||
if err != nil {
|
||||
log.Fatalf("error marshaling combined activity: %v\n", err)
|
||||
log.Fatalf("error marshaling combined activity 1: %v\n", err)
|
||||
}
|
||||
|
||||
metricsText = string(data)
|
||||
@ -176,15 +176,15 @@ func getSearch(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
if exists_search && searchKey != "" {
|
||||
if offsetKey == -1 {
|
||||
rows, err = pool.Query(context.Background(), "SELECT activities.id, activities.document, actors.document FROM activities as activities INNER JOIN actors as actors ON activities.document->>'actor' = actors.document->>'id' WHERE activities.normalized_tsvector @@ plainto_tsquery($1) ORDER BY activities.id DESC LIMIT 10", searchKey)
|
||||
rows, err = pool.Query(context.Background(), "SELECT activities.id, activities.document, actors.document, activities.instance FROM activities as activities INNER JOIN actors as actors ON activities.document->>'actor' = actors.document->>'id' WHERE activities.normalized_tsvector @@ plainto_tsquery($1) ORDER BY activities.id DESC LIMIT 10", searchKey)
|
||||
} else {
|
||||
rows, err = pool.Query(context.Background(), "SELECT activities.id, activities.document, actors.document FROM activities as activities INNER JOIN actors as actors ON activities.document->>'actor' = actors.document->>'id' WHERE activities.normalized_tsvector @@ plainto_tsquery($1) AND activities.id < $2 ORDER BY activities.id DESC LIMIT 10", searchKey, offsetKey)
|
||||
rows, err = pool.Query(context.Background(), "SELECT activities.id, activities.document, actors.document, activities.instance, FROM activities as activities INNER JOIN actors as actors ON activities.document->>'actor' = actors.document->>'id' WHERE activities.normalized_tsvector @@ plainto_tsquery($1) AND activities.id < $2 ORDER BY activities.id DESC LIMIT 10", searchKey, offsetKey)
|
||||
}
|
||||
} else {
|
||||
if offsetKey == -1 {
|
||||
rows, err = pool.Query(context.Background(), "SELECT activities.id, activities.document, actors.document FROM activities as activities INNER JOIN actors as actors ON activities.document->>'actor' = actors.document->>'id' ORDER BY activities.id DESC LIMIT 10")
|
||||
rows, err = pool.Query(context.Background(), "SELECT activities.id, activities.document, actors.document, activities.instance FROM activities as activities INNER JOIN actors as actors ON activities.document->>'actor' = actors.document->>'id' ORDER BY activities.id DESC LIMIT 10")
|
||||
} else {
|
||||
rows, err = pool.Query(context.Background(), "SELECT activities.id, activities.document, actors.document FROM activities as activities INNER JOIN actors as actors ON activities.document->>'actor' = actors.document->>'id' AND activities.id < $1 ORDER BY activities.id DESC LIMIT 10", offsetKey)
|
||||
rows, err = pool.Query(context.Background(), "SELECT activities.id, activities.document, actors.document, activities.instance FROM activities as activities INNER JOIN actors as actors ON activities.document->>'actor' = actors.document->>'id' AND activities.id < $1 ORDER BY activities.id DESC LIMIT 10", offsetKey)
|
||||
}
|
||||
}
|
||||
|
||||
@ -200,9 +200,10 @@ func getSearch(w http.ResponseWriter, r *http.Request) {
|
||||
var id int
|
||||
var activityRaw string
|
||||
var actorRaw string
|
||||
var instance string
|
||||
var activityJson map[string]json.RawMessage
|
||||
|
||||
err = rows.Scan(&id, &activityRaw, &actorRaw)
|
||||
err = rows.Scan(&id, &activityRaw, &actorRaw, &instance)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@ -217,6 +218,14 @@ func getSearch(w http.ResponseWriter, r *http.Request) {
|
||||
earliestid = id
|
||||
}
|
||||
|
||||
// Add the instance string
|
||||
rawInstance, err := json.Marshal(instance)
|
||||
if err != nil {
|
||||
fmt.Println("Error marshaling instance string:", err)
|
||||
return
|
||||
}
|
||||
activityJson["instance"] = json.RawMessage(rawInstance)
|
||||
|
||||
activityJson["actor"] = json.RawMessage(actorRaw)
|
||||
activitiesJson = append(activitiesJson, activityJson)
|
||||
}
|
||||
@ -230,7 +239,7 @@ func getSearch(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
data, err := json.Marshal(totalJson)
|
||||
if err != nil {
|
||||
log.Fatalf("error marshaling combined activity: %v\n", err)
|
||||
log.Fatalf("error marshaling combined activity 2: %v\n", err)
|
||||
}
|
||||
fmt.Fprintf(w, "%s", data)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user