package routers

import (
	"encoding/json"
	"log"
	endpoints "monitoring/app/storage/clickhouse/tables"
	"net/http"
)

func AddEndpointMetric (r *http.Request) (interface{}, int) {
	d := json.NewDecoder(r.Body)
	body := endpoints.EndpointMetric{}
	err := d.Decode(&body)
	if err != nil {
		return nil, http.StatusBadRequest
	}

	err = endpoints.AddEndpointMetric(body)
	if err != nil {
		log.Printf(err.Error())
		return nil, http.StatusInternalServerError
	}

	return nil, http.StatusAccepted
}