commit inicial do projeto
This commit is contained in:
31
internal/api/block_handlers.go
Normal file
31
internal/api/block_handlers.go
Normal file
@ -0,0 +1,31 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
func (h *Handler) ListBlocks(w http.ResponseWriter, r *http.Request) {
|
||||
blocks, err := h.Store.ListBlocks()
|
||||
if err != nil {
|
||||
WriteError(w, http.StatusInternalServerError, "Erro ao listar blocos")
|
||||
return
|
||||
}
|
||||
WriteJSON(w, blocks)
|
||||
}
|
||||
|
||||
func (h *Handler) GetBlockByHeight(w http.ResponseWriter, r *http.Request) {
|
||||
heightStr := mux.Vars(r)["height"]
|
||||
height, err := strconv.Atoi(heightStr)
|
||||
if err != nil {
|
||||
WriteError(w, http.StatusBadRequest, "Altura inválida")
|
||||
return
|
||||
}
|
||||
block, err := h.Store.LoadBlock(height)
|
||||
if err != nil {
|
||||
WriteError(w, http.StatusNotFound, "Bloco não encontrado")
|
||||
return
|
||||
}
|
||||
WriteJSON(w, block)
|
||||
}
|
||||
Reference in New Issue
Block a user