Source identity
| Field | Recorded value |
|---|---|
| Source type | GitHub source |
| Original record | Janady13/missionmatch / internal/modules/awards/service.go |
| Date | Not specified in source |
| Repository | Janady13/missionmatch |
| Revision | 9bde0f9a74b89d01980fa658e5253acda7528d0c |
| Branch | per-tenant-routing |
| Path or archive member | internal/modules/awards/service.go |
| Original SHA-256 | ec29e2e84182866a0100041edb7159bf1b85a09e0e2911a1e123c44166869191 |
| Git blob SHA | d8bdc3fd5980e38172ee5d0d4cb8bcbffa6a2c18 |
| Reading-copy SHA-256 | ec29e2e84182866a0100041edb7159bf1b85a09e0e2911a1e123c44166869191 |
Every recorded occurrence
These 3 records contain identical original source bytes. Their paths and revisions remain part of the archive.
| Original record | Branch or archive | Revision / identifier | Original location |
|---|---|---|---|
| Janady13/missionmatch / internal/modules/awards/service.go | per-tenant-routing | 9bde0f9a74b89d01980fa658e5253acda7528d0c | Open original |
| Janady13/missionmatch / internal/modules/awards/service.go | deploy-and-ops | bdacd9d0b4d5998d25fc74bf4007f4c3ec538c7a | Open original |
| Janady13/missionmatch / internal/modules/awards/service.go | per-tenant-routing | 9bde0f9a74b89d01980fa658e5253acda7528d0c | Open original |
Recovered source transcript
Download complete source text ↓123 lines · 3.0 KB
package awards
import (
"context"
"errors"
"time"
"github.com/jackc/pgx/v5/pgtype"
"github.com/missionworkforce/missionmatch/internal/platform/database/dbgen"
"github.com/missionworkforce/missionmatch/internal/platform/tenant"
)
// ErrNoDatabase is returned when no pool is configured.
var ErrNoDatabase = errors.New("awards: no database configured")
const (
defaultIncumbentLimit = 5
maxLimit = 50
)
// Service reads the cached awards catalog.
type Service struct{ db *tenant.DB }
// NewService builds the service. db may be nil (then calls return ErrNoDatabase).
func NewService(db *tenant.DB) *Service { return &Service{db: db} }
// Incumbents returns the largest comparable awards for the given NAICS codes, excluding Galapagos own
// awards. Returns an empty slice when no NAICS is supplied.
func (s *Service) Incumbents(ctx context.Context, naics []string, limit int) ([]Award, error) {
if s.db == nil {
return nil, ErrNoDatabase
}
if len(naics) == 0 {
return []Award{}, nil
}
leaf, release, err := s.db.Acquire(ctx)
if err != nil {
return nil, err
}
defer release()
if leaf.Pool == nil {
return nil, ErrNoDatabase
}
rows, err := dbgen.New(leaf.Pool).ListAwardsByNaics(ctx, dbgen.ListAwardsByNaicsParams{
Naics: naics,
Lim: int32(clampLimit(limit, defaultIncumbentLimit)),
})
if err != nil {
return nil, err
}
return toViews(rows), nil
}
// Galapagos returns Galapagos own past performance, largest first.
func (s *Service) Galapagos(ctx context.Context, limit int) ([]Award, error) {
if s.db == nil {
return nil, ErrNoDatabase
}
leaf, release, err := s.db.Acquire(ctx)
if err != nil {
return nil, err
}
defer release()
if leaf.Pool == nil {
return nil, ErrNoDatabase
}
rows, err := dbgen.New(leaf.Pool).ListGalapagosAwards(ctx, int32(clampLimit(limit, 10)))
if err != nil {
return nil, err
}
return toViews(rows), nil
}
func clampLimit(v, def int) int {
if v <= 0 {
return def
}
if v > maxLimit {
return maxLimit
}
return v
}
func toViews(rows []dbgen.UsaspendingAward) []Award {
out := make([]Award, 0, len(rows))
for _, r := range rows {
out = append(out, toView(r))
}
return out
}
func toView(r dbgen.UsaspendingAward) Award {
amount := ""
if r.AwardAmount != nil {
amount = r.AwardAmount.StringFixed(2)
}
return Award{
AwardUID: r.GeneratedInternalID,
AwardID: r.AwardID,
RecipientName: r.RecipientName,
RecipientUEI: r.RecipientUei,
AwardAmount: amount,
AwardingAgency: r.AwardingAgency,
AwardingSubAgency: r.AwardingSubAgency,
POPStartDate: dateStr(r.PopStartDate),
POPEndDate: dateStr(r.PopEndDate),
NaicsCode: r.NaicsCode,
NaicsDescription: r.NaicsDescription,
Description: r.Description,
IsGalapagos: r.IsGalapagos,
Source: r.Source,
SyncedAt: r.SyncedAt.Format(time.RFC3339),
}
}
func dateStr(d pgtype.Date) string {
if !d.Valid {
return ""
}
return d.Time.Format("2006-01-02")
}