Align document handlers/repo with contract updates

This commit is contained in:
Trey t
2026-02-18 21:37:38 -06:00
parent e7c23bdeb1
commit 09a35c0b99
5 changed files with 156 additions and 131 deletions

View File

@@ -12,11 +12,8 @@ import (
type DocumentFilter struct {
ResidenceID *uint
DocumentType string
Category string
ContractorID *uint
IsActive *bool
ExpiringSoon *int
Tags string
Search string
}
@@ -72,18 +69,17 @@ func (r *DocumentRepository) FindByUserFiltered(residenceIDs []uint, filter *Doc
query := r.db.Preload("CreatedBy").
Preload("Residence").
Preload("Images").
Where("residence_id IN ? AND is_active = ?", residenceIDs, true)
Where("residence_id IN ?", residenceIDs)
// Default behavior is active-only unless explicitly overridden.
if filter == nil || filter.IsActive == nil {
query = query.Where("is_active = ?", true)
}
if filter != nil {
if filter.DocumentType != "" {
query = query.Where("document_type = ?", filter.DocumentType)
}
if filter.Category != "" {
query = query.Where("category = ?", filter.Category)
}
if filter.ContractorID != nil {
query = query.Where("contractor_id = ?", *filter.ContractorID)
}
if filter.IsActive != nil {
query = query.Where("is_active = ?", *filter.IsActive)
}
@@ -92,9 +88,6 @@ func (r *DocumentRepository) FindByUserFiltered(residenceIDs []uint, filter *Doc
threshold := now.AddDate(0, 0, *filter.ExpiringSoon)
query = query.Where("expiry_date IS NOT NULL AND expiry_date > ? AND expiry_date <= ?", now, threshold)
}
if filter.Tags != "" {
query = query.Where("tags LIKE ?", "%"+filter.Tags+"%")
}
if filter.Search != "" {
searchPattern := "%" + filter.Search + "%"
query = query.Where("(title ILIKE ? OR description ILIKE ?)", searchPattern, searchPattern)