Refactor common.go to add soft delete and audit functionality with appropriate struct definitions

This commit is contained in:
Habib Fatkhul Rohman 2025-10-15 21:14:09 +07:00
parent d1f0d2000e
commit 3497f4e540
1 changed files with 33 additions and 0 deletions

View File

@ -2,6 +2,9 @@ package entities
import (
"time"
"github.com/google/uuid"
"gorm.io/gorm"
)
type Timestamp struct {
@ -9,7 +12,37 @@ type Timestamp struct {
UpdatedAt time.Time `gorm:"type:timestamp with time zone" json:"updated_at"`
}
// SoftDelete menyediakan soft delete functionality
type SoftDelete struct {
DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at,omitempty"`
}
// TimestampWithSoftDelete menggabungkan timestamp dan soft delete
type TimestampWithSoftDelete struct {
Timestamp
SoftDelete
}
type Authorization struct {
Token string `json:"token" binding:"required"`
Role string `json:"role" binding:"required,oneof=user admin"`
}
// Audit menyediakan audit trail functionality
type Audit struct {
CreatedBy uuid.UUID `gorm:"type:uuid;not null" json:"created_by"`
UpdatedBy uuid.UUID `gorm:"type:uuid;not null" json:"updated_by"`
}
// TimestampWithAudit menggabungkan timestamp dan audit
type TimestampWithAudit struct {
Timestamp
Audit
}
// FullAuditTrail menggabungkan timestamp, audit, dan soft delete
type FullAuditTrail struct {
Timestamp
Audit
SoftDelete
}