Files
DocNest/backend/internal/models/version.go
M1ngdaXie c84cbafb2c Refactor and improve code consistency across multiple files
- Enhanced SQL queries in `session.go` and `share.go` for clarity and consistency.
- Updated comments for better understanding and maintenance.
- Ensured consistent error handling and return statements across various methods.
2026-02-04 22:01:47 -08:00

45 lines
1.5 KiB
Go

package models
import (
"time"
"github.com/google/uuid"
)
// DocumentVersion represents a snapshot of a document at a point in time
type DocumentVersion struct {
ID uuid.UUID `json:"id"`
DocumentID uuid.UUID `json:"document_id"`
YjsSnapshot []byte `json:"-"` // Omit from JSON (binary)
TextPreview *string `json:"text_preview"` // Full plain text
VersionNumber int `json:"version_number"`
CreatedBy *uuid.UUID `json:"created_by"`
VersionLabel *string `json:"version_label"`
IsAutoGenerated bool `json:"is_auto_generated"`
CreatedAt time.Time `json:"created_at"`
}
// DocumentVersionWithAuthor includes author information
type DocumentVersionWithAuthor struct {
DocumentVersion
Author *User `json:"author,omitempty"` // Nullable if user deleted
}
// CreateVersionRequest is the API request for manual snapshots
type CreateVersionRequest struct {
VersionLabel *string `json:"version_label"` // Optional user label
TextPreview *string `json:"text_preview"` // Frontend-generated full text
// YjsSnapshot sent as multipart file, not JSON
}
// RestoreVersionRequest specifies which version to restore
type RestoreVersionRequest struct {
VersionID uuid.UUID `json:"version_id" binding:"required"`
}
// VersionListResponse for listing versions
type VersionListResponse struct {
Versions []DocumentVersionWithAuthor `json:"versions"`
Total int `json:"total"`
}