/
api.go
126 lines (106 loc) · 5.26 KB
/
api.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package supportapi
import (
"log"
"net/http"
"github.com/benbjohnson/clock"
"github.com/go-openapi/loads"
"github.com/transcom/mymove/pkg/gen/supportapi"
supportops "github.com/transcom/mymove/pkg/gen/supportapi/supportoperations"
"github.com/transcom/mymove/pkg/handlers"
"github.com/transcom/mymove/pkg/services/address"
"github.com/transcom/mymove/pkg/services/fetch"
"github.com/transcom/mymove/pkg/services/ghcrateengine"
"github.com/transcom/mymove/pkg/services/invoice"
move "github.com/transcom/mymove/pkg/services/move"
movetaskorder "github.com/transcom/mymove/pkg/services/move_task_order"
mtoserviceitem "github.com/transcom/mymove/pkg/services/mto_service_item"
mtoshipment "github.com/transcom/mymove/pkg/services/mto_shipment"
paymentrequest "github.com/transcom/mymove/pkg/services/payment_request"
"github.com/transcom/mymove/pkg/services/query"
internalmovetaskorder "github.com/transcom/mymove/pkg/services/support/move_task_order"
)
// NewSupportAPIHandler returns a handler for the Prime API
func NewSupportAPIHandler(handlerConfig handlers.HandlerConfig) http.Handler {
queryBuilder := query.NewQueryBuilder()
moveRouter := move.NewMoveRouter()
shipmentFetcher := mtoshipment.NewMTOShipmentFetcher()
addressCreator := address.NewAddressCreator()
supportSpec, err := loads.Analyzed(supportapi.SwaggerJSON, "")
if err != nil {
log.Fatalln(err)
}
supportAPI := supportops.NewMymoveAPI(supportSpec)
supportAPI.ServeError = handlers.ServeCustomError
supportAPI.MoveTaskOrderListMTOsHandler = ListMTOsHandler{
handlerConfig,
movetaskorder.NewMoveTaskOrderFetcher(),
}
supportAPI.MoveTaskOrderMakeMoveTaskOrderAvailableHandler = MakeMoveTaskOrderAvailableHandlerFunc{
handlerConfig,
movetaskorder.NewMoveTaskOrderUpdater(
queryBuilder,
mtoserviceitem.NewMTOServiceItemCreator(handlerConfig.HHGPlanner(), queryBuilder, moveRouter),
moveRouter,
),
}
supportAPI.MoveTaskOrderHideNonFakeMoveTaskOrdersHandler = HideNonFakeMoveTaskOrdersHandlerFunc{
handlerConfig,
movetaskorder.NewMoveTaskOrderHider(),
}
supportAPI.MoveTaskOrderGetMoveTaskOrderHandler = GetMoveTaskOrderHandlerFunc{
handlerConfig,
movetaskorder.NewMoveTaskOrderFetcher()}
supportAPI.MoveTaskOrderCreateMoveTaskOrderHandler = CreateMoveTaskOrderHandler{
handlerConfig,
internalmovetaskorder.NewInternalMoveTaskOrderCreator(),
}
supportAPI.PaymentRequestUpdatePaymentRequestStatusHandler = UpdatePaymentRequestStatusHandler{
HandlerConfig: handlerConfig,
PaymentRequestStatusUpdater: paymentrequest.NewPaymentRequestStatusUpdater(queryBuilder),
PaymentRequestFetcher: paymentrequest.NewPaymentRequestFetcher(),
}
supportAPI.PaymentRequestListMTOPaymentRequestsHandler = ListMTOPaymentRequestsHandler{
handlerConfig,
}
supportAPI.MtoShipmentUpdateMTOShipmentStatusHandler = UpdateMTOShipmentStatusHandlerFunc{
handlerConfig,
fetch.NewFetcher(queryBuilder),
mtoshipment.NewMTOShipmentStatusUpdater(queryBuilder,
mtoserviceitem.NewMTOServiceItemCreator(handlerConfig.HHGPlanner(), queryBuilder, moveRouter), handlerConfig.HHGPlanner()),
}
supportAPI.MtoServiceItemUpdateMTOServiceItemStatusHandler = UpdateMTOServiceItemStatusHandler{handlerConfig, mtoserviceitem.NewMTOServiceItemUpdater(handlerConfig.HHGPlanner(), queryBuilder, moveRouter, shipmentFetcher, addressCreator)}
supportAPI.WebhookReceiveWebhookNotificationHandler = ReceiveWebhookNotificationHandler{handlerConfig}
supportAPI.PaymentRequestGetPaymentRequestEDIHandler = GetPaymentRequestEDIHandler{
HandlerConfig: handlerConfig,
PaymentRequestFetcher: paymentrequest.NewPaymentRequestFetcher(),
GHCPaymentRequestInvoiceGenerator: invoice.NewGHCPaymentRequestInvoiceGenerator(handlerConfig.ICNSequencer(), clock.New()),
}
supportAPI.PaymentRequestProcessReviewedPaymentRequestsHandler = ProcessReviewedPaymentRequestsHandler{
HandlerConfig: handlerConfig,
PaymentRequestFetcher: paymentrequest.NewPaymentRequestFetcher(),
PaymentRequestStatusUpdater: paymentrequest.NewPaymentRequestStatusUpdater(queryBuilder),
PaymentRequestReviewedFetcher: paymentrequest.NewPaymentRequestReviewedFetcher(),
// Unable to get logger to pass in for the instantiation of
// paymentrequest.InitNewPaymentRequestReviewedProcessor(appCtx.DB(), appCtx.Logger(), true),
// This limitation has come up a few times
// - https://dp3.atlassian.net/browse/MB-2352 (story to address issue)
// - https://ustcdp3.slack.com/archives/CP6F568DC/p1592508325118600
// - https://github.com/transcom/mymove/blob/c42adf61735be8ee8e5e83f41a656206f1e59b9d/pkg/handlers/primeapi/api.go
// As a temporary workaround paymentrequest.InitNewPaymentRequestReviewedProcessor
// is called directly in the handler
}
supportAPI.PaymentRequestRecalculatePaymentRequestHandler = RecalculatePaymentRequestHandler{
HandlerConfig: handlerConfig,
PaymentRequestRecalculator: paymentrequest.NewPaymentRequestRecalculator(
paymentrequest.NewPaymentRequestCreator(
handlerConfig.HHGPlanner(),
ghcrateengine.NewServiceItemPricer(),
),
paymentrequest.NewPaymentRequestStatusUpdater(queryBuilder),
),
}
supportAPI.WebhookCreateWebhookNotificationHandler = CreateWebhookNotificationHandler{
HandlerConfig: handlerConfig,
}
return supportAPI.Serve(nil)
}