Add letter and user id
This commit is contained in:
@@ -0,0 +1,229 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"eslogad-be/internal/entities"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type ApprovalFlowRepository struct{ db *gorm.DB }
|
||||
|
||||
func NewApprovalFlowRepository(db *gorm.DB) *ApprovalFlowRepository {
|
||||
return &ApprovalFlowRepository{db: db}
|
||||
}
|
||||
|
||||
func (r *ApprovalFlowRepository) Create(ctx context.Context, e *entities.ApprovalFlow) error {
|
||||
db := DBFromContext(ctx, r.db)
|
||||
return db.WithContext(ctx).Create(e).Error
|
||||
}
|
||||
|
||||
func (r *ApprovalFlowRepository) Get(ctx context.Context, id uuid.UUID) (*entities.ApprovalFlow, error) {
|
||||
db := DBFromContext(ctx, r.db)
|
||||
var e entities.ApprovalFlow
|
||||
if err := db.WithContext(ctx).
|
||||
Preload("Department").
|
||||
Preload("Steps", func(db *gorm.DB) *gorm.DB {
|
||||
return db.Order("step_order ASC, parallel_group ASC")
|
||||
}).
|
||||
Preload("Steps.ApproverRole").
|
||||
Preload("Steps.ApproverUser").
|
||||
Where("id = ?", id).
|
||||
First(&e).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &e, nil
|
||||
}
|
||||
|
||||
func (r *ApprovalFlowRepository) GetByDepartment(ctx context.Context, departmentID uuid.UUID) (*entities.ApprovalFlow, error) {
|
||||
db := DBFromContext(ctx, r.db)
|
||||
var e entities.ApprovalFlow
|
||||
if err := db.WithContext(ctx).
|
||||
Preload("Department").
|
||||
Preload("Steps", func(db *gorm.DB) *gorm.DB {
|
||||
return db.Order("step_order ASC, parallel_group ASC")
|
||||
}).
|
||||
Preload("Steps.ApproverRole").
|
||||
Preload("Steps.ApproverUser").
|
||||
Where("department_id = ? AND is_active = true", departmentID).
|
||||
First(&e).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &e, nil
|
||||
}
|
||||
|
||||
func (r *ApprovalFlowRepository) Update(ctx context.Context, e *entities.ApprovalFlow) error {
|
||||
db := DBFromContext(ctx, r.db)
|
||||
return db.WithContext(ctx).Model(&entities.ApprovalFlow{}).Where("id = ?", e.ID).Updates(e).Error
|
||||
}
|
||||
|
||||
func (r *ApprovalFlowRepository) Delete(ctx context.Context, id uuid.UUID) error {
|
||||
db := DBFromContext(ctx, r.db)
|
||||
return db.WithContext(ctx).Where("id = ?", id).Delete(&entities.ApprovalFlow{}).Error
|
||||
}
|
||||
|
||||
type ListApprovalFlowsFilter struct {
|
||||
DepartmentID *uuid.UUID
|
||||
IsActive *bool
|
||||
}
|
||||
|
||||
func (r *ApprovalFlowRepository) List(ctx context.Context, filter ListApprovalFlowsFilter, limit, offset int) ([]entities.ApprovalFlow, int64, error) {
|
||||
db := DBFromContext(ctx, r.db)
|
||||
query := db.WithContext(ctx).Model(&entities.ApprovalFlow{})
|
||||
|
||||
if filter.DepartmentID != nil {
|
||||
query = query.Where("department_id = ?", *filter.DepartmentID)
|
||||
}
|
||||
if filter.IsActive != nil {
|
||||
query = query.Where("is_active = ?", *filter.IsActive)
|
||||
}
|
||||
|
||||
var total int64
|
||||
if err := query.Count(&total).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
var list []entities.ApprovalFlow
|
||||
if err := query.
|
||||
Preload("Department").
|
||||
Preload("Steps", func(db *gorm.DB) *gorm.DB {
|
||||
return db.Order("step_order ASC, parallel_group ASC")
|
||||
}).
|
||||
Order("created_at DESC").
|
||||
Limit(limit).
|
||||
Offset(offset).
|
||||
Find(&list).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
return list, total, nil
|
||||
}
|
||||
|
||||
type ApprovalFlowStepRepository struct{ db *gorm.DB }
|
||||
|
||||
func NewApprovalFlowStepRepository(db *gorm.DB) *ApprovalFlowStepRepository {
|
||||
return &ApprovalFlowStepRepository{db: db}
|
||||
}
|
||||
|
||||
func (r *ApprovalFlowStepRepository) Create(ctx context.Context, e *entities.ApprovalFlowStep) error {
|
||||
db := DBFromContext(ctx, r.db)
|
||||
return db.WithContext(ctx).Create(e).Error
|
||||
}
|
||||
|
||||
func (r *ApprovalFlowStepRepository) CreateBulk(ctx context.Context, list []entities.ApprovalFlowStep) error {
|
||||
db := DBFromContext(ctx, r.db)
|
||||
if len(list) == 0 {
|
||||
return nil
|
||||
}
|
||||
return db.WithContext(ctx).Create(&list).Error
|
||||
}
|
||||
|
||||
func (r *ApprovalFlowStepRepository) Update(ctx context.Context, e *entities.ApprovalFlowStep) error {
|
||||
db := DBFromContext(ctx, r.db)
|
||||
return db.WithContext(ctx).Model(&entities.ApprovalFlowStep{}).Where("id = ?", e.ID).Updates(e).Error
|
||||
}
|
||||
|
||||
func (r *ApprovalFlowStepRepository) Delete(ctx context.Context, id uuid.UUID) error {
|
||||
db := DBFromContext(ctx, r.db)
|
||||
return db.WithContext(ctx).Where("id = ?", id).Delete(&entities.ApprovalFlowStep{}).Error
|
||||
}
|
||||
|
||||
func (r *ApprovalFlowStepRepository) DeleteByFlow(ctx context.Context, flowID uuid.UUID) error {
|
||||
db := DBFromContext(ctx, r.db)
|
||||
return db.WithContext(ctx).Where("flow_id = ?", flowID).Delete(&entities.ApprovalFlowStep{}).Error
|
||||
}
|
||||
|
||||
func (r *ApprovalFlowStepRepository) ListByFlow(ctx context.Context, flowID uuid.UUID) ([]entities.ApprovalFlowStep, error) {
|
||||
db := DBFromContext(ctx, r.db)
|
||||
var list []entities.ApprovalFlowStep
|
||||
if err := db.WithContext(ctx).
|
||||
Preload("ApproverRole").
|
||||
Preload("ApproverUser").
|
||||
Where("flow_id = ?", flowID).
|
||||
Order("step_order ASC, parallel_group ASC").
|
||||
Find(&list).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return list, nil
|
||||
}
|
||||
|
||||
type LetterOutgoingApprovalRepository struct{ db *gorm.DB }
|
||||
|
||||
func NewLetterOutgoingApprovalRepository(db *gorm.DB) *LetterOutgoingApprovalRepository {
|
||||
return &LetterOutgoingApprovalRepository{db: db}
|
||||
}
|
||||
|
||||
func (r *LetterOutgoingApprovalRepository) Create(ctx context.Context, e *entities.LetterOutgoingApproval) error {
|
||||
db := DBFromContext(ctx, r.db)
|
||||
return db.WithContext(ctx).Create(e).Error
|
||||
}
|
||||
|
||||
func (r *LetterOutgoingApprovalRepository) CreateBulk(ctx context.Context, list []entities.LetterOutgoingApproval) error {
|
||||
db := DBFromContext(ctx, r.db)
|
||||
if len(list) == 0 {
|
||||
return nil
|
||||
}
|
||||
return db.WithContext(ctx).Create(&list).Error
|
||||
}
|
||||
|
||||
func (r *LetterOutgoingApprovalRepository) Get(ctx context.Context, id uuid.UUID) (*entities.LetterOutgoingApproval, error) {
|
||||
db := DBFromContext(ctx, r.db)
|
||||
var e entities.LetterOutgoingApproval
|
||||
if err := db.WithContext(ctx).
|
||||
Preload("Letter").
|
||||
Preload("Step").
|
||||
Preload("Approver").
|
||||
Where("id = ?", id).
|
||||
First(&e).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &e, nil
|
||||
}
|
||||
|
||||
func (r *LetterOutgoingApprovalRepository) GetByLetterAndStep(ctx context.Context, letterID, stepID uuid.UUID) (*entities.LetterOutgoingApproval, error) {
|
||||
db := DBFromContext(ctx, r.db)
|
||||
var e entities.LetterOutgoingApproval
|
||||
if err := db.WithContext(ctx).
|
||||
Where("letter_id = ? AND step_id = ?", letterID, stepID).
|
||||
First(&e).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &e, nil
|
||||
}
|
||||
|
||||
func (r *LetterOutgoingApprovalRepository) Update(ctx context.Context, e *entities.LetterOutgoingApproval) error {
|
||||
db := DBFromContext(ctx, r.db)
|
||||
return db.WithContext(ctx).Model(&entities.LetterOutgoingApproval{}).Where("id = ?", e.ID).Updates(e).Error
|
||||
}
|
||||
|
||||
func (r *LetterOutgoingApprovalRepository) ListByLetter(ctx context.Context, letterID uuid.UUID) ([]entities.LetterOutgoingApproval, error) {
|
||||
db := DBFromContext(ctx, r.db)
|
||||
var list []entities.LetterOutgoingApproval
|
||||
if err := db.WithContext(ctx).
|
||||
Preload("Step.ApproverRole").
|
||||
Preload("Step.ApproverUser").
|
||||
Preload("Approver").
|
||||
Where("letter_id = ?", letterID).
|
||||
Order("created_at ASC").
|
||||
Find(&list).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return list, nil
|
||||
}
|
||||
|
||||
func (r *LetterOutgoingApprovalRepository) GetPendingApprovals(ctx context.Context, userID uuid.UUID) ([]entities.LetterOutgoingApproval, error) {
|
||||
db := DBFromContext(ctx, r.db)
|
||||
var list []entities.LetterOutgoingApproval
|
||||
|
||||
if err := db.WithContext(ctx).
|
||||
Preload("Letter").
|
||||
Preload("Step").
|
||||
Joins("JOIN approval_flow_steps afs ON afs.id = letter_outgoing_approvals.step_id").
|
||||
Where("letter_outgoing_approvals.status = ? AND (afs.approver_user_id = ? OR afs.approver_role_id IN (SELECT role_id FROM user_roles WHERE user_id = ?))",
|
||||
entities.ApprovalStatusPending, userID, userID).
|
||||
Find(&list).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return list, nil
|
||||
}
|
||||
@@ -0,0 +1,275 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"eslogad-be/internal/entities"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type LetterOutgoingRepository struct{ db *gorm.DB }
|
||||
|
||||
func NewLetterOutgoingRepository(db *gorm.DB) *LetterOutgoingRepository {
|
||||
return &LetterOutgoingRepository{db: db}
|
||||
}
|
||||
|
||||
func (r *LetterOutgoingRepository) Create(ctx context.Context, e *entities.LetterOutgoing) error {
|
||||
db := DBFromContext(ctx, r.db)
|
||||
return db.WithContext(ctx).Create(e).Error
|
||||
}
|
||||
|
||||
func (r *LetterOutgoingRepository) Get(ctx context.Context, id uuid.UUID) (*entities.LetterOutgoing, error) {
|
||||
db := DBFromContext(ctx, r.db)
|
||||
var e entities.LetterOutgoing
|
||||
if err := db.WithContext(ctx).
|
||||
Preload("Priority").
|
||||
Preload("ReceiverInstitution").
|
||||
Preload("Creator").
|
||||
Preload("ApprovalFlow").
|
||||
Preload("Recipients").
|
||||
Preload("Attachments").
|
||||
Preload("Approvals.Step").
|
||||
Preload("Approvals.Approver").
|
||||
Where("id = ? AND deleted_at IS NULL", id).
|
||||
First(&e).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &e, nil
|
||||
}
|
||||
|
||||
func (r *LetterOutgoingRepository) Update(ctx context.Context, e *entities.LetterOutgoing) error {
|
||||
db := DBFromContext(ctx, r.db)
|
||||
return db.WithContext(ctx).Model(&entities.LetterOutgoing{}).Where("id = ? AND deleted_at IS NULL", e.ID).Updates(e).Error
|
||||
}
|
||||
|
||||
func (r *LetterOutgoingRepository) SoftDelete(ctx context.Context, id uuid.UUID) error {
|
||||
db := DBFromContext(ctx, r.db)
|
||||
now := time.Now()
|
||||
return db.WithContext(ctx).Model(&entities.LetterOutgoing{}).Where("id = ? AND deleted_at IS NULL", id).Update("deleted_at", now).Error
|
||||
}
|
||||
|
||||
type ListOutgoingLettersFilter struct {
|
||||
Status *string
|
||||
Query *string
|
||||
CreatedBy *uuid.UUID
|
||||
ReceiverInstitutionID *uuid.UUID
|
||||
FromDate *time.Time
|
||||
ToDate *time.Time
|
||||
}
|
||||
|
||||
func (r *LetterOutgoingRepository) List(ctx context.Context, filter ListOutgoingLettersFilter, limit, offset int) ([]entities.LetterOutgoing, int64, error) {
|
||||
db := DBFromContext(ctx, r.db)
|
||||
query := db.WithContext(ctx).Model(&entities.LetterOutgoing{}).Where("deleted_at IS NULL")
|
||||
|
||||
if filter.Status != nil {
|
||||
query = query.Where("status = ?", *filter.Status)
|
||||
}
|
||||
if filter.Query != nil {
|
||||
q := "%" + *filter.Query + "%"
|
||||
query = query.Where("subject ILIKE ? OR reference_number ILIKE ? OR letter_number ILIKE ?", q, q, q)
|
||||
}
|
||||
if filter.CreatedBy != nil {
|
||||
query = query.Where("created_by = ?", *filter.CreatedBy)
|
||||
}
|
||||
if filter.ReceiverInstitutionID != nil {
|
||||
query = query.Where("receiver_institution_id = ?", *filter.ReceiverInstitutionID)
|
||||
}
|
||||
if filter.FromDate != nil {
|
||||
query = query.Where("issue_date >= ?", *filter.FromDate)
|
||||
}
|
||||
if filter.ToDate != nil {
|
||||
query = query.Where("issue_date <= ?", *filter.ToDate)
|
||||
}
|
||||
|
||||
var total int64
|
||||
if err := query.Count(&total).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
var list []entities.LetterOutgoing
|
||||
if err := query.
|
||||
Preload("Priority").
|
||||
Preload("ReceiverInstitution").
|
||||
Preload("Creator").
|
||||
Order("created_at DESC").
|
||||
Limit(limit).
|
||||
Offset(offset).
|
||||
Find(&list).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
return list, total, nil
|
||||
}
|
||||
|
||||
func (r *LetterOutgoingRepository) UpdateStatus(ctx context.Context, id uuid.UUID, status entities.LetterOutgoingStatus) error {
|
||||
db := DBFromContext(ctx, r.db)
|
||||
return db.WithContext(ctx).Model(&entities.LetterOutgoing{}).Where("id = ? AND deleted_at IS NULL", id).Update("status", status).Error
|
||||
}
|
||||
|
||||
type LetterOutgoingAttachmentRepository struct{ db *gorm.DB }
|
||||
|
||||
func NewLetterOutgoingAttachmentRepository(db *gorm.DB) *LetterOutgoingAttachmentRepository {
|
||||
return &LetterOutgoingAttachmentRepository{db: db}
|
||||
}
|
||||
|
||||
func (r *LetterOutgoingAttachmentRepository) Create(ctx context.Context, e *entities.LetterOutgoingAttachment) error {
|
||||
db := DBFromContext(ctx, r.db)
|
||||
return db.WithContext(ctx).Create(e).Error
|
||||
}
|
||||
|
||||
func (r *LetterOutgoingAttachmentRepository) CreateBulk(ctx context.Context, list []entities.LetterOutgoingAttachment) error {
|
||||
db := DBFromContext(ctx, r.db)
|
||||
if len(list) == 0 {
|
||||
return nil
|
||||
}
|
||||
return db.WithContext(ctx).Create(&list).Error
|
||||
}
|
||||
|
||||
func (r *LetterOutgoingAttachmentRepository) ListByLetter(ctx context.Context, letterID uuid.UUID) ([]entities.LetterOutgoingAttachment, error) {
|
||||
db := DBFromContext(ctx, r.db)
|
||||
var list []entities.LetterOutgoingAttachment
|
||||
if err := db.WithContext(ctx).Where("letter_id = ?", letterID).Order("uploaded_at ASC").Find(&list).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return list, nil
|
||||
}
|
||||
|
||||
func (r *LetterOutgoingAttachmentRepository) Delete(ctx context.Context, id uuid.UUID) error {
|
||||
db := DBFromContext(ctx, r.db)
|
||||
return db.WithContext(ctx).Where("id = ?", id).Delete(&entities.LetterOutgoingAttachment{}).Error
|
||||
}
|
||||
|
||||
type LetterOutgoingRecipientRepository struct{ db *gorm.DB }
|
||||
|
||||
func NewLetterOutgoingRecipientRepository(db *gorm.DB) *LetterOutgoingRecipientRepository {
|
||||
return &LetterOutgoingRecipientRepository{db: db}
|
||||
}
|
||||
|
||||
func (r *LetterOutgoingRecipientRepository) Create(ctx context.Context, e *entities.LetterOutgoingRecipient) error {
|
||||
db := DBFromContext(ctx, r.db)
|
||||
return db.WithContext(ctx).Create(e).Error
|
||||
}
|
||||
|
||||
func (r *LetterOutgoingRecipientRepository) CreateBulk(ctx context.Context, list []entities.LetterOutgoingRecipient) error {
|
||||
db := DBFromContext(ctx, r.db)
|
||||
if len(list) == 0 {
|
||||
return nil
|
||||
}
|
||||
return db.WithContext(ctx).Create(&list).Error
|
||||
}
|
||||
|
||||
func (r *LetterOutgoingRecipientRepository) ListByLetter(ctx context.Context, letterID uuid.UUID) ([]entities.LetterOutgoingRecipient, error) {
|
||||
db := DBFromContext(ctx, r.db)
|
||||
var list []entities.LetterOutgoingRecipient
|
||||
if err := db.WithContext(ctx).Where("letter_id = ?", letterID).Order("is_primary DESC, created_at ASC").Find(&list).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return list, nil
|
||||
}
|
||||
|
||||
func (r *LetterOutgoingRecipientRepository) Update(ctx context.Context, e *entities.LetterOutgoingRecipient) error {
|
||||
db := DBFromContext(ctx, r.db)
|
||||
return db.WithContext(ctx).Model(&entities.LetterOutgoingRecipient{}).Where("id = ?", e.ID).Updates(e).Error
|
||||
}
|
||||
|
||||
func (r *LetterOutgoingRecipientRepository) Delete(ctx context.Context, id uuid.UUID) error {
|
||||
db := DBFromContext(ctx, r.db)
|
||||
return db.WithContext(ctx).Where("id = ?", id).Delete(&entities.LetterOutgoingRecipient{}).Error
|
||||
}
|
||||
|
||||
func (r *LetterOutgoingRecipientRepository) DeleteByLetter(ctx context.Context, letterID uuid.UUID) error {
|
||||
db := DBFromContext(ctx, r.db)
|
||||
return db.WithContext(ctx).Where("letter_id = ?", letterID).Delete(&entities.LetterOutgoingRecipient{}).Error
|
||||
}
|
||||
|
||||
type LetterOutgoingDiscussionRepository struct{ db *gorm.DB }
|
||||
|
||||
func NewLetterOutgoingDiscussionRepository(db *gorm.DB) *LetterOutgoingDiscussionRepository {
|
||||
return &LetterOutgoingDiscussionRepository{db: db}
|
||||
}
|
||||
|
||||
func (r *LetterOutgoingDiscussionRepository) Create(ctx context.Context, e *entities.LetterOutgoingDiscussion) error {
|
||||
db := DBFromContext(ctx, r.db)
|
||||
return db.WithContext(ctx).Create(e).Error
|
||||
}
|
||||
|
||||
func (r *LetterOutgoingDiscussionRepository) Get(ctx context.Context, id uuid.UUID) (*entities.LetterOutgoingDiscussion, error) {
|
||||
db := DBFromContext(ctx, r.db)
|
||||
var e entities.LetterOutgoingDiscussion
|
||||
if err := db.WithContext(ctx).
|
||||
Preload("User").
|
||||
Preload("Attachments").
|
||||
Where("id = ?", id).
|
||||
First(&e).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &e, nil
|
||||
}
|
||||
|
||||
func (r *LetterOutgoingDiscussionRepository) ListByLetter(ctx context.Context, letterID uuid.UUID) ([]entities.LetterOutgoingDiscussion, error) {
|
||||
db := DBFromContext(ctx, r.db)
|
||||
var list []entities.LetterOutgoingDiscussion
|
||||
if err := db.WithContext(ctx).
|
||||
Preload("User").
|
||||
Preload("Attachments").
|
||||
Preload("Replies.User").
|
||||
Where("letter_id = ? AND parent_id IS NULL", letterID).
|
||||
Order("created_at DESC").
|
||||
Find(&list).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return list, nil
|
||||
}
|
||||
|
||||
func (r *LetterOutgoingDiscussionRepository) Update(ctx context.Context, e *entities.LetterOutgoingDiscussion) error {
|
||||
db := DBFromContext(ctx, r.db)
|
||||
now := time.Now()
|
||||
e.EditedAt = &now
|
||||
return db.WithContext(ctx).Model(&entities.LetterOutgoingDiscussion{}).Where("id = ?", e.ID).Updates(e).Error
|
||||
}
|
||||
|
||||
func (r *LetterOutgoingDiscussionRepository) Delete(ctx context.Context, id uuid.UUID) error {
|
||||
db := DBFromContext(ctx, r.db)
|
||||
return db.WithContext(ctx).Where("id = ?", id).Delete(&entities.LetterOutgoingDiscussion{}).Error
|
||||
}
|
||||
|
||||
type LetterOutgoingDiscussionAttachmentRepository struct{ db *gorm.DB }
|
||||
|
||||
func NewLetterOutgoingDiscussionAttachmentRepository(db *gorm.DB) *LetterOutgoingDiscussionAttachmentRepository {
|
||||
return &LetterOutgoingDiscussionAttachmentRepository{db: db}
|
||||
}
|
||||
|
||||
func (r *LetterOutgoingDiscussionAttachmentRepository) CreateBulk(ctx context.Context, list []entities.LetterOutgoingDiscussionAttachment) error {
|
||||
db := DBFromContext(ctx, r.db)
|
||||
if len(list) == 0 {
|
||||
return nil
|
||||
}
|
||||
return db.WithContext(ctx).Create(&list).Error
|
||||
}
|
||||
|
||||
type LetterOutgoingActivityLogRepository struct{ db *gorm.DB }
|
||||
|
||||
func NewLetterOutgoingActivityLogRepository(db *gorm.DB) *LetterOutgoingActivityLogRepository {
|
||||
return &LetterOutgoingActivityLogRepository{db: db}
|
||||
}
|
||||
|
||||
func (r *LetterOutgoingActivityLogRepository) Create(ctx context.Context, e *entities.LetterOutgoingActivityLog) error {
|
||||
db := DBFromContext(ctx, r.db)
|
||||
return db.WithContext(ctx).Create(e).Error
|
||||
}
|
||||
|
||||
func (r *LetterOutgoingActivityLogRepository) ListByLetter(ctx context.Context, letterID uuid.UUID) ([]entities.LetterOutgoingActivityLog, error) {
|
||||
db := DBFromContext(ctx, r.db)
|
||||
var list []entities.LetterOutgoingActivityLog
|
||||
if err := db.WithContext(ctx).
|
||||
Preload("ActorUser").
|
||||
Preload("ActorDepartment").
|
||||
Where("letter_id = ?", letterID).
|
||||
Order("occurred_at DESC").
|
||||
Find(&list).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return list, nil
|
||||
}
|
||||
Reference in New Issue
Block a user