package routers

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

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

	err = tasks.AddTaskMetric(body)
	if err != nil {
		log.Print(err.Error())
		return nil, http.StatusInternalServerError
	}

	return nil, http.StatusAccepted
}
