Skip to content

Commit

Permalink
Merge branch 'integrationTesting' into INT-B-20463-update-previous-mo…
Browse files Browse the repository at this point in the history
…ves-to-consider-multi-move-data
  • Loading branch information
danieljordan-caci committed Jul 19, 2024
2 parents fb17b4b + b048057 commit 006a124
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 22 deletions.
4 changes: 2 additions & 2 deletions pkg/handlers/ghcapi/tranportation_offices.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func (h GetTransportationOfficesHandler) Handle(params transportationofficeop.Ge
return h.AuditableAppContextFromRequestWithErrors(params.HTTPRequest,
func(appCtx appcontext.AppContext) (middleware.Responder, error) {

transportationOffices, err := h.TransportationOfficesFetcher.GetTransportationOffices(appCtx, params.Search)
transportationOffices, err := h.TransportationOfficesFetcher.GetTransportationOffices(appCtx, params.Search, true)
if err != nil {
appCtx.Logger().Error("Error searching for Transportation Offices: ", zap.Error(err))
return transportationofficeop.NewGetTransportationOfficesInternalServerError(), err
Expand All @@ -40,7 +40,7 @@ func (h GetTransportationOfficesOpenHandler) Handle(params transportationofficeo
return h.AuditableAppContextFromRequestWithErrors(params.HTTPRequest,
func(appCtx appcontext.AppContext) (middleware.Responder, error) {

transportationOffices, err := h.TransportationOfficesFetcher.GetTransportationOffices(appCtx, params.Search)
transportationOffices, err := h.TransportationOfficesFetcher.GetTransportationOffices(appCtx, params.Search, true)
if err != nil {
appCtx.Logger().Error("Error searching for Transportation Offices: ", zap.Error(err))
return transportationofficeop.NewGetTransportationOfficesOpenInternalServerError(), err
Expand Down
2 changes: 1 addition & 1 deletion pkg/handlers/internalapi/transportation_offices.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (h GetTransportationOfficesHandler) Handle(params transportationofficeop.Ge
return transportationofficeop.NewGetTransportationOfficesForbidden(), noServiceMemberIDErr
}

transportationOffices, err := h.TransportationOfficesFetcher.GetTransportationOffices(appCtx, params.Search)
transportationOffices, err := h.TransportationOfficesFetcher.GetTransportationOffices(appCtx, params.Search, false)
if err != nil {
appCtx.Logger().Error("Error searching for Transportation Offices: ", zap.Error(err))
return transportationofficeop.NewGetTransportationOfficesInternalServerError(), err
Expand Down
18 changes: 9 additions & 9 deletions pkg/services/mocks/TransportationOfficesFetcher.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/services/transportation_office.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

//go:generate mockery --name TransportationOfficesFetcher
type TransportationOfficesFetcher interface {
GetTransportationOffices(appCtx appcontext.AppContext, search string) (*models.TransportationOffices, error)
GetTransportationOffices(appCtx appcontext.AppContext, search string, forPpm bool) (*models.TransportationOffices, error)
GetTransportationOffice(appCtx appcontext.AppContext, transportationOfficeID uuid.UUID, includeOnlyPPMCloseoutOffices bool) (*models.TransportationOffice, error)
GetAllGBLOCs(appCtx appcontext.AppContext) (*models.GBLOCs, error)
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ func (o transportationOfficesFetcher) GetTransportationOffice(appCtx appcontext.
return &transportationOffice, nil
}

func (o transportationOfficesFetcher) GetTransportationOffices(appCtx appcontext.AppContext, search string) (*models.TransportationOffices, error) {
officeList, err := FindTransportationOffice(appCtx, search)
func (o transportationOfficesFetcher) GetTransportationOffices(appCtx appcontext.AppContext, search string, forPpm bool) (*models.TransportationOffices, error) {
officeList, err := FindTransportationOffice(appCtx, search, forPpm)

if err != nil {
switch err {
Expand All @@ -52,22 +52,27 @@ func (o transportationOfficesFetcher) GetTransportationOffices(appCtx appcontext
return &officeList, nil
}

func FindTransportationOffice(appCtx appcontext.AppContext, search string) (models.TransportationOffices, error) {
func FindTransportationOffice(appCtx appcontext.AppContext, search string, forPpm bool) (models.TransportationOffices, error) {
var officeList []models.TransportationOffice

// The % operator filters out strings that are below this similarity threshold
err := appCtx.DB().Q().RawQuery("SET pg_trgm.similarity_threshold = 0.03").Exec()
if err != nil {
return officeList, err
}
providesPPMCloseout := `and provides_ppm_closeout is true`

sqlQuery := `
with names as (select office.id as transportation_office_id, office.name, similarity(office.name, $1) as sim
with names as (select office.id as transportation_office_id, office.name, similarity(office.name, $1) as sim
from transportation_offices as office
where name % $1 and provides_ppm_closeout is true
where name % $1 `
if forPpm {
sqlQuery += providesPPMCloseout
}
sqlQuery += `
order by sim desc
limit 5)
select office.*
select office.*
from names n inner join transportation_offices office on n.transportation_office_id = office.id
group by office.id
order by max(n.sim) desc, office.name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (suite *TransportationOfficeServiceSuite) Test_SearchTransportationOffice()
},
},
}, nil)
office, err := FindTransportationOffice(suite.AppContextForTest(), "LRC Fort Knox")
office, err := FindTransportationOffice(suite.AppContextForTest(), "LRC Fort Knox", true)

suite.NoError(err)
suite.Equal(transportationOffice.Name, office[0].Name)
Expand All @@ -47,7 +47,7 @@ func (suite *TransportationOfficeServiceSuite) Test_SearchTransportationOffice()

func (suite *TransportationOfficeServiceSuite) Test_SearchWithNoTransportationOffices() {

office, err := FindTransportationOffice(suite.AppContextForTest(), "LRC Fort Knox")
office, err := FindTransportationOffice(suite.AppContextForTest(), "LRC Fort Knox", true)
suite.NoError(err)
suite.Len(office, 0)
}
Expand Down Expand Up @@ -81,7 +81,7 @@ func (suite *TransportationOfficeServiceSuite) Test_SortedTransportationOffices(
},
}, nil)

office, err := FindTransportationOffice(suite.AppContextForTest(), "JPPSO")
office, err := FindTransportationOffice(suite.AppContextForTest(), "JPPSO", true)

suite.NoError(err)
suite.Equal(transportationOffice1.Name, office[0].Name)
Expand Down

0 comments on commit 006a124

Please sign in to comment.