@@ -0,0 +1,33 @@
|
||||
package vote
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"tomatentum.net/outfit-voting-abi26/internal/database"
|
||||
)
|
||||
|
||||
func GetVoteResultEndpoint(w http.ResponseWriter, r *http.Request) {
|
||||
entries, err := database.GetVotes()
|
||||
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(entries)
|
||||
}
|
||||
|
||||
func GetVoteResultSingleEndoint(w http.ResponseWriter, r *http.Request) {
|
||||
id := r.PathValue("id")
|
||||
entry, err := database.GetVote(id)
|
||||
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(entry)
|
||||
}
|
||||
Reference in New Issue
Block a user