Refactor common.go to add soft delete and audit functionality with appropriate struct definitions
This commit is contained in:
parent
d1f0d2000e
commit
3497f4e540
|
|
@ -2,6 +2,9 @@ package entities
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Timestamp struct {
|
type Timestamp struct {
|
||||||
|
|
@ -9,7 +12,37 @@ type Timestamp struct {
|
||||||
UpdatedAt time.Time `gorm:"type:timestamp with time zone" json:"updated_at"`
|
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 {
|
type Authorization struct {
|
||||||
Token string `json:"token" binding:"required"`
|
Token string `json:"token" binding:"required"`
|
||||||
Role string `json:"role" binding:"required,oneof=user admin"`
|
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
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue