added manager, driver, order, route, vehicle, warehouse endpoints,models and migrations.

This commit is contained in:
2026-03-23 18:28:01 +05:00
parent f710cda3f3
commit 6e8750a566
22 changed files with 2463 additions and 111 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,13 @@
package handler
import "net/http"
func (s *Server) ListDrivers(w http.ResponseWriter, r *http.Request) {}
func (s *Server) CreateDriver(w http.ResponseWriter, r *http.Request) {}
func (s *Server) GetDriver(w http.ResponseWriter, r *http.Request, slug string) {}
func (s *Server) UpdateDriver(w http.ResponseWriter, r *http.Request, slug string) {}
func (s *Server) DeleteDriver(w http.ResponseWriter, r *http.Request, slug string) {}

View File

@@ -0,0 +1,11 @@
package handler
import "net/http"
func (s *Server) ListManagers(w http.ResponseWriter, r *http.Request) {}
func (s *Server) CreateManager(w http.ResponseWriter, r *http.Request) {}
func (s *Server) GetManager(w http.ResponseWriter, r *http.Request, slug string) {}
func (s *Server) DeleteManager(w http.ResponseWriter, r *http.Request, slug string) {}

17
internal/handler/order.go Normal file
View File

@@ -0,0 +1,17 @@
package handler
import (
"net/http"
openapi_types "github.com/oapi-codegen/runtime/types"
)
func (s *Server) ListOrders(w http.ResponseWriter, r *http.Request) {}
func (s *Server) CreateOrder(w http.ResponseWriter, r *http.Request) {}
func (s *Server) GetOrder(w http.ResponseWriter, r *http.Request, id openapi_types.UUID) {}
func (s *Server) CancelOrder(w http.ResponseWriter, r *http.Request, id openapi_types.UUID) {}
func (s *Server) UpdateOrderStatus(w http.ResponseWriter, r *http.Request, id openapi_types.UUID) {}

11
internal/handler/route.go Normal file
View File

@@ -0,0 +1,11 @@
package handler
import (
"net/http"
openapi_types "github.com/oapi-codegen/runtime/types"
)
func (s *Server) GetRoute(w http.ResponseWriter, r *http.Request, id openapi_types.UUID) {}
func (s *Server) RouteWebSocket(w http.ResponseWriter, r *http.Request, id openapi_types.UUID) {}

View File

@@ -47,7 +47,7 @@ func (s *Server) AuthLogin(w http.ResponseWriter, r *http.Request) {
}
if err := bcrypt.CompareHashAndPassword([]byte(user.PasswordHash), []byte(req.Password)); err != nil {
slog.WarnContext(ctx, "Failed login to account with", slog.String("email:", string(req.Email)), slog.String("password from request", req.Password))
slog.WarnContext(ctx, "Failed login to account with", slog.String("email:", string(req.Email)))
s.JSON(w, r, http.StatusBadRequest, "Неверный пароль", "error")
return
}
@@ -207,7 +207,7 @@ func (s *Server) DeleteMe(w http.ResponseWriter, r *http.Request) {
}
jwt := r.Header.Get("Authorization")
tokenKey := "access_token" + jwt
tokenKey := "access_token:" + jwt
if err := s.Redis.Del(ctx, tokenKey).Err(); err != nil {
slog.ErrorContext(ctx, "Error while deleting access token from redis", slog.String("token", jwt))
s.JSON(w, r, http.StatusInternalServerError, "Internal server error", "error")

View File

@@ -0,0 +1,13 @@
package handler
import "net/http"
func (s *Server) ListVehicles(w http.ResponseWriter, r *http.Request) {}
func (s *Server) CreateVehicle(w http.ResponseWriter, r *http.Request) {}
func (s *Server) GetVehicle(w http.ResponseWriter, r *http.Request, slug string) {}
func (s *Server) UpdateVehicle(w http.ResponseWriter, r *http.Request, slug string) {}
func (s *Server) DeleteVehicle(w http.ResponseWriter, r *http.Request, slug string) {}

View File

@@ -0,0 +1,13 @@
package handler
import "net/http"
func (s *Server) ListWarehouses(w http.ResponseWriter, r *http.Request) {}
func (s *Server) CreateWarehouse(w http.ResponseWriter, r *http.Request) {}
func (s *Server) GetWarehouse(w http.ResponseWriter, r *http.Request, slug string) {}
func (s *Server) UpdateWarehouse(w http.ResponseWriter, r *http.Request, slug string) {}
func (s *Server) DeleteWarehouse(w http.ResponseWriter, r *http.Request, slug string) {}

18
internal/models/driver.go Normal file
View File

@@ -0,0 +1,18 @@
package models
import (
"time"
"github.com/google/uuid"
)
type Driver struct {
ID uuid.UUID `db:"id"`
UserID uuid.UUID `db:"user_id"`
VehicleID *uuid.UUID `db:"vehicle_id"`
LicenseNumber string `db:"license_number"`
LicenseExpiry time.Time `db:"license_expiry"`
Rating float64 `db:"rating"`
Slug string `db:"slug"`
Status string `db:"status"` // available, on_route, off_duty
}

View File

@@ -0,0 +1,10 @@
package models
import "github.com/google/uuid"
type Manager struct {
ID uuid.UUID `db:"id"`
UserID uuid.UUID `db:"user_id"`
WarehouseID *uuid.UUID `db:"warehouse_id"`
Slug string `db:"slug"`
}

25
internal/models/order.go Normal file
View File

@@ -0,0 +1,25 @@
package models
import (
"time"
"github.com/google/uuid"
)
type Order struct {
ID uuid.UUID `db:"id"`
CreatedByID *uuid.UUID `db:"created_by_id"`
DriverID *uuid.UUID `db:"driver_id"`
ManagerID *uuid.UUID `db:"manager_id"`
OriginWarehouseID *uuid.UUID `db:"origin_warehouse_id"`
OriginAddress string `db:"origin_address"`
DestinationAddress string `db:"destination_address"`
CargoDescription string `db:"cargo_description"`
WeightKg float64 `db:"weight_kg"`
VolumeM3 float64 `db:"volume_m3"`
Status string `db:"status"` // pending, assigned, in_transit, delivered, cancelled
TotalPrice float64 `db:"total_price"`
CreatedAt time.Time `db:"created_at"`
AssignedAt *time.Time `db:"assigned_at"`
DeliveredAt *time.Time `db:"delivered_at"`
}

33
internal/models/route.go Normal file
View File

@@ -0,0 +1,33 @@
package models
import (
"encoding/json"
"time"
"github.com/google/uuid"
)
// Coordinate represents a [longitude, latitude] pair — ORS array format.
type Coordinate [2]float64
type Route struct {
ID uuid.UUID `db:"id"`
OrderID uuid.UUID `db:"order_id"`
DriverID *uuid.UUID `db:"driver_id"`
Coordinates json.RawMessage `db:"coordinates"` // JSONB: [][2]float64
CurrentIndex int `db:"current_index"`
StartedAt *time.Time `db:"started_at"`
FinishedAt *time.Time `db:"finished_at"`
DistanceKm float64 `db:"distance_km"`
DurationSec int `db:"duration_sec"`
Status string `db:"status"` // pending, active, finished
}
// ParseCoordinates unmarshals the raw JSONB coordinates into a typed slice.
func (r *Route) ParseCoordinates() ([]Coordinate, error) {
var coords []Coordinate
if err := json.Unmarshal(r.Coordinates, &coords); err != nil {
return nil, err
}
return coords, nil
}

View File

@@ -0,0 +1,15 @@
package models
import "github.com/google/uuid"
type Vehicle struct {
ID uuid.UUID `db:"id"`
PlateNumber string `db:"plate_number"`
Brand string `db:"brand"`
Model string `db:"model"`
Year int `db:"year"`
CapacityKg float64 `db:"capacity_kg"`
CapacityM3 float64 `db:"capacity_m3"`
Status string `db:"status"` // available, in_transit, maintenance
Slug string `db:"slug"`
}

View File

@@ -0,0 +1,19 @@
package models
import (
"time"
"github.com/google/uuid"
)
type Warehouse struct {
ID uuid.UUID `db:"id"`
Slug string `db:"slug"`
Name string `db:"name"`
Address string `db:"address"`
City string `db:"city"`
Latitude float64 `db:"latitude"`
Longitude float64 `db:"longitude"`
Status string `db:"status"` // active, inactive
CreatedAt time.Time `db:"created_at"`
}