Files
seadoc/models/version.go
Vladimir V Maksimov b2218dd198 char -> uuid
2025-11-08 12:43:30 +03:00

35 lines
1.6 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 (
"encoding/json"
"time"
"github.com/google/uuid"
)
// Version версия документа
// @Description Version хранит либо патч изменений (Patch), либо полный снимок состояния (Snapshot).
// @Description Если IsSnapshot=true — Snapshot содержит полное состояние документа, а Patch = null.
// @Description Если IsSnapshot=false — Patch содержит JSON Patch относительно предыдущей версии.
// swagger:model Version
type Version struct {
ID uuid.UUID `json:"id" gorm:"type:uuid;default:gen_random_uuid();primaryKey" example:"550e8400-e29b-41d4-a716-446655440000"`
DocumentID uuid.UUID `json:"document_id" gorm:"type:uuid;index" example:"550e8400-e29b-41d4-a716-446655440000"`
Document *Document `json:"-" gorm:"foreignKey:DocumentID;references:ID;constraint:OnDelete:CASCADE,OnUpdate:CASCADE;"`
ParentID *uuid.UUID `json:"parent_id,omitempty" gorm:"type:uuid;" example:"null"`
IsSnapshot bool `json:"is_snapshot" example:"false"`
// JSON Patch или nil, если Snapshot
Patch json.RawMessage `json:"patch,omitempty" gorm:"type:json" example:"[{\"op\":\"replace\",\"path\":\"/name\",\"value\":\"new name\"}]"`
// Полный JSON, если IsSnapshot = true
Snapshot json.RawMessage `json:"snapshot,omitempty" gorm:"type:json" example:"{\"field\": \"value\"}"`
CreatedAt time.Time `json:"created_at" example:"2025-01-02T15:04:05Z"`
}
func (s *Version) TableName() (res string) {
res = "version"
return
}