Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

B 20493 int #13265

Merged
merged 10 commits into from
Jul 19, 2024
Merged

B 20493 int #13265

merged 10 commits into from
Jul 19, 2024

Conversation

deandreJones
Copy link
Contributor

B-20493

Summary

Verification Steps for the Author

These are to be checked by the author.

  • Tested in the Experimental environment (for changes to containers, app startup, or connection to data stores)
  • Have the Agility acceptance criteria been met for this change?

Verification Steps for Reviewers

These are to be checked by a reviewer.

  • Has the branch been pulled in and checked out?
  • Have the BL acceptance criteria been met for this change?
  • Was the CircleCI build successful?
  • Has the code been reviewed from a standards and best practices point of view?

Setup to Run the Code

How to test

  1. Access the Office app
  2. Click Request Account
  3. For this test- we want to be able to select all available transportation offiices- even those that don't office ppm_closeout- , JPPSO Southeast (CNNQ) is one example, where before this change- it was not able to be selected, after this change it is able to be selected

Backend

Screenshots

image

@deandreJones deandreJones requested a review from a team as a code owner July 18, 2024 14:20
Copy link
Contributor

@danieljordan-caci danieljordan-caci left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need you to clarify some things with Dan before signing off or doing additional work.

Comment on lines 64 to 70
sqlQuery := `
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
order by sim desc
limit 5)
select office.*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I know this works, but I have some reservations.

This is also used for customers when searching for transpo offices in /pkg/handlers/internalapi/transportation_offices.go:54:

transportationOffices, err := h.TransportationOfficesFetcher.GetTransportationOffices(appCtx, params.Search)
			if err != nil {
				appCtx.Logger().Error("Error searching for Transportation Offices: ", zap.Error(err))
				return transportationofficeop.NewGetTransportationOfficesInternalServerError(), err
			}

and...

This is also used for customers when searching for transpo offices in /pkg/handlers/ghcapi/transportation_offices.go:23:

transportationOffices, err := h.TransportationOfficesFetcher.GetTransportationOffices(appCtx, params.Search)
			if err != nil {
				appCtx.Logger().Error("Error searching for Transportation Offices: ", zap.Error(err))
				return transportationofficeop.NewGetTransportationOfficesInternalServerError(), err
			}

So I think that if that is fine for customers and office users inside of the app to see all transpo offices, then we can leave this.

If not, then we should probably create a new service object that only this open handler uses. Should prob ask Dan.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after some research- this endpoint can't be used, will have to create anew one or- use the admin api

image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can just create a new service object that the handler calls. Just copy over what's in pkg/services/transportation_office/transportation_office_fetcher.go:

func (o transportationOfficesFetcher) GetTransportationOfficesForRequestedOfficeUsers(appCtx appcontext.AppContext, search string) (*models.TransportationOffices, error) {
	officeList, err := FindTransportationOfficeForRequestedOfficeUsers(appCtx, search)

	if err != nil {
		switch err {
		case sql.ErrNoRows:
			return &officeList, apperror.NewNotFoundError(uuid.Nil, "Search string: "+search)
		default:
			return &officeList, err
		}
	}

	return &officeList, nil
}

func FindTransportationOfficeForRequestedOfficeUsers(appCtx appcontext.AppContext, search string) (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
	}

	sqlQuery := `
	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
		order by sim desc
        limit 5)
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
        limit 5`
	query := appCtx.DB().Q().RawQuery(sqlQuery, search)
	if err := query.All(&officeList); err != nil {
		if errors.Cause(err).Error() != models.RecordNotFoundErrorString {
			return officeList, err
		}
	}
	for i := range officeList {
		err := appCtx.DB().Load(&officeList[i], "Address")
		if err != nil {
			return officeList, err
		}
	}
	return officeList, nil
}

Bing bang boom.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like copied code- I prefer to make the code more flexible for multiple use

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine by me! Your solution looks good!

@deandreJones deandreJones reopened this Jul 19, 2024
@danieljordan-caci danieljordan-caci added Mountain Movers Movin' Mountains 1 Sprint at a time INTEGRATION Slated for Integration Testing labels Jul 19, 2024
@danieljordan-caci
Copy link
Contributor

You just not putting labels on your PRs now, boss? :)

Copy link
Contributor

@traskowskycaci traskowskycaci left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Query results look good!

May need a make mocks_generate on your branch

@deandreJones
Copy link
Contributor Author

You just not putting labels on your PRs now, boss? :)

I never claimed to be perfect...

@deandreJones
Copy link
Contributor Author

Query results look good!

May need a make mocks_generate on your branch

already did

Copy link
Contributor

@danieljordan-caci danieljordan-caci left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nailed it!

@deandreJones deandreJones merged commit b048057 into integrationTesting Jul 19, 2024
30 checks passed
@deandreJones deandreJones deleted the B-20493-INT branch July 19, 2024 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
INTEGRATION Slated for Integration Testing Mountain Movers Movin' Mountains 1 Sprint at a time
Development

Successfully merging this pull request may close these issues.

3 participants