queues-go/app/routers/finish.go
Egor Matveev c2659fb49c initial
2024-12-31 00:53:40 +03:00

30 lines
516 B
Go

package routers
import (
"encoding/json"
"net/http"
tasks "queues-go/app/storage/mongo/collections"
)
type FinishRequestBody struct {
Id string `json:"id"`
}
func Finish(w http.ResponseWriter, r *http.Request) {
d := json.NewDecoder(r.Body)
body := FinishRequestBody{}
err := d.Decode(&body)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
return
}
err = tasks.Finish(body.Id)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusAccepted)
}