feat: started to make things work
This commit is contained in:
1 parent
9e21732d00
commit
de6480ba4e
8 files changed
+157
-106
No files matched your search
@@ -2,7 +2,6 @@ package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -17,20 +16,15 @@ func registerAPI(mux *http.ServeMux, sqlite *sqliteStore, logger *zap.Logger) {
|
||||
return
|
||||
}
|
||||
|
||||
ids, err := sqlite.listAllPublicIDs(r.Context())
|
||||
summaries, err := sqlite.listAll(r.Context())
|
||||
if err != nil {
|
||||
logger.Error("list flashcards", zap.Error(err))
|
||||
http.Error(w, `{"error":"internal error"}`, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
urls := make([]string, 0, len(ids))
|
||||
for _, id := range ids {
|
||||
urls = append(urls, fmt.Sprintf("/api/v1/flashcards/%d", id))
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(map[string][]string{"flashcards": urls})
|
||||
json.NewEncoder(w).Encode(map[string][]flashcardSummary{"flashcards": summaries})
|
||||
})
|
||||
|
||||
mux.HandleFunc("/api/v1/flashcards/", func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
Reference in new issue
Block a user