workshop/internal/controllers/vehicleController.go
Dmitry Sirotkin 2534bd9e7f
Some checks failed
Deploy to Server (Docker) / deploy (push) Failing after 1m0s
1 +
2 +-
3
4
5
2025-03-25 21:30:30 +03:00

35 lines
782 B
Go

package controllers
import (
"gocommunity.ru/workshop/internal/models"
u "gocommunity.ru/workshop/internal/utils"
"encoding/json"
"net/http"
)
var CreateVehicle = func(w http.ResponseWriter, r *http.Request) {
vehicle := &models.Vehicle{}
err := json.NewDecoder(r.Body).Decode(vehicle)
if err != nil {
u.Respond(w, u.Message(false, "Invalid request!"))
return
}
resp := vehicle.CreateVehicle()
u.Respond(w, resp)
}
var GetvehiclesInService = func(w http.ResponseWriter, r *http.Request) {
VehicleId := r.Context().Value("id").(uint)
vehicle := &models.Vehicle{}
err := json.NewDecoder(r.Body).Decode(vehicle)
if err != nil {
u.Respond(w, u.Message(false, "Error!"))
return
}
vehicle.ID = VehicleId
resp := vehicle.CreateVehicle()
u.Respond(w, resp)
}