Skip to content

Commit

Permalink
Merge branch 'B-19815-Office-Date-Validation' of github.com:transcom/…
Browse files Browse the repository at this point in the history
…mymove into B-19815-Office-Date-Validation
  • Loading branch information
r-mettler committed Aug 28, 2024
2 parents 075875c + 4c23398 commit 06ac0c5
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 71 deletions.
10 changes: 8 additions & 2 deletions pkg/gen/ghcapi/embedded_spec.go

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

7 changes: 5 additions & 2 deletions pkg/gen/ghcmessages/available_office_user.go

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

3 changes: 0 additions & 3 deletions pkg/handlers/ghcapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,6 @@ func NewGhcAPIHandler(handlerConfig handlers.HandlerConfig) *ghcops.MymoveAPI {
order.NewOrderFetcher(),
movelocker.NewMoveUnlocker(),
officeusercreator.NewOfficeUserFetcherPop(),
officeusercreator.NewOfficeUserGblocFetcher(),
}

ghcAPI.QueuesListPrimeMovesHandler = ListPrimeMovesHandler{
Expand All @@ -527,15 +526,13 @@ func NewGhcAPIHandler(handlerConfig handlers.HandlerConfig) *ghcops.MymoveAPI {
paymentrequest.NewPaymentRequestListFetcher(),
movelocker.NewMoveUnlocker(),
officeusercreator.NewOfficeUserFetcherPop(),
officeusercreator.NewOfficeUserGblocFetcher(),
}

ghcAPI.QueuesGetServicesCounselingQueueHandler = GetServicesCounselingQueueHandler{
handlerConfig,
order.NewOrderFetcher(),
movelocker.NewMoveUnlocker(),
officeusercreator.NewOfficeUserFetcherPop(),
officeusercreator.NewOfficeUserGblocFetcher(),
}

ghcAPI.QueuesGetServicesCounselingOriginListHandler = GetServicesCounselingOriginListHandler{
Expand Down
3 changes: 2 additions & 1 deletion pkg/handlers/ghcapi/internal/payloads/model_to_payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -1883,7 +1883,8 @@ func QueueAvailableOfficeUsers(officeUsers []models.OfficeUser) *ghcmessages.Ava
hasSafety := officeUser.User.Privileges.HasPrivilege(models.PrivilegeTypeSafety)

availableOfficeUsers[i] = &ghcmessages.AvailableOfficeUser{
FullName: officeUser.LastName + ", " + officeUser.FirstName,
LastName: officeUser.LastName,
FirstName: officeUser.FirstName,
OfficeUserID: *handlers.FmtUUID(officeUser.ID),
HasSafetyPrivilege: swag.BoolValue(&hasSafety),
}
Expand Down
53 changes: 28 additions & 25 deletions pkg/handlers/ghcapi/queues.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/go-openapi/runtime/middleware"
"github.com/gobuffalo/pop/v6"
"github.com/gofrs/uuid"
"go.uber.org/zap"

"github.com/transcom/mymove/pkg/appcontext"
Expand All @@ -17,7 +18,6 @@ import (
"github.com/transcom/mymove/pkg/models"
"github.com/transcom/mymove/pkg/models/roles"
"github.com/transcom/mymove/pkg/services"
officeuser "github.com/transcom/mymove/pkg/services/office_user"
)

// GetMovesQueueHandler returns the moves for the TOO queue user via GET /queues/moves
Expand All @@ -26,7 +26,6 @@ type GetMovesQueueHandler struct {
services.OrderFetcher
services.MoveUnlocker
services.OfficeUserFetcherPop
services.OfficeUserGblocFetcher
}

// FilterOption defines the type for the functional arguments used for private functions in OrderFetcher
Expand Down Expand Up @@ -92,17 +91,19 @@ func (h GetMovesQueueHandler) Handle(params queues.GetMovesQueueParams) middlewa
return queues.NewGetMovesQueueInternalServerError(), err
}

var gblocErr error
gblocFetcher := officeuser.NewOfficeUserGblocFetcher()
officeUserGbloc, gblocErr := gblocFetcher.FetchGblocForOfficeUser(appCtx, appCtx.Session().OfficeUserID)
if gblocErr != nil {
return queues.NewGetMovesQueueInternalServerError(), gblocErr
var officeUser models.OfficeUser
if appCtx.Session().OfficeUserID != uuid.Nil {
officeUser, err = h.OfficeUserFetcherPop.FetchOfficeUserByID(appCtx, appCtx.Session().OfficeUserID)
if err != nil {
appCtx.Logger().Error("Error retrieving office_user", zap.Error(err))
return queues.NewGetServicesCounselingQueueInternalServerError(), err
}
}

officeUsers, err := h.OfficeUserFetcherPop.FetchOfficeUserByRoleAndGbloc(
officeUsers, err := h.OfficeUserFetcherPop.FetchOfficeUsersByRoleAndOffice(
appCtx,
roles.RoleTypeTOO,
officeUserGbloc,
officeUser.TransportationOfficeID,
)

if err != nil {
Expand Down Expand Up @@ -204,7 +205,6 @@ type GetPaymentRequestsQueueHandler struct {
services.PaymentRequestListFetcher
services.MoveUnlocker
services.OfficeUserFetcherPop
services.OfficeUserGblocFetcher
}

// Handle returns the paginated list of payment requests for the TIO user
Expand Down Expand Up @@ -266,17 +266,19 @@ func (h GetPaymentRequestsQueueHandler) Handle(
return queues.NewGetPaymentRequestsQueueInternalServerError(), err
}

var gblocErr error
gblocFetcher := officeuser.NewOfficeUserGblocFetcher()
officeUserGbloc, gblocErr := gblocFetcher.FetchGblocForOfficeUser(appCtx, appCtx.Session().OfficeUserID)
if gblocErr != nil {
return queues.NewGetPaymentRequestsQueueInternalServerError(), gblocErr
var officeUser models.OfficeUser
if appCtx.Session().OfficeUserID != uuid.Nil {
officeUser, err = h.OfficeUserFetcherPop.FetchOfficeUserByID(appCtx, appCtx.Session().OfficeUserID)
if err != nil {
appCtx.Logger().Error("Error retrieving office_user", zap.Error(err))
return queues.NewGetServicesCounselingQueueInternalServerError(), err
}
}

officeUsers, err := h.OfficeUserFetcherPop.FetchOfficeUserByRoleAndGbloc(
officeUsers, err := h.OfficeUserFetcherPop.FetchOfficeUsersByRoleAndOffice(
appCtx,
roles.RoleTypeTIO,
officeUserGbloc,
officeUser.TransportationOfficeID,
)

if err != nil {
Expand Down Expand Up @@ -327,7 +329,6 @@ type GetServicesCounselingQueueHandler struct {
services.OrderFetcher
services.MoveUnlocker
services.OfficeUserFetcherPop
services.OfficeUserGblocFetcher
}

// Handle returns the paginated list of moves for the services counselor
Expand Down Expand Up @@ -401,17 +402,19 @@ func (h GetServicesCounselingQueueHandler) Handle(
return queues.NewGetServicesCounselingQueueInternalServerError(), err
}

var gblocErr error
gblocFetcher := officeuser.NewOfficeUserGblocFetcher()
officeUserGbloc, gblocErr := gblocFetcher.FetchGblocForOfficeUser(appCtx, appCtx.Session().OfficeUserID)
if gblocErr != nil {
return queues.NewGetServicesCounselingQueueInternalServerError(), gblocErr
var officeUser models.OfficeUser
if appCtx.Session().OfficeUserID != uuid.Nil {
officeUser, err = h.OfficeUserFetcherPop.FetchOfficeUserByID(appCtx, appCtx.Session().OfficeUserID)
if err != nil {
appCtx.Logger().Error("Error retrieving office_user", zap.Error(err))
return queues.NewGetServicesCounselingQueueInternalServerError(), err
}
}

officeUsers, err := h.OfficeUserFetcherPop.FetchOfficeUserByRoleAndGbloc(
officeUsers, err := h.OfficeUserFetcherPop.FetchOfficeUsersByRoleAndOffice(
appCtx,
roles.RoleTypeServicesCounselor,
officeUserGbloc,
officeUser.TransportationOfficeID,
)

if err != nil {
Expand Down
15 changes: 0 additions & 15 deletions pkg/handlers/ghcapi/queues_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ func (suite *HandlerSuite) TestGetMoveQueuesHandler() {
order.NewOrderFetcher(),
mockUnlocker,
officeusercreator.NewOfficeUserFetcherPop(),
officeusercreator.NewOfficeUserGblocFetcher(),
}

// Validate incoming payload: no body to validate
Expand Down Expand Up @@ -208,7 +207,6 @@ func (suite *HandlerSuite) TestGetMoveQueuesHandlerMoveInfo() {
&orderFetcher,
mockUnlocker,
officeusercreator.NewOfficeUserFetcherPop(),
officeusercreator.NewOfficeUserGblocFetcher(),
}

// Validate incoming payload: no body to validate
Expand Down Expand Up @@ -283,7 +281,6 @@ func (suite *HandlerSuite) TestGetMoveQueuesBranchFilter() {
order.NewOrderFetcher(),
mockUnlocker,
officeusercreator.NewOfficeUserFetcherPop(),
officeusercreator.NewOfficeUserGblocFetcher(),
}

// Validate incoming payload: no body to validate
Expand Down Expand Up @@ -372,7 +369,6 @@ func (suite *HandlerSuite) TestGetMoveQueuesHandlerStatuses() {
order.NewOrderFetcher(),
mockUnlocker,
officeusercreator.NewOfficeUserFetcherPop(),
officeusercreator.NewOfficeUserGblocFetcher(),
}

// Validate incoming payload: no body to validate
Expand Down Expand Up @@ -522,7 +518,6 @@ func (suite *HandlerSuite) TestGetMoveQueuesHandlerFilters() {
order.NewOrderFetcher(),
mockUnlocker,
officeusercreator.NewOfficeUserFetcherPop(),
officeusercreator.NewOfficeUserGblocFetcher(),
}

suite.Run("loads results with all STATUSes selected", func() {
Expand Down Expand Up @@ -780,7 +775,6 @@ func (suite *HandlerSuite) TestGetMoveQueuesHandlerCustomerInfoFilters() {
order.NewOrderFetcher(),
mockUnlocker,
officeusercreator.NewOfficeUserFetcherPop(),
officeusercreator.NewOfficeUserGblocFetcher(),
}

suite.Run("returns unfiltered results", func() {
Expand Down Expand Up @@ -927,7 +921,6 @@ func (suite *HandlerSuite) TestGetMoveQueuesHandlerUnauthorizedRole() {
order.NewOrderFetcher(),
mockUnlocker,
officeusercreator.NewOfficeUserFetcherPop(),
officeusercreator.NewOfficeUserGblocFetcher(),
}

// Validate incoming payload: no body to validate
Expand Down Expand Up @@ -959,7 +952,6 @@ func (suite *HandlerSuite) TestGetMoveQueuesHandlerUnauthorizedUser() {
order.NewOrderFetcher(),
mockUnlocker,
officeusercreator.NewOfficeUserFetcherPop(),
officeusercreator.NewOfficeUserGblocFetcher(),
}

// Validate incoming payload: no body to validate
Expand Down Expand Up @@ -1012,7 +1004,6 @@ func (suite *HandlerSuite) TestGetMoveQueuesHandlerEmptyResults() {
order.NewOrderFetcher(),
mockUnlocker,
officeusercreator.NewOfficeUserFetcherPop(),
officeusercreator.NewOfficeUserGblocFetcher(),
}

// Validate incoming payload: no body to validate
Expand Down Expand Up @@ -1063,7 +1054,6 @@ func (suite *HandlerSuite) TestGetPaymentRequestsQueueHandler() {
paymentrequest.NewPaymentRequestListFetcher(),
mockUnlocker,
officeusercreator.NewOfficeUserFetcherPop(),
officeusercreator.NewOfficeUserGblocFetcher(),
}

// Validate incoming payload: no body to validate
Expand Down Expand Up @@ -1142,7 +1132,6 @@ func (suite *HandlerSuite) TestGetPaymentRequestsQueueSubmittedAtFilter() {
paymentrequest.NewPaymentRequestListFetcher(),
mockUnlocker,
officeusercreator.NewOfficeUserFetcherPop(),
officeusercreator.NewOfficeUserGblocFetcher(),
}
suite.Run("returns unfiltered results", func() {
params := queues.GetPaymentRequestsQueueParams{
Expand Down Expand Up @@ -1223,7 +1212,6 @@ func (suite *HandlerSuite) TestGetPaymentRequestsQueueHandlerUnauthorizedRole()
paymentrequest.NewPaymentRequestListFetcher(),
mockUnlocker,
officeusercreator.NewOfficeUserFetcherPop(),
officeusercreator.NewOfficeUserGblocFetcher(),
}

// Validate incoming payload: no body to validate
Expand Down Expand Up @@ -1260,7 +1248,6 @@ func (suite *HandlerSuite) TestGetPaymentRequestsQueueHandlerServerError() {
&paymentRequestListFetcher,
mockUnlocker,
officeusercreator.NewOfficeUserFetcherPop(),
officeusercreator.NewOfficeUserGblocFetcher(),
}

// Validate incoming payload: no body to validate
Expand Down Expand Up @@ -1298,7 +1285,6 @@ func (suite *HandlerSuite) TestGetPaymentRequestsQueueHandlerEmptyResults() {
&paymentRequestListFetcher,
mockUnlocker,
officeusercreator.NewOfficeUserFetcherPop(),
officeusercreator.NewOfficeUserGblocFetcher(),
}

// Validate incoming payload: no body to validate
Expand Down Expand Up @@ -1505,7 +1491,6 @@ func (suite *HandlerSuite) makeServicesCounselingSubtestData() (subtestData *ser
order.NewOrderFetcher(),
mockUnlocker,
officeusercreator.NewOfficeUserFetcherPop(),
officeusercreator.NewOfficeUserGblocFetcher(),
}

return subtestData
Expand Down
18 changes: 9 additions & 9 deletions pkg/services/mocks/OfficeUserFetcherPop.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/office_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type OfficeUserFetcher interface {
//go:generate mockery --name OfficeUserFetcherPop
type OfficeUserFetcherPop interface {
FetchOfficeUserByID(appCtx appcontext.AppContext, id uuid.UUID) (models.OfficeUser, error)
FetchOfficeUserByRoleAndGbloc(appCtx appcontext.AppContext, role roles.RoleType, gbloc string) ([]models.OfficeUser, error)
FetchOfficeUsersByRoleAndOffice(appCtx appcontext.AppContext, role roles.RoleType, officeID uuid.UUID) ([]models.OfficeUser, error)
}

// OfficeUserGblocFetcher is the exported interface for fetching the GBLOC of the
Expand Down
6 changes: 3 additions & 3 deletions pkg/services/office_user/office_user_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (o *officeUserFetcherPop) FetchOfficeUserByID(appCtx appcontext.AppContext,
}

// Fetch office users of the same role within a gbloc, for assignment purposes
func (o *officeUserFetcherPop) FetchOfficeUserByRoleAndGbloc(appCtx appcontext.AppContext, role roles.RoleType, gbloc string) ([]models.OfficeUser, error) {
func (o *officeUserFetcherPop) FetchOfficeUsersByRoleAndOffice(appCtx appcontext.AppContext, role roles.RoleType, officeID uuid.UUID) ([]models.OfficeUser, error) {
var officeUsers []models.OfficeUser

err := appCtx.DB().EagerPreload(
Expand All @@ -70,9 +70,9 @@ func (o *officeUserFetcherPop) FetchOfficeUserByRoleAndGbloc(appCtx appcontext.A
Join("users", "users.id = office_users.user_id").
Join("users_roles", "users.id = users_roles.user_id").
Join("roles", "users_roles.role_id = roles.id").
Join("transportation_offices", "office_users.transportation_office_id = transportation_offices.id").
Where("gbloc = ?", gbloc).
Where("transportation_office_id = ?", officeID).
Where("role_type = ?", role).
Where("users_roles.deleted_at IS NULL").
Where("office_users.active = TRUE").
Order("last_name asc").
All(&officeUsers)
Expand Down
Loading

0 comments on commit 06ac0c5

Please sign in to comment.