Files
Mini-ERP-app/core-service/internal/models/models.go
Andrey Epifantsev cce7622ae1 fix: исправлена регистрация - добавлена поддержка JSON полей
- Исправлена конвертация models.JSON в PostgreSQL
- Добавлено детальное логирование в AuthService
- Обновлены структуры LoginResponse с UserResponse и OrganizationResponse
- Исправлены методы Create/GetByID/Update в OrganizationRepository
- Протестирована полная регистрация и аутентификация

Регистрация и login работают корректно
2025-08-27 15:03:10 +04:00

142 lines
5.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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"`
}
// UserResponse ответ с информацией о пользователе
type UserResponse struct {
ID uuid.UUID `json:"id"`
Email string `json:"email"`
Role string `json:"role"`
}
// OrganizationResponse ответ с информацией об организации
type OrganizationResponse struct {
ID uuid.UUID `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
}
// LoginResponse ответ на аутентификацию
type LoginResponse struct {
Token string `json:"token"`
User UserResponse `json:"user"`
Organization OrganizationResponse `json:"organization"`
}
// 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"`
}