add ability to update existing entries
This commit is contained in:
parent
8b70804c6e
commit
c041c7c179
@ -83,10 +83,58 @@ func AddEntry(w http.ResponseWriter, r *http.Request) {
|
||||
json.NewEncoder(w).Encode(entry)
|
||||
}
|
||||
|
||||
// UpdateEntries handles requests to /etries/update
|
||||
func UpdateEntries(w http.ResponseWriter, r *http.Request) {
|
||||
var params db.UpdateEntryParams
|
||||
|
||||
err := json.NewDecoder(r.Body).Decode(¶ms)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
user, err := getUser(r)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
params.UserID = user.UserID
|
||||
|
||||
entry, err := base.UpdateEntry(ctx, params)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
json.NewEncoder(w).Encode(entry)
|
||||
}
|
||||
|
||||
// Entries handles requests to /entries
|
||||
func Entries(w http.ResponseWriter, r *http.Request) {
|
||||
// Print secret message
|
||||
fmt.Fprintln(w, "The cake is a lie!")
|
||||
var params db.GetEntryParams
|
||||
|
||||
err := json.NewDecoder(r.Body).Decode(¶ms)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
user, err := getUser(r)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
params.UserID = user.UserID
|
||||
|
||||
entry, err := base.GetEntry(ctx, params)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
json.NewEncoder(w).Encode(entry)
|
||||
}
|
||||
|
||||
// SimilarEntries are entries that match some text
|
||||
|
@ -75,8 +75,7 @@ func main() {
|
||||
http.HandleFunc("/entries/list", checkAuth(logger(ListEntries)))
|
||||
http.HandleFunc("/entries/delete", checkAuth(logger(Entries)))
|
||||
http.HandleFunc("/entries/get", checkAuth(logger(Entries)))
|
||||
http.HandleFunc("/entries/update", checkAuth(logger(Entries)))
|
||||
http.HandleFunc("/entries/update", checkAuth(logger(UpdateEntries)))
|
||||
http.HandleFunc("/entries/similar", checkAuth(logger(SimilarEntries)))
|
||||
|
||||
log.Fatalln(http.ListenAndServe(":8080", nil))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user