- Удалены зависимости: grpc, redis, prometheus - Упрощена конфигурация (Server, Database, JWT) - Создан логгер на основе logrus - Добавлено подключение к PostgreSQL - Создана миграция с базовыми таблицами - Обновлены модели с валидацией - Создан базовый API сервер с health check - Добавлен .env.example Готово для этапа 2 - Аутентификация
128 lines
4.7 KiB
Go
128 lines
4.7 KiB
Go
package models
|
||
|
||
import (
|
||
"time"
|
||
|
||
"github.com/google/uuid"
|
||
)
|
||
|
||
// Organization представляет организацию/компанию
|
||
type Organization struct {
|
||
ID uuid.UUID `json:"id" db:"id"`
|
||
Name string `json:"name" validate:"required"`
|
||
Type string `json:"type"`
|
||
Settings JSON `json:"settings"`
|
||
CreatedAt time.Time `json:"created_at" db:"created_at"`
|
||
}
|
||
|
||
// User представляет пользователя системы
|
||
type User struct {
|
||
ID uuid.UUID `json:"id" db:"id"`
|
||
OrganizationID uuid.UUID `json:"organization_id" db:"organization_id"`
|
||
Email string `json:"email" validate:"required,email"`
|
||
PasswordHash string `json:"-" db:"password_hash"`
|
||
Role string `json:"role"`
|
||
CreatedAt time.Time `json:"created_at" db:"created_at"`
|
||
}
|
||
|
||
// StorageLocation представляет место хранения
|
||
type StorageLocation struct {
|
||
ID uuid.UUID `json:"id" db:"id"`
|
||
OrganizationID uuid.UUID `json:"organization_id" db:"organization_id"`
|
||
ParentID *uuid.UUID `json:"parent_id,omitempty" db:"parent_id"`
|
||
Name string `json:"name" validate:"required"`
|
||
Address string `json:"address" validate:"required"`
|
||
Type string `json:"type" validate:"required"`
|
||
Coordinates JSON `json:"coordinates"`
|
||
CreatedAt time.Time `json:"created_at" db:"created_at"`
|
||
}
|
||
|
||
// Item представляет товар/материал
|
||
type Item struct {
|
||
ID uuid.UUID `json:"id" db:"id"`
|
||
OrganizationID uuid.UUID `json:"organization_id" db:"organization_id"`
|
||
Name string `json:"name" validate:"required"`
|
||
Description string `json:"description"`
|
||
Category string `json:"category"`
|
||
CreatedAt time.Time `json:"created_at" db:"created_at"`
|
||
}
|
||
|
||
// ItemPlacement представляет размещение товара в месте хранения
|
||
type ItemPlacement struct {
|
||
ID uuid.UUID `json:"id" db:"id"`
|
||
OrganizationID uuid.UUID `json:"organization_id" db:"organization_id"`
|
||
ItemID uuid.UUID `json:"item_id" db:"item_id"`
|
||
LocationID uuid.UUID `json:"location_id" db:"location_id"`
|
||
Quantity int `json:"quantity" validate:"min=1"`
|
||
CreatedAt time.Time `json:"created_at" db:"created_at"`
|
||
}
|
||
|
||
// JSON тип для JSON полей
|
||
type JSON map[string]interface{}
|
||
|
||
// LoginRequest запрос на аутентификацию
|
||
type LoginRequest struct {
|
||
Email string `json:"email" validate:"required,email"`
|
||
Password string `json:"password" validate:"required"`
|
||
}
|
||
|
||
// RegisterRequest запрос на регистрацию
|
||
type RegisterRequest struct {
|
||
OrganizationName string `json:"organization_name" validate:"required"`
|
||
UserEmail string `json:"user_email" validate:"required,email"`
|
||
UserPassword string `json:"user_password" validate:"required,min=8"`
|
||
OrganizationType string `json:"organization_type"`
|
||
}
|
||
|
||
// LoginResponse ответ на аутентификацию
|
||
type LoginResponse struct {
|
||
Token string `json:"token"`
|
||
User User `json:"user"`
|
||
ExpiresAt time.Time `json:"expires_at"`
|
||
}
|
||
|
||
// CreateLocationRequest запрос на создание места хранения
|
||
type CreateLocationRequest struct {
|
||
Name string `json:"name" validate:"required"`
|
||
Address string `json:"address" validate:"required"`
|
||
Type string `json:"type" validate:"required"`
|
||
ParentID *uuid.UUID `json:"parent_id"`
|
||
Coordinates JSON `json:"coordinates"`
|
||
}
|
||
|
||
// CreateItemRequest запрос на создание товара
|
||
type CreateItemRequest struct {
|
||
Name string `json:"name" validate:"required"`
|
||
Description string `json:"description"`
|
||
Category string `json:"category"`
|
||
}
|
||
|
||
// PlaceItemRequest запрос на размещение товара
|
||
type PlaceItemRequest struct {
|
||
ItemID uuid.UUID `json:"item_id" validate:"required"`
|
||
LocationID uuid.UUID `json:"location_id" validate:"required"`
|
||
Quantity int `json:"quantity" validate:"required,min=1"`
|
||
}
|
||
|
||
// SearchRequest запрос на поиск
|
||
type SearchRequest struct {
|
||
Query string `form:"q"`
|
||
Category string `form:"category"`
|
||
Address string `form:"address"`
|
||
Page int `form:"page,default=1"`
|
||
PageSize int `form:"page_size,default=20"`
|
||
}
|
||
|
||
// SearchResponse результат поиска
|
||
type SearchResponse struct {
|
||
Items []ItemWithLocation `json:"items"`
|
||
TotalCount int `json:"total_count"`
|
||
}
|
||
|
||
// ItemWithLocation товар с информацией о месте размещения
|
||
type ItemWithLocation struct {
|
||
Item Item `json:"item"`
|
||
Location StorageLocation `json:"location"`
|
||
Quantity int `json:"quantity"`
|
||
}
|