40 lines
939 B
Go
40 lines
939 B
Go
package client
|
|
|
|
import (
|
|
"net/http"
|
|
"strconv"
|
|
|
|
"git.cliffbreak.de/haveachin/go-tsviewer/response"
|
|
"github.com/go-chi/chi"
|
|
)
|
|
|
|
func ClientHandler(s Service) http.HandlerFunc {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
response.Handler(w, response.HandlerFunc(func() (int, error) {
|
|
id, err := strconv.ParseUint(chi.URLParam(r, "id"), 10, 64)
|
|
if err != nil {
|
|
return http.StatusBadRequest, err
|
|
}
|
|
|
|
c, err := s.Client(int(id))
|
|
if err != nil {
|
|
return http.StatusNotFound, err
|
|
}
|
|
|
|
return response.New(c, r).Send(w, http.StatusOK)
|
|
}))
|
|
})
|
|
}
|
|
|
|
func ClientsHandler(s Service) http.HandlerFunc {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
response.Handler(w, response.HandlerFunc(func() (int, error) {
|
|
cc, err := s.Clients()
|
|
if err != nil {
|
|
return http.StatusBadRequest, err
|
|
}
|
|
|
|
return response.New(cc, r).Send(w, http.StatusOK)
|
|
}))
|
|
})
|
|
}
|