Add single cake endpoint handler
This commit is contained in:
parent
f552e87a9d
commit
01732b97fc
4 changed files with 56 additions and 0 deletions
|
|
@ -18,6 +18,25 @@ func (h *Server) cakes(r *http.Request) (any, int, error) {
|
|||
return data, http.StatusOK, err
|
||||
}
|
||||
|
||||
func (h *Server) cake(r *http.Request) (any, int, error) {
|
||||
url := strings.Split(r.URL.String(), "/")
|
||||
if len(url) < 3 || url[2] == "" {
|
||||
return store.Cake{}, http.StatusOK, nil
|
||||
}
|
||||
|
||||
id, err := strconv.Atoi(url[2])
|
||||
if err != nil {
|
||||
return nil, http.StatusBadRequest, err
|
||||
}
|
||||
|
||||
data, err := h.s.GetCake(id)
|
||||
if err != nil {
|
||||
return nil, http.StatusNotFound, err
|
||||
}
|
||||
|
||||
return data, http.StatusOK, nil
|
||||
}
|
||||
|
||||
func (h *Server) order(r *http.Request) (any, int, error) {
|
||||
type formData struct {
|
||||
Order store.Order
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue