added manager, driver, order, route, vehicle, warehouse endpoints,models and migrations.
This commit is contained in:
File diff suppressed because it is too large
Load Diff
1272
internal/api/gen.go
1272
internal/api/gen.go
File diff suppressed because it is too large
Load Diff
13
internal/handler/driver.go
Normal file
13
internal/handler/driver.go
Normal 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) {}
|
||||
11
internal/handler/manager.go
Normal file
11
internal/handler/manager.go
Normal 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
17
internal/handler/order.go
Normal 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
11
internal/handler/route.go
Normal 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) {}
|
||||
@@ -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")
|
||||
|
||||
13
internal/handler/vehicle.go
Normal file
13
internal/handler/vehicle.go
Normal 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) {}
|
||||
13
internal/handler/warehouse.go
Normal file
13
internal/handler/warehouse.go
Normal 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
18
internal/models/driver.go
Normal 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
|
||||
}
|
||||
10
internal/models/manager.go
Normal file
10
internal/models/manager.go
Normal 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
25
internal/models/order.go
Normal 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
33
internal/models/route.go
Normal 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
|
||||
}
|
||||
15
internal/models/vehicle.go
Normal file
15
internal/models/vehicle.go
Normal 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"`
|
||||
}
|
||||
19
internal/models/warehouse.go
Normal file
19
internal/models/warehouse.go
Normal 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"`
|
||||
}
|
||||
Reference in New Issue
Block a user