package routers

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

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

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

	return nil, http.StatusAccepted
}
