mirror of
https://github.com/IS1DI/x0gp.git
synced 2026-07-16 20:47:55 +00:00
removed device_id from all entities except car. Replaced with car_id . Car -> device_id
This commit is contained in:
@@ -283,7 +283,7 @@ func driversListHandler(svc *drivers.Service) http.HandlerFunc {
|
||||
// @Router /api/drivers/{id} [get]
|
||||
// @Router /api/drivers/{id} [put]
|
||||
// @Router /api/drivers/{id} [delete]
|
||||
// @Router /api/drivers/{id}/device [put]
|
||||
// @Router /api/drivers/{id}/car [put]
|
||||
func driversByIDHandler(svc *drivers.Service, lobbySvc *lobby.Service) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
id := strings.TrimPrefix(r.URL.Path, "/api/drivers/")
|
||||
@@ -291,8 +291,8 @@ func driversByIDHandler(svc *drivers.Service, lobbySvc *lobby.Service) http.Hand
|
||||
writeError(w, http.StatusBadRequest, "bad_request", "missing driver id")
|
||||
return
|
||||
}
|
||||
if strings.HasSuffix(id, "/device") {
|
||||
driverID := strings.TrimSuffix(id, "/device")
|
||||
if strings.HasSuffix(id, "/car") {
|
||||
driverID := strings.TrimSuffix(id, "/car")
|
||||
if driverID == "" {
|
||||
writeError(w, http.StatusBadRequest, "bad_request", "missing driver id")
|
||||
return
|
||||
@@ -303,29 +303,26 @@ func driversByIDHandler(svc *drivers.Service, lobbySvc *lobby.Service) http.Hand
|
||||
return
|
||||
}
|
||||
|
||||
// Read device_id from JSON body or query param
|
||||
var deviceID *int
|
||||
type deviceRequest struct {
|
||||
DeviceID *int `json:"device_id"`
|
||||
// Read car_id from JSON body or query param
|
||||
var carID *string
|
||||
type carRequest struct {
|
||||
CarID *string `json:"car_id"`
|
||||
}
|
||||
var req deviceRequest
|
||||
var req carRequest
|
||||
if r.ContentLength > 0 {
|
||||
if err := json.NewDecoder(r.Body).Decode(&req); err == nil {
|
||||
deviceID = req.DeviceID
|
||||
carID = req.CarID
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback to query parameter if body didn't provide it
|
||||
if deviceID == nil {
|
||||
qVal := r.URL.Query().Get("device_id")
|
||||
if carID == nil {
|
||||
qVal := r.URL.Query().Get("car_id")
|
||||
if qVal != "" {
|
||||
if qVal == "null" {
|
||||
deviceID = nil
|
||||
} else if idInt, err := strconv.Atoi(qVal); err == nil {
|
||||
deviceID = &idInt
|
||||
carID = nil
|
||||
} else {
|
||||
writeError(w, http.StatusBadRequest, "bad_request", "invalid device_id query parameter")
|
||||
return
|
||||
carID = &qVal
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -345,8 +342,8 @@ func driversByIDHandler(svc *drivers.Service, lobbySvc *lobby.Service) http.Hand
|
||||
_, _ = lobbySvc.AddDriver(driverID, drv.Name, "")
|
||||
lobbySvc.SetDriverProfile(driverID, drv.Nickname, drv.AvatarURL, drv.ClanID, "")
|
||||
|
||||
// Select device in lobby (handles constraints and write-through)
|
||||
if err := lobbySvc.SelectDevice(driverID, deviceID); err != nil {
|
||||
// Select car in lobby (handles constraints and write-through)
|
||||
if err := lobbySvc.SelectCar(driverID, carID); err != nil {
|
||||
writeError(w, http.StatusBadRequest, "bad_request", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user