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 | 720d47fae476b0d38477ae4401697d372b1ea2bc |
| Branch | feature/opportunity-to-outcome |
| Path or archive member | internal/modules/awards/service.go |
| Original SHA-256 | 169a4f27cebcaf7f2b7115676c88791ddc68ce406a694036289b9aa68fc0b0ff |
| Git blob SHA | ff031fc3fa38a89f224041c79ee9dd187da8e976 |
| Reading-copy SHA-256 | 169a4f27cebcaf7f2b7115676c88791ddc68ce406a694036289b9aa68fc0b0ff |
Every recorded occurrence
These 2 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 | feature/opportunity-to-outcome | 720d47fae476b0d38477ae4401697d372b1ea2bc | Open original |
| Janady13/missionmatch / internal/modules/awards/service.go | feature/aioe-upgrade | 2178e7298d0e5d9af83afa12402fd587f0ba6ed8 | Open original |
Recovered source transcript
Download complete source text ↓117 lines · 2.9 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.Ready() {
return nil, ErrNoDatabase
}
if len(naics) == 0 {
return []Award{}, nil
}
pool, release, perr := s.acquirePool(ctx)
if perr != nil {
return nil, perr
}
defer release()
rows, err := dbgen.New(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.Ready() {
return nil, ErrNoDatabase
}
pool, release, perr := s.acquirePool(ctx)
if perr != nil {
return nil, perr
}
defer release()
rows, err := dbgen.New(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")
}