New Quotator and some major changes to pricing admin

This commit is contained in:
Mikhail Chusavitin
2026-01-26 18:30:45 +03:00
parent a93644131c
commit d7d6e9d62c
24 changed files with 565 additions and 112 deletions

View File

@@ -1,7 +1,7 @@
package repository
import (
"github.com/mchus/quoteforge/internal/models"
"git.mchus.pro/mchus/quoteforge/internal/models"
"gorm.io/gorm"
)

View File

@@ -1,7 +1,7 @@
package repository
import (
"github.com/mchus/quoteforge/internal/models"
"git.mchus.pro/mchus/quoteforge/internal/models"
"gorm.io/gorm"
)

View File

@@ -3,7 +3,7 @@ package repository
import (
"time"
"github.com/mchus/quoteforge/internal/models"
"git.mchus.pro/mchus/quoteforge/internal/models"
"gorm.io/gorm"
)
@@ -17,7 +17,6 @@ func NewComponentRepository(db *gorm.DB) *ComponentRepository {
type ComponentFilter struct {
Category string
Vendor string
Search string
HasPrice bool
}
@@ -34,9 +33,6 @@ func (r *ComponentRepository) List(filter ComponentFilter, offset, limit int) ([
query = query.Joins("JOIN qt_categories ON qt_lot_metadata.category_id = qt_categories.id").
Where("qt_categories.code = ?", filter.Category)
}
if filter.Vendor != "" {
query = query.Where("vendor = ?", filter.Vendor)
}
if filter.Search != "" {
search := "%" + filter.Search + "%"
query = query.Where("lot_name LIKE ? OR model LIKE ?", search, search)
@@ -89,17 +85,6 @@ func (r *ComponentRepository) Create(component *models.LotMetadata) error {
return r.db.Create(component).Error
}
func (r *ComponentRepository) GetVendors(category string) ([]string, error) {
var vendors []string
query := r.db.Model(&models.LotMetadata{}).Distinct("vendor")
if category != "" {
query = query.Joins("JOIN qt_categories ON qt_lot_metadata.category_id = qt_categories.id").
Where("qt_categories.code = ?", category)
}
err := query.Pluck("vendor", &vendors).Error
return vendors, err
}
func (r *ComponentRepository) IncrementRequestCount(lotName string) error {
now := time.Now()
return r.db.Model(&models.LotMetadata{}).

View File

@@ -1,7 +1,7 @@
package repository
import (
"github.com/mchus/quoteforge/internal/models"
"git.mchus.pro/mchus/quoteforge/internal/models"
"gorm.io/gorm"
)

View File

@@ -3,7 +3,7 @@ package repository
import (
"time"
"github.com/mchus/quoteforge/internal/models"
"git.mchus.pro/mchus/quoteforge/internal/models"
"gorm.io/gorm"
)
@@ -97,3 +97,28 @@ func (r *PriceRepository) GetQuoteCount(lotName string, periodDays int) (int64,
return count, err
}
// GetQuoteCounts returns quote counts for multiple lot names
func (r *PriceRepository) GetQuoteCounts(lotNames []string) (map[string]int64, error) {
type Result struct {
Lot string
Count int64
}
var results []Result
err := r.db.Model(&models.LotLog{}).
Select("lot, COUNT(*) as count").
Where("lot IN ?", lotNames).
Group("lot").
Scan(&results).Error
if err != nil {
return nil, err
}
counts := make(map[string]int64)
for _, r := range results {
counts[r.Lot] = r.Count
}
return counts, nil
}

View File

@@ -3,7 +3,7 @@ package repository
import (
"time"
"github.com/mchus/quoteforge/internal/models"
"git.mchus.pro/mchus/quoteforge/internal/models"
"gorm.io/gorm"
)

View File

@@ -1,7 +1,7 @@
package repository
import (
"github.com/mchus/quoteforge/internal/models"
"git.mchus.pro/mchus/quoteforge/internal/models"
"gorm.io/gorm"
)