add app setting letter out

This commit is contained in:
Aditya Siregar
2025-08-28 19:23:41 +07:00
parent 6da48504fa
commit 592fa97be7
18 changed files with 1077 additions and 538 deletions
@@ -0,0 +1,28 @@
package repository
import (
"context"
"eslogad-be/internal/entities"
"gorm.io/gorm"
)
type AppSettingRepository struct{ db *gorm.DB }
func NewAppSettingRepository(db *gorm.DB) *AppSettingRepository {
return &AppSettingRepository{
db: db,
}
}
func (r *AppSettingRepository) Get(ctx context.Context, key string) (*entities.AppSetting, error) {
db := DBFromContext(ctx, r.db)
var e entities.AppSetting
if err := db.WithContext(ctx).First(&e, "key = ?", key).Error; err != nil {
return nil, err
}
return &e, nil
}
func (r *AppSettingRepository) Upsert(ctx context.Context, key string, value entities.JSONB) error {
db := DBFromContext(ctx, r.db)
return db.WithContext(ctx).Exec("INSERT INTO app_settings(key, value) VALUES(?, ?) ON CONFLICT(key) DO UPDATE SET value = EXCLUDED.value, updated_at = CURRENT_TIMESTAMP", key, value).Error
}
-16
View File
@@ -278,22 +278,6 @@ func (r *LetterDiscussionRepository) GetUsersByIDs(ctx context.Context, userIDs
return users, nil
}
type AppSettingRepository struct{ db *gorm.DB }
func NewAppSettingRepository(db *gorm.DB) *AppSettingRepository { return &AppSettingRepository{db: db} }
func (r *AppSettingRepository) Get(ctx context.Context, key string) (*entities.AppSetting, error) {
db := DBFromContext(ctx, r.db)
var e entities.AppSetting
if err := db.WithContext(ctx).First(&e, "key = ?", key).Error; err != nil {
return nil, err
}
return &e, nil
}
func (r *AppSettingRepository) Upsert(ctx context.Context, key string, value entities.JSONB) error {
db := DBFromContext(ctx, r.db)
return db.WithContext(ctx).Exec("INSERT INTO app_settings(key, value) VALUES(?, ?) ON CONFLICT(key) DO UPDATE SET value = EXCLUDED.value, updated_at = CURRENT_TIMESTAMP", key, value).Error
}
// recipients
type LetterIncomingRecipientRepository struct{ db *gorm.DB }
+29
View File
@@ -159,3 +159,32 @@ func (r *DepartmentRepository) Get(ctx context.Context, id uuid.UUID) (*entities
}
return &dep, nil
}
func (r *DepartmentRepository) List(ctx context.Context, search string, limit, offset int) ([]entities.Department, int64, error) {
db := DBFromContext(ctx, r.db)
query := db.WithContext(ctx).Model(&entities.Department{})
// Add search filter if provided
if search != "" {
query = query.Where("name ILIKE ?", "%"+search+"%")
}
// Get total count
var total int64
if err := query.Count(&total).Error; err != nil {
return nil, 0, err
}
// Get paginated results
var list []entities.Department
if err := query.
Order("name ASC").
Limit(limit).
Offset(offset).
Find(&list).Error; err != nil {
return nil, 0, err
}
return list, total, nil
}