Add document saved
This commit is contained in:
@@ -7,36 +7,34 @@ import (
|
||||
)
|
||||
|
||||
type ApprovalFlow struct {
|
||||
ID uuid.UUID `gorm:"type:uuid;primary_key;default:gen_random_uuid()" json:"id"`
|
||||
DepartmentID uuid.UUID `gorm:"type:uuid;not null" json:"department_id"`
|
||||
Name string `gorm:"not null" json:"name"`
|
||||
Description *string `json:"description,omitempty"`
|
||||
IsActive bool `gorm:"default:true" json:"is_active"`
|
||||
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
|
||||
ID uuid.UUID `gorm:"type:uuid;primary_key;default:gen_random_uuid()" json:"id"`
|
||||
DepartmentID uuid.UUID `gorm:"type:uuid;not null" json:"department_id"`
|
||||
Name string `gorm:"not null" json:"name"`
|
||||
Description *string `json:"description,omitempty"`
|
||||
IsActive bool `gorm:"default:true" json:"is_active"`
|
||||
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
|
||||
|
||||
// Relations
|
||||
Department *Department `gorm:"foreignKey:DepartmentID" json:"department,omitempty"`
|
||||
Steps []ApprovalFlowStep `gorm:"foreignKey:FlowID" json:"steps,omitempty"`
|
||||
Department *Department `gorm:"foreignKey:DepartmentID" json:"department,omitempty"`
|
||||
Steps []ApprovalFlowStep `gorm:"foreignKey:FlowID" json:"steps,omitempty"`
|
||||
}
|
||||
|
||||
func (ApprovalFlow) TableName() string { return "approval_flows" }
|
||||
|
||||
type ApprovalFlowStep struct {
|
||||
ID uuid.UUID `gorm:"type:uuid;primary_key;default:gen_random_uuid()" json:"id"`
|
||||
FlowID uuid.UUID `gorm:"type:uuid;not null" json:"flow_id"`
|
||||
StepOrder int `gorm:"not null" json:"step_order"`
|
||||
ParallelGroup int `gorm:"default:1" json:"parallel_group"`
|
||||
ApproverRoleID *uuid.UUID `json:"approver_role_id,omitempty"`
|
||||
ApproverUserID *uuid.UUID `json:"approver_user_id,omitempty"`
|
||||
Required bool `gorm:"default:true" json:"required"`
|
||||
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
|
||||
|
||||
// Relations
|
||||
ApprovalFlow *ApprovalFlow `gorm:"foreignKey:FlowID" json:"approval_flow,omitempty"`
|
||||
ApproverRole *Role `gorm:"foreignKey:ApproverRoleID" json:"approver_role,omitempty"`
|
||||
ApproverUser *User `gorm:"foreignKey:ApproverUserID" json:"approver_user,omitempty"`
|
||||
ID uuid.UUID `gorm:"type:uuid;primary_key;default:gen_random_uuid()" json:"id"`
|
||||
FlowID uuid.UUID `gorm:"type:uuid;not null" json:"flow_id"`
|
||||
StepOrder int `gorm:"not null" json:"step_order"`
|
||||
ParallelGroup int `gorm:"default:1" json:"parallel_group"`
|
||||
ApproverRoleID *uuid.UUID `json:"approver_role_id,omitempty"`
|
||||
ApproverUserID *uuid.UUID `json:"approver_user_id,omitempty"`
|
||||
Required bool `gorm:"default:true" json:"required"`
|
||||
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
|
||||
ApprovalFlow *ApprovalFlow `gorm:"foreignKey:FlowID" json:"approval_flow,omitempty"`
|
||||
ApproverRole *Role `gorm:"foreignKey:ApproverRoleID" json:"approver_role,omitempty"`
|
||||
ApproverUser *User `gorm:"foreignKey:ApproverUserID" json:"approver_user,omitempty"`
|
||||
}
|
||||
|
||||
func (ApprovalFlowStep) TableName() string { return "approval_flow_steps" }
|
||||
@@ -65,4 +63,4 @@ type LetterOutgoingApproval struct {
|
||||
Approver *User `gorm:"foreignKey:ApproverID" json:"approver,omitempty"`
|
||||
}
|
||||
|
||||
func (LetterOutgoingApproval) TableName() string { return "letter_outgoing_approvals" }
|
||||
func (LetterOutgoingApproval) TableName() string { return "letter_outgoing_approvals" }
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
package entities
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// DocumentSession represents an OnlyOffice document editing session
|
||||
type DocumentSession struct {
|
||||
ID uuid.UUID `gorm:"type:uuid;primary_key;default:gen_random_uuid()" json:"id"`
|
||||
DocumentID uuid.UUID `gorm:"type:uuid;not null;index" json:"document_id"`
|
||||
DocumentKey string `gorm:"uniqueIndex;not null" json:"document_key"` // OnlyOffice document key
|
||||
UserID uuid.UUID `gorm:"type:uuid;not null" json:"user_id"`
|
||||
Status int `gorm:"not null;default:0" json:"status"` // OnlyOffice status codes
|
||||
IsLocked bool `gorm:"default:false" json:"is_locked"`
|
||||
LockedBy *uuid.UUID `gorm:"type:uuid" json:"locked_by,omitempty"`
|
||||
LockedAt *time.Time `json:"locked_at,omitempty"`
|
||||
LastSavedAt *time.Time `json:"last_saved_at,omitempty"`
|
||||
Version int `gorm:"not null;default:1" json:"version"`
|
||||
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
|
||||
|
||||
// Relations
|
||||
User *User `gorm:"foreignKey:UserID" json:"user,omitempty"`
|
||||
}
|
||||
|
||||
func (DocumentSession) TableName() string {
|
||||
return "document_sessions"
|
||||
}
|
||||
|
||||
func (ds *DocumentSession) BeforeCreate(tx *gorm.DB) error {
|
||||
if ds.ID == uuid.Nil {
|
||||
ds.ID = uuid.New()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DocumentVersion represents a version of a document
|
||||
type DocumentVersion struct {
|
||||
ID uuid.UUID `gorm:"type:uuid;primary_key;default:gen_random_uuid()" json:"id"`
|
||||
DocumentID uuid.UUID `gorm:"type:uuid;not null;index" json:"document_id"`
|
||||
Version int `gorm:"not null" json:"version"`
|
||||
FileURL string `gorm:"not null" json:"file_url"`
|
||||
FileSize int64 `gorm:"not null" json:"file_size"`
|
||||
ChangesURL *string `json:"changes_url,omitempty"`
|
||||
SavedBy uuid.UUID `gorm:"type:uuid;not null" json:"saved_by"`
|
||||
SavedAt time.Time `gorm:"not null" json:"saved_at"`
|
||||
IsActive bool `gorm:"default:false;index" json:"is_active"`
|
||||
Comments *string `json:"comments,omitempty"`
|
||||
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
|
||||
|
||||
// Relations
|
||||
User *User `gorm:"foreignKey:SavedBy" json:"user,omitempty"`
|
||||
}
|
||||
|
||||
func (DocumentVersion) TableName() string {
|
||||
return "document_versions"
|
||||
}
|
||||
|
||||
func (dv *DocumentVersion) BeforeCreate(tx *gorm.DB) error {
|
||||
if dv.ID == uuid.Nil {
|
||||
dv.ID = uuid.New()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DocumentError represents errors during document operations
|
||||
type DocumentError struct {
|
||||
ID uuid.UUID `gorm:"type:uuid;primary_key;default:gen_random_uuid()" json:"id"`
|
||||
DocumentID uuid.UUID `gorm:"type:uuid;not null;index" json:"document_id"`
|
||||
SessionID *uuid.UUID `gorm:"type:uuid" json:"session_id,omitempty"`
|
||||
ErrorType string `gorm:"not null" json:"error_type"`
|
||||
ErrorMsg string `gorm:"not null" json:"error_msg"`
|
||||
Details map[string]interface{} `gorm:"type:jsonb" json:"details,omitempty"`
|
||||
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
|
||||
|
||||
// Relations
|
||||
Session *DocumentSession `gorm:"foreignKey:SessionID" json:"session,omitempty"`
|
||||
}
|
||||
|
||||
func (DocumentError) TableName() string {
|
||||
return "document_errors"
|
||||
}
|
||||
|
||||
func (de *DocumentError) BeforeCreate(tx *gorm.DB) error {
|
||||
if de.ID == uuid.Nil {
|
||||
de.ID = uuid.New()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DocumentMetadata stores document-specific metadata
|
||||
type DocumentMetadata struct {
|
||||
ID uuid.UUID `gorm:"type:uuid;primary_key;default:gen_random_uuid()" json:"id"`
|
||||
DocumentID uuid.UUID `gorm:"type:uuid;uniqueIndex;not null" json:"document_id"`
|
||||
DocumentType string `gorm:"not null" json:"document_type"` // letter_attachment, outgoing_attachment, etc.
|
||||
ReferenceID uuid.UUID `gorm:"type:uuid;not null" json:"reference_id"` // ID of the parent entity (letter, outgoing letter, etc.)
|
||||
FileName string `gorm:"not null" json:"file_name"`
|
||||
FileType string `gorm:"not null" json:"file_type"`
|
||||
FileSize int64 `gorm:"not null" json:"file_size"`
|
||||
MimeType string `json:"mime_type,omitempty"`
|
||||
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
|
||||
}
|
||||
|
||||
func (DocumentMetadata) TableName() string {
|
||||
return "document_metadata"
|
||||
}
|
||||
|
||||
func (dm *DocumentMetadata) BeforeCreate(tx *gorm.DB) error {
|
||||
if dm.ID == uuid.Nil {
|
||||
dm.ID = uuid.New()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -33,28 +33,32 @@ type LetterOutgoing struct {
|
||||
DeletedAt *time.Time `gorm:"index" json:"deleted_at,omitempty"`
|
||||
|
||||
// Relations
|
||||
Priority *Priority `gorm:"foreignKey:PriorityID" json:"priority,omitempty"`
|
||||
ReceiverInstitution *Institution `gorm:"foreignKey:ReceiverInstitutionID" json:"receiver_institution,omitempty"`
|
||||
Creator *User `gorm:"foreignKey:CreatedBy" json:"creator,omitempty"`
|
||||
ApprovalFlow *ApprovalFlow `gorm:"foreignKey:ApprovalFlowID" json:"approval_flow,omitempty"`
|
||||
Recipients []LetterOutgoingRecipient `gorm:"foreignKey:LetterID" json:"recipients,omitempty"`
|
||||
Attachments []LetterOutgoingAttachment `gorm:"foreignKey:LetterID" json:"attachments,omitempty"`
|
||||
Approvals []LetterOutgoingApproval `gorm:"foreignKey:LetterID" json:"approvals,omitempty"`
|
||||
Discussions []LetterOutgoingDiscussion `gorm:"foreignKey:LetterID" json:"discussions,omitempty"`
|
||||
ActivityLogs []LetterOutgoingActivityLog `gorm:"foreignKey:LetterID" json:"activity_logs,omitempty"`
|
||||
Priority *Priority `gorm:"foreignKey:PriorityID" json:"priority,omitempty"`
|
||||
ReceiverInstitution *Institution `gorm:"foreignKey:ReceiverInstitutionID" json:"receiver_institution,omitempty"`
|
||||
Creator *User `gorm:"foreignKey:CreatedBy" json:"creator,omitempty"`
|
||||
ApprovalFlow *ApprovalFlow `gorm:"foreignKey:ApprovalFlowID" json:"approval_flow,omitempty"`
|
||||
Recipients []LetterOutgoingRecipient `gorm:"foreignKey:LetterID" json:"recipients,omitempty"`
|
||||
Attachments []LetterOutgoingAttachment `gorm:"foreignKey:LetterID" json:"attachments,omitempty"`
|
||||
Approvals []LetterOutgoingApproval `gorm:"foreignKey:LetterID" json:"approvals,omitempty"`
|
||||
Discussions []LetterOutgoingDiscussion `gorm:"foreignKey:LetterID" json:"discussions,omitempty"`
|
||||
ActivityLogs []LetterOutgoingActivityLog `gorm:"foreignKey:LetterID" json:"activity_logs,omitempty"`
|
||||
}
|
||||
|
||||
func (LetterOutgoing) TableName() string { return "letters_outgoing" }
|
||||
|
||||
type LetterOutgoingRecipient struct {
|
||||
ID uuid.UUID `gorm:"type:uuid;primary_key;default:gen_random_uuid()" json:"id"`
|
||||
LetterID uuid.UUID `gorm:"type:uuid;not null" json:"letter_id"`
|
||||
RecipientName string `gorm:"not null" json:"recipient_name"`
|
||||
RecipientEmail *string `json:"recipient_email,omitempty"`
|
||||
RecipientPosition *string `json:"recipient_position,omitempty"`
|
||||
RecipientInstitution *string `json:"recipient_institution,omitempty"`
|
||||
IsPrimary bool `gorm:"default:false" json:"is_primary"`
|
||||
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
|
||||
ID uuid.UUID `gorm:"type:uuid;primary_key;default:gen_random_uuid()" json:"id"`
|
||||
LetterID uuid.UUID `gorm:"type:uuid;not null" json:"letter_id"`
|
||||
UserID *uuid.UUID `gorm:"type:uuid" json:"user_id,omitempty"`
|
||||
DepartmentID *uuid.UUID `gorm:"type:uuid" json:"department_id,omitempty"`
|
||||
IsPrimary bool `gorm:"default:false" json:"is_primary"`
|
||||
Status string `gorm:"default:'pending'" json:"status"`
|
||||
ReadAt *time.Time `json:"read_at,omitempty"`
|
||||
Flag *string `json:"flag,omitempty"`
|
||||
IsArchived bool `gorm:"default:false" json:"is_archived"`
|
||||
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
|
||||
User *User `gorm:"foreignKey:UserID" json:"user,omitempty"`
|
||||
Department *Department `gorm:"foreignKey:DepartmentID" json:"department,omitempty"`
|
||||
}
|
||||
|
||||
func (LetterOutgoingRecipient) TableName() string { return "letter_outgoing_recipients" }
|
||||
@@ -102,4 +106,4 @@ type LetterOutgoingDiscussionAttachment struct {
|
||||
|
||||
func (LetterOutgoingDiscussionAttachment) TableName() string {
|
||||
return "letter_outgoing_discussion_attachments"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user