89 lines
2.2 KiB
Go
89 lines
2.2 KiB
Go
package api
|
||
|
||
import (
|
||
"net/http"
|
||
"strings"
|
||
|
||
"dana/internal/storage"
|
||
)
|
||
|
||
func (a *API) health(w http.ResponseWriter, r *http.Request) {
|
||
ok(w, map[string]string{"status": "ok"}, nil)
|
||
}
|
||
|
||
func (a *API) services(w http.ResponseWriter, r *http.Request) {
|
||
tree, err := a.store.ServiceTree(r.Context())
|
||
if err != nil {
|
||
handleErr(w, err)
|
||
return
|
||
}
|
||
ok(w, tree, map[string]any{"total": len(tree)})
|
||
}
|
||
|
||
func (a *API) service(w http.ResponseWriter, r *http.Request) {
|
||
path := strings.Trim(r.PathValue("path"), "/")
|
||
if path == "" {
|
||
fail(w, http.StatusBadRequest, "bad_request", "Не указан путь услуги")
|
||
return
|
||
}
|
||
svc, err := a.store.ServiceByPath(r.Context(), path)
|
||
if err != nil {
|
||
handleErr(w, err)
|
||
return
|
||
}
|
||
ok(w, svc, nil)
|
||
}
|
||
|
||
func (a *API) specialties(w http.ResponseWriter, r *http.Request) {
|
||
list, err := a.store.Specialties(r.Context())
|
||
if err != nil {
|
||
handleErr(w, err)
|
||
return
|
||
}
|
||
ok(w, list, map[string]any{"total": len(list)})
|
||
}
|
||
|
||
// doctors: ?specialty=slug&service=path&branch=slug&q=фамилия
|
||
func (a *API) doctors(w http.ResponseWriter, r *http.Request) {
|
||
q := r.URL.Query()
|
||
list, err := a.store.Doctors(r.Context(), storage.DoctorFilter{
|
||
Specialty: q.Get("specialty"),
|
||
Service: q.Get("service"),
|
||
Branch: q.Get("branch"),
|
||
Query: strings.TrimSpace(q.Get("q")),
|
||
})
|
||
if err != nil {
|
||
handleErr(w, err)
|
||
return
|
||
}
|
||
ok(w, list, map[string]any{"total": len(list)})
|
||
}
|
||
|
||
func (a *API) doctor(w http.ResponseWriter, r *http.Request) {
|
||
d, err := a.store.DoctorBySlug(r.Context(), r.PathValue("slug"))
|
||
if err != nil {
|
||
handleErr(w, err)
|
||
return
|
||
}
|
||
ok(w, d, nil)
|
||
}
|
||
|
||
func (a *API) prices(w http.ResponseWriter, r *http.Request) {
|
||
list, err := a.store.PriceList(r.Context(), r.URL.Query().Get("section"))
|
||
if err != nil {
|
||
handleErr(w, err)
|
||
return
|
||
}
|
||
ok(w, list, map[string]any{"total": len(list)})
|
||
}
|
||
|
||
// priceSections — короткий список разделов прайса для меню в шапке.
|
||
func (a *API) priceSections(w http.ResponseWriter, r *http.Request) {
|
||
list, err := a.store.PriceSectionsBrief(r.Context())
|
||
if err != nil {
|
||
handleErr(w, err)
|
||
return
|
||
}
|
||
ok(w, list, map[string]any{"total": len(list)})
|
||
}
|