2019-01-15 00:46:39 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"strconv"
|
|
|
|
|
2019-01-17 00:35:51 +00:00
|
|
|
"git.cliffbreak.de/Cliffbreak/tsviewer/response"
|
2019-01-15 00:46:39 +00:00
|
|
|
"github.com/go-chi/chi"
|
|
|
|
)
|
|
|
|
|
2019-01-16 21:01:48 +00:00
|
|
|
func ClientAPIHandler(s Service) http.HandlerFunc {
|
2019-01-15 00:46:39 +00:00
|
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
2019-01-17 00:35:51 +00:00
|
|
|
response.Handler(w, r, response.HandlerFunc(func() (int, error) {
|
2019-01-15 00:46:39 +00:00
|
|
|
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)
|
|
|
|
}))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-01-16 21:01:48 +00:00
|
|
|
func ClientsAPIHandler(s Service) http.HandlerFunc {
|
2019-01-15 00:46:39 +00:00
|
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
2019-01-17 00:35:51 +00:00
|
|
|
response.Handler(w, r, response.HandlerFunc(func() (int, error) {
|
2019-01-15 00:46:39 +00:00
|
|
|
cc, err := s.Clients()
|
|
|
|
if err != nil {
|
|
|
|
return http.StatusBadRequest, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return response.New(cc, r).Send(w, http.StatusOK)
|
|
|
|
}))
|
|
|
|
})
|
|
|
|
}
|