add service b
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package meteo
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"pkg"
|
||||
"serviceb/internal/app"
|
||||
)
|
||||
|
||||
type Handler struct {
|
||||
pkg.BaseHandler
|
||||
s *Service
|
||||
}
|
||||
|
||||
func NewHandler(service *Service) *Handler {
|
||||
return &Handler{
|
||||
s: service,
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Handler) GetMeteoData(w http.ResponseWriter, r *http.Request) {
|
||||
locationValue := r.PathValue("city")
|
||||
queryParams := r.URL.Query()
|
||||
|
||||
params := GetMeteoData{
|
||||
Location: locationValue,
|
||||
Date: queryParams.Get("date"),
|
||||
Days: h.ParamToInt(queryParams.Get("days"), 5),
|
||||
Unit: Unit(queryParams.Get("unit")),
|
||||
Agg: Agg(queryParams.Get("agg")),
|
||||
}
|
||||
|
||||
if err := params.Validate(); err != nil {
|
||||
slog.Error("error validating struct", "error", err)
|
||||
h.ToJSON(w, http.StatusBadRequest, app.H{"error": err.Error()})
|
||||
}
|
||||
|
||||
slog.Info("loc value", "value", params)
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user