new file: main_dc/yalarba/api_es/internal/models/authentication.go

new file:   main_dc/yalarba/api_es/internal/models/filter.go
	new file:   main_dc/yalarba/api_es/internal/models/object.go
	deleted:    main_dc/yalarba/api_es/internal/models/rest_object.go
	new file:   main_dc/yalarba/api_es/internal/models/review.go
	modified:   main_dc/yalarba/api_es/internal/models/user.go
add models into es system
This commit is contained in:
2025-11-11 02:25:22 +05:00
parent 2dbf2c557e
commit ea9540dc73
6 changed files with 271 additions and 46 deletions
@@ -0,0 +1,121 @@
package models
import (
"gorm.io/gorm"
"time"
)
type ObjectType string
const (
ObjectTypeHotel ObjectType = "hotel"
ObjectTypeSanatorium ObjectType = "sanatorium"
ObjectTypeGuestHouse ObjectType = "guest_house"
ObjectTypeTour ObjectType = "tour"
ObjectTypeRestaurant ObjectType = "restaurant"
ObjectTypeMuseum ObjectType = "museum"
ObjectTypeLandmark ObjectType = "landmark"
ObjectTypeEvent ObjectType = "event"
ObjectTypeRoute ObjectType = "route"
)
type ObjectStatus string
const (
ObjectStatusDraft ObjectStatus = "draft"
ObjectStatusModeration ObjectStatus = "moderation"
ObjectStatusActive ObjectStatus = "active"
ObjectStatusInactive ObjectStatus = "inactive"
ObjectStatusRejected ObjectStatus = "rejected"
)
type Object struct {
ID uint `gorm:"primaryKey" json:"id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
// Основная информация
Title string `gorm:"not null" json:"title"`
Type ObjectType `gorm:"not null" json:"type"`
Description string `gorm:"type:text" json:"description"`
// Локация
City string `gorm:"not null" json:"city"`
Address string `json:"address"`
Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"`
// Цена и условия
Price float64 `gorm:"default:0" json:"price"`
PricePeriod string `gorm:"default:'per_night'" json:"price_period"` // per_night, per_person, per_tour
// Статус и рейтинг
Status ObjectStatus `gorm:"default:draft" json:"status"`
Rating float64 `gorm:"default:0" json:"rating"`
ReviewCount int `gorm:"default:0" json:"review_count"`
ViewCount int `gorm:"default:0" json:"view_count"`
// Владелец
OwnerID uint `gorm:"not null" json:"owner_id"`
Owner User `gorm:"foreignKey:OwnerID" json:"owner,omitempty"`
// Связи
Images []ObjectImage `gorm:"foreignKey:ObjectID" json:"images"`
Amenities []Amenity `gorm:"many2many:object_amenities;" json:"amenities"`
Reviews []Review `gorm:"foreignKey:ObjectID" json:"-"`
}
// ObjectImage представляет изображения объекта
type ObjectImage struct {
ID uint `gorm:"primaryKey" json:"id"`
ObjectID uint `gorm:"not null" json:"object_id"`
URL string `gorm:"not null" json:"url"`
IsPrimary bool `gorm:"default:false" json:"is_primary"`
Order int `gorm:"default:0" json:"order"`
CreatedAt time.Time `json:"created_at"`
}
// Amenity представляет удобства объекта
type Amenity struct {
ID uint `gorm:"primaryKey" json:"id"`
Name string `gorm:"uniqueIndex;not null" json:"name"`
Category string `json:"category"` // basic, comfort, safety, entertainment, etc.
Icon string `json:"icon"` // иконка для фронтенда
Description string `json:"description"`
}
// ObjectAmenity связь многие-ко-многим между Object и Amenity
type ObjectAmenity struct {
ObjectID uint `gorm:"primaryKey" json:"object_id"`
AmenityID uint `gorm:"primaryKey" json:"amenity_id"`
}
// ObjectCreateRequest - запрос на создание объекта
type ObjectCreateRequest struct {
Title string `json:"title" binding:"required"`
Type ObjectType `json:"type" binding:"required"`
Description string `json:"description" binding:"required"`
City string `json:"city" binding:"required"`
Address string `json:"address"`
Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"`
Price float64 `json:"price"`
PricePeriod string `json:"price_period"`
AmenityIDs []uint `json:"amenity_ids"`
}
// ObjectUpdateRequest - запрос на обновление объекта
type ObjectUpdateRequest struct {
Title string `json:"title"`
Type ObjectType `json:"type"`
Description string `json:"description"`
City string `json:"city"`
Address string `json:"address"`
Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"`
Price float64 `json:"price"`
PricePeriod string `json:"price_period"`
Status ObjectStatus `json:"status"`
AmenityIDs []uint `json:"amenity_ids"`
}