basic online
This commit is contained in:
33
internal/handler/actuals.go
Normal file
33
internal/handler/actuals.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"Engine/internal/database"
|
||||
"Engine/internal/model"
|
||||
)
|
||||
|
||||
type ActualsHandler struct {
|
||||
repo *database.ActualsRepo
|
||||
}
|
||||
|
||||
func NewActualsHandler(repo *database.ActualsRepo) *ActualsHandler {
|
||||
return &ActualsHandler{repo: repo}
|
||||
}
|
||||
|
||||
func (h *ActualsHandler) Ingest(w http.ResponseWriter, r *http.Request) {
|
||||
var req model.IngestActualsRequest
|
||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
||||
writeError(w, http.StatusBadRequest, "invalid request body")
|
||||
return
|
||||
}
|
||||
|
||||
actual, err := h.repo.Ingest(r.Context(), req)
|
||||
if err != nil {
|
||||
writeError(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
writeJSON(w, http.StatusCreated, actual)
|
||||
}
|
||||
Reference in New Issue
Block a user