diff --git a/pkg/gen/primeapi/embedded_spec.go b/pkg/gen/primeapi/embedded_spec.go index de35a7e58a8..47c78bb9a8a 100644 --- a/pkg/gen/primeapi/embedded_spec.go +++ b/pkg/gen/primeapi/embedded_spec.go @@ -642,7 +642,7 @@ func init() { } }, "patch": { - "description": "Updates an existing shipment for a move.\n\nNote that there are some restrictions on nested objects:\n\n* Service items: You cannot add or update service items using this endpoint. Please use [createMTOServiceItem](#operation/createMTOServiceItem) and [updateMTOServiceItem](#operation/updateMTOServiceItem) instead.\n* Agents: You cannot add or update agents using this endpoint. Please use [createMTOAgent](#operation/createMTOAgent) and [updateMTOAgent](#operation/updateMTOAgent) instead.\n* Addresses: You can add new addresses using this endpoint (and must use this endpoint to do so), but you cannot update existing ones. Please use [updateMTOShipmentAddress](#operation/updateMTOShipmentAddress) instead.\n\nThese restrictions are due to our [optimistic locking/concurrency control](https://transcom.github.io/mymove-docs/docs/dev/contributing/backend/use-optimistic-locking) mechanism.\n\nNote that some fields cannot be manually changed but will still be updated automatically, such as ` + "`" + `primeEstimatedWeightRecordedDate` + "`" + ` and ` + "`" + `requiredDeliveryDate` + "`" + `.\n", + "description": "_[Deprecated: sunset on August 5th, 2024]_ This endpoint is deprecated and will be removed in a future version.\nPlease use the new endpoint at ` + "`" + `/prime/v2/updateMTOShipment` + "`" + ` instead.\n\n**DEPRECATION ON AUGUST 5TH, 2024**\nFollowing deprecation, there is an edge case scenario where a PPM shipment with no addresses could be updated and it would also update the final destination SIT address\nfor SIT service items. This edge case has been removed as you should not be able to update items using this endpoint. Third-party APIs have confirmed they will require\ndeprecation for this change.\n\nUpdates an existing shipment for a move.\n\nNote that there are some restrictions on nested objects:\n\n* Service items: You cannot add or update service items using this endpoint. Please use [createMTOServiceItem](#operation/createMTOServiceItem) and [updateMTOServiceItem](#operation/updateMTOServiceItem) instead.\n* Agents: You cannot add or update agents using this endpoint. Please use [createMTOAgent](#operation/createMTOAgent) and [updateMTOAgent](#operation/updateMTOAgent) instead.\n* Addresses: You can add new addresses using this endpoint (and must use this endpoint to do so), but you cannot update existing ones. Please use [updateMTOShipmentAddress](#operation/updateMTOShipmentAddress) instead.\n\nThese restrictions are due to our [optimistic locking/concurrency control](https://transcom.github.io/mymove-docs/docs/dev/contributing/backend/use-optimistic-locking) mechanism.\n\nNote that some fields cannot be manually changed but will still be updated automatically, such as ` + "`" + `primeEstimatedWeightRecordedDate` + "`" + ` and ` + "`" + `requiredDeliveryDate` + "`" + `.\n", "consumes": [ "application/json" ], @@ -5483,7 +5483,7 @@ func init() { } }, "patch": { - "description": "Updates an existing shipment for a move.\n\nNote that there are some restrictions on nested objects:\n\n* Service items: You cannot add or update service items using this endpoint. Please use [createMTOServiceItem](#operation/createMTOServiceItem) and [updateMTOServiceItem](#operation/updateMTOServiceItem) instead.\n* Agents: You cannot add or update agents using this endpoint. Please use [createMTOAgent](#operation/createMTOAgent) and [updateMTOAgent](#operation/updateMTOAgent) instead.\n* Addresses: You can add new addresses using this endpoint (and must use this endpoint to do so), but you cannot update existing ones. Please use [updateMTOShipmentAddress](#operation/updateMTOShipmentAddress) instead.\n\nThese restrictions are due to our [optimistic locking/concurrency control](https://transcom.github.io/mymove-docs/docs/dev/contributing/backend/use-optimistic-locking) mechanism.\n\nNote that some fields cannot be manually changed but will still be updated automatically, such as ` + "`" + `primeEstimatedWeightRecordedDate` + "`" + ` and ` + "`" + `requiredDeliveryDate` + "`" + `.\n", + "description": "_[Deprecated: sunset on August 5th, 2024]_ This endpoint is deprecated and will be removed in a future version.\nPlease use the new endpoint at ` + "`" + `/prime/v2/updateMTOShipment` + "`" + ` instead.\n\n**DEPRECATION ON AUGUST 5TH, 2024**\nFollowing deprecation, there is an edge case scenario where a PPM shipment with no addresses could be updated and it would also update the final destination SIT address\nfor SIT service items. This edge case has been removed as you should not be able to update items using this endpoint. Third-party APIs have confirmed they will require\ndeprecation for this change.\n\nUpdates an existing shipment for a move.\n\nNote that there are some restrictions on nested objects:\n\n* Service items: You cannot add or update service items using this endpoint. Please use [createMTOServiceItem](#operation/createMTOServiceItem) and [updateMTOServiceItem](#operation/updateMTOServiceItem) instead.\n* Agents: You cannot add or update agents using this endpoint. Please use [createMTOAgent](#operation/createMTOAgent) and [updateMTOAgent](#operation/updateMTOAgent) instead.\n* Addresses: You can add new addresses using this endpoint (and must use this endpoint to do so), but you cannot update existing ones. Please use [updateMTOShipmentAddress](#operation/updateMTOShipmentAddress) instead.\n\nThese restrictions are due to our [optimistic locking/concurrency control](https://transcom.github.io/mymove-docs/docs/dev/contributing/backend/use-optimistic-locking) mechanism.\n\nNote that some fields cannot be manually changed but will still be updated automatically, such as ` + "`" + `primeEstimatedWeightRecordedDate` + "`" + ` and ` + "`" + `requiredDeliveryDate` + "`" + `.\n", "consumes": [ "application/json" ], diff --git a/pkg/gen/primeapi/primeoperations/mto_shipment/update_m_t_o_shipment.go b/pkg/gen/primeapi/primeoperations/mto_shipment/update_m_t_o_shipment.go index f1effe18a55..2687dc61066 100644 --- a/pkg/gen/primeapi/primeoperations/mto_shipment/update_m_t_o_shipment.go +++ b/pkg/gen/primeapi/primeoperations/mto_shipment/update_m_t_o_shipment.go @@ -34,6 +34,14 @@ func NewUpdateMTOShipment(ctx *middleware.Context, handler UpdateMTOShipmentHand updateMTOShipment +_[Deprecated: sunset on August 5th, 2024]_ This endpoint is deprecated and will be removed in a future version. +Please use the new endpoint at `/prime/v2/updateMTOShipment` instead. + +**DEPRECATION ON AUGUST 5TH, 2024** +Following deprecation, there is an edge case scenario where a PPM shipment with no addresses could be updated and it would also update the final destination SIT address +for SIT service items. This edge case has been removed as you should not be able to update items using this endpoint. Third-party APIs have confirmed they will require +deprecation for this change. + Updates an existing shipment for a move. Note that there are some restrictions on nested objects: diff --git a/pkg/gen/primeclient/mto_shipment/mto_shipment_client.go b/pkg/gen/primeclient/mto_shipment/mto_shipment_client.go index a2be987d118..a9af70964aa 100644 --- a/pkg/gen/primeclient/mto_shipment/mto_shipment_client.go +++ b/pkg/gen/primeclient/mto_shipment/mto_shipment_client.go @@ -297,7 +297,16 @@ func (a *Client) UpdateMTOAgent(params *UpdateMTOAgentParams, opts ...ClientOpti /* UpdateMTOShipment updates m t o shipment - Updates an existing shipment for a move. + _[Deprecated: sunset on August 5th, 2024]_ This endpoint is deprecated and will be removed in a future version. + +Please use the new endpoint at `/prime/v2/updateMTOShipment` instead. + +**DEPRECATION ON AUGUST 5TH, 2024** +Following deprecation, there is an edge case scenario where a PPM shipment with no addresses could be updated and it would also update the final destination SIT address +for SIT service items. This edge case has been removed as you should not be able to update items using this endpoint. Third-party APIs have confirmed they will require +deprecation for this change. + +Updates an existing shipment for a move. Note that there are some restrictions on nested objects: diff --git a/pkg/gen/primev2api/configure_mymove.go b/pkg/gen/primev2api/configure_mymove.go index 3adefc12fa5..9110ba549e9 100644 --- a/pkg/gen/primev2api/configure_mymove.go +++ b/pkg/gen/primev2api/configure_mymove.go @@ -49,6 +49,11 @@ func configureAPI(api *primev2operations.MymoveAPI) http.Handler { return middleware.NotImplemented("operation move_task_order.GetMoveTaskOrder has not yet been implemented") }) } + if api.MtoShipmentUpdateMTOShipmentHandler == nil { + api.MtoShipmentUpdateMTOShipmentHandler = mto_shipment.UpdateMTOShipmentHandlerFunc(func(params mto_shipment.UpdateMTOShipmentParams) middleware.Responder { + return middleware.NotImplemented("operation mto_shipment.UpdateMTOShipment has not yet been implemented") + }) + } api.PreServerShutdown = func() {} diff --git a/pkg/gen/primev2api/embedded_spec.go b/pkg/gen/primev2api/embedded_spec.go index b656dbecae8..13900e31f60 100644 --- a/pkg/gen/primev2api/embedded_spec.go +++ b/pkg/gen/primev2api/embedded_spec.go @@ -194,6 +194,134 @@ func init() { } } } + }, + "/mto-shipments/{mtoShipmentID}": { + "patch": { + "description": "Updates an existing shipment for a move.\n\nNote that there are some restrictions on nested objects:\n\n* Service items: You cannot add or update service items using this endpoint. Please use [createMTOServiceItem](#operation/createMTOServiceItem) and [updateMTOServiceItem](#operation/updateMTOServiceItem) instead.\n* Agents: You cannot add or update agents using this endpoint. Please use [createMTOAgent](#operation/createMTOAgent) and [updateMTOAgent](#operation/updateMTOAgent) instead.\n* Addresses: You can add new addresses using this endpoint (and must use this endpoint to do so), but you cannot update existing ones. Please use [updateMTOShipmentAddress](#operation/updateMTOShipmentAddress) instead.\n\nThese restrictions are due to our [optimistic locking/concurrency control](https://transcom.github.io/mymove-docs/docs/dev/contributing/backend/use-optimistic-locking) mechanism.\n\nNote that some fields cannot be manually changed but will still be updated automatically, such as ` + "`" + `primeEstimatedWeightRecordedDate` + "`" + ` and ` + "`" + `requiredDeliveryDate` + "`" + `.\n", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "mtoShipment" + ], + "summary": "updateMTOShipment", + "operationId": "updateMTOShipment", + "parameters": [ + { + "type": "string", + "format": "uuid", + "description": "UUID of the shipment being updated.", + "name": "mtoShipmentID", + "in": "path", + "required": true + }, + { + "x-examples": { + "application/json": { + "hhg": { + "summary": "HHG", + "value": { + "actualPickupDate": "2022-12-29", + "destinationAddress": { + "city": "Great Bend", + "postalCode": "13643", + "state": "NY", + "streetAddress1": "6622 Airport Way S", + "streetAddress2": "#1430" + }, + "firstAvailableDeliveryDate": "2023-01-04", + "pointOfContact": "peyton.wing@example.com", + "primeActualWeight": 4500, + "primeEstimatedWeight": 4250, + "scheduledPickupDate": "2022-12-30" + } + }, + "nts": { + "summary": "NTS", + "value": { + "actualPickupDate": "2022-12-29", + "actualWeight": 4500, + "counselorRemarks": "Beware of dogs on property", + "estimatedWeight": 4250, + "moveTaskOrderId": "5691c951-c35c-49a8-a1d5-a4b7ea7b7ad8", + "scheduledPickupDate": "2022-12-30" + } + }, + "nts-r": { + "summary": "NTS Release", + "value": { + "destinationAddress": { + "city": "San Antonio", + "postalCode": "78245", + "state": "TX", + "streetAddress1": "812 S 129th Street" + }, + "moveTaskOrderId": "5691c951-c35c-49a8-a1d5-a4b7ea7b7ad8", + "ntsRecordedWeight": 4500 + } + }, + "ppm": { + "summary": "PPM", + "value": { + "moveTaskOrderId": "5691c951-c35c-49a8-a1d5-a4b7ea7b7ad8", + "ppmShipment": { + "hasProGear": true, + "proGearWeight": 830, + "sitEstimatedDepartureDate": "2022-10-13", + "sitEstimatedEntryDate": "2022-10-06", + "sitEstimatedWeight": 1760, + "sitExpected": true, + "sitLocation": "DESTINATION", + "spouseProGearWeight": 366 + } + } + } + } + }, + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/UpdateMTOShipment" + } + }, + { + "$ref": "#/parameters/ifMatch" + } + ], + "responses": { + "200": { + "description": "Successfully updated the MTO shipment.", + "schema": { + "$ref": "#/definitions/MTOShipment" + } + }, + "400": { + "$ref": "#/responses/InvalidRequest" + }, + "401": { + "$ref": "#/responses/PermissionDenied" + }, + "403": { + "$ref": "#/responses/PermissionDenied" + }, + "404": { + "$ref": "#/responses/NotFound" + }, + "412": { + "$ref": "#/responses/PreconditionFailed" + }, + "422": { + "$ref": "#/responses/UnprocessableEntity" + }, + "500": { + "$ref": "#/responses/ServerError" + } + } + } } }, "definitions": { @@ -3217,6 +3345,15 @@ func init() { ] } }, + "parameters": { + "ifMatch": { + "type": "string", + "description": "Optimistic locking is implemented via the ` + "`" + `If-Match` + "`" + ` header. If the ETag header does not match the value of the resource on the server, the server rejects the change with a ` + "`" + `412 Precondition Failed` + "`" + ` error.\n", + "name": "If-Match", + "in": "header", + "required": true + } + }, "responses": { "InvalidRequest": { "description": "The request payload is invalid.", @@ -3236,6 +3373,12 @@ func init() { "$ref": "#/definitions/ClientError" } }, + "PreconditionFailed": { + "description": "Precondition failed, likely due to a stale eTag (If-Match). Fetch the request again to get the updated eTag value.", + "schema": { + "$ref": "#/definitions/ClientError" + } + }, "ServerError": { "description": "A server error occurred.", "schema": { @@ -3470,6 +3613,159 @@ func init() { } } } + }, + "/mto-shipments/{mtoShipmentID}": { + "patch": { + "description": "Updates an existing shipment for a move.\n\nNote that there are some restrictions on nested objects:\n\n* Service items: You cannot add or update service items using this endpoint. Please use [createMTOServiceItem](#operation/createMTOServiceItem) and [updateMTOServiceItem](#operation/updateMTOServiceItem) instead.\n* Agents: You cannot add or update agents using this endpoint. Please use [createMTOAgent](#operation/createMTOAgent) and [updateMTOAgent](#operation/updateMTOAgent) instead.\n* Addresses: You can add new addresses using this endpoint (and must use this endpoint to do so), but you cannot update existing ones. Please use [updateMTOShipmentAddress](#operation/updateMTOShipmentAddress) instead.\n\nThese restrictions are due to our [optimistic locking/concurrency control](https://transcom.github.io/mymove-docs/docs/dev/contributing/backend/use-optimistic-locking) mechanism.\n\nNote that some fields cannot be manually changed but will still be updated automatically, such as ` + "`" + `primeEstimatedWeightRecordedDate` + "`" + ` and ` + "`" + `requiredDeliveryDate` + "`" + `.\n", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "mtoShipment" + ], + "summary": "updateMTOShipment", + "operationId": "updateMTOShipment", + "parameters": [ + { + "type": "string", + "format": "uuid", + "description": "UUID of the shipment being updated.", + "name": "mtoShipmentID", + "in": "path", + "required": true + }, + { + "x-examples": { + "application/json": { + "hhg": { + "summary": "HHG", + "value": { + "actualPickupDate": "2022-12-29", + "destinationAddress": { + "city": "Great Bend", + "postalCode": "13643", + "state": "NY", + "streetAddress1": "6622 Airport Way S", + "streetAddress2": "#1430" + }, + "firstAvailableDeliveryDate": "2023-01-04", + "pointOfContact": "peyton.wing@example.com", + "primeActualWeight": 4500, + "primeEstimatedWeight": 4250, + "scheduledPickupDate": "2022-12-30" + } + }, + "nts": { + "summary": "NTS", + "value": { + "actualPickupDate": "2022-12-29", + "actualWeight": 4500, + "counselorRemarks": "Beware of dogs on property", + "estimatedWeight": 4250, + "moveTaskOrderId": "5691c951-c35c-49a8-a1d5-a4b7ea7b7ad8", + "scheduledPickupDate": "2022-12-30" + } + }, + "nts-r": { + "summary": "NTS Release", + "value": { + "destinationAddress": { + "city": "San Antonio", + "postalCode": "78245", + "state": "TX", + "streetAddress1": "812 S 129th Street" + }, + "moveTaskOrderId": "5691c951-c35c-49a8-a1d5-a4b7ea7b7ad8", + "ntsRecordedWeight": 4500 + } + }, + "ppm": { + "summary": "PPM", + "value": { + "moveTaskOrderId": "5691c951-c35c-49a8-a1d5-a4b7ea7b7ad8", + "ppmShipment": { + "hasProGear": true, + "proGearWeight": 830, + "sitEstimatedDepartureDate": "2022-10-13", + "sitEstimatedEntryDate": "2022-10-06", + "sitEstimatedWeight": 1760, + "sitExpected": true, + "sitLocation": "DESTINATION", + "spouseProGearWeight": 366 + } + } + } + } + }, + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/UpdateMTOShipment" + } + }, + { + "type": "string", + "description": "Optimistic locking is implemented via the ` + "`" + `If-Match` + "`" + ` header. If the ETag header does not match the value of the resource on the server, the server rejects the change with a ` + "`" + `412 Precondition Failed` + "`" + ` error.\n", + "name": "If-Match", + "in": "header", + "required": true + } + ], + "responses": { + "200": { + "description": "Successfully updated the MTO shipment.", + "schema": { + "$ref": "#/definitions/MTOShipment" + } + }, + "400": { + "description": "The request payload is invalid.", + "schema": { + "$ref": "#/definitions/ClientError" + } + }, + "401": { + "description": "The request was denied.", + "schema": { + "$ref": "#/definitions/ClientError" + } + }, + "403": { + "description": "The request was denied.", + "schema": { + "$ref": "#/definitions/ClientError" + } + }, + "404": { + "description": "The requested resource wasn't found.", + "schema": { + "$ref": "#/definitions/ClientError" + } + }, + "412": { + "description": "Precondition failed, likely due to a stale eTag (If-Match). Fetch the request again to get the updated eTag value.", + "schema": { + "$ref": "#/definitions/ClientError" + } + }, + "422": { + "description": "The request was unprocessable, likely due to bad input from the requester.", + "schema": { + "$ref": "#/definitions/ValidationError" + } + }, + "500": { + "description": "A server error occurred.", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } } }, "definitions": { @@ -6495,6 +6791,15 @@ func init() { ] } }, + "parameters": { + "ifMatch": { + "type": "string", + "description": "Optimistic locking is implemented via the ` + "`" + `If-Match` + "`" + ` header. If the ETag header does not match the value of the resource on the server, the server rejects the change with a ` + "`" + `412 Precondition Failed` + "`" + ` error.\n", + "name": "If-Match", + "in": "header", + "required": true + } + }, "responses": { "InvalidRequest": { "description": "The request payload is invalid.", @@ -6514,6 +6819,12 @@ func init() { "$ref": "#/definitions/ClientError" } }, + "PreconditionFailed": { + "description": "Precondition failed, likely due to a stale eTag (If-Match). Fetch the request again to get the updated eTag value.", + "schema": { + "$ref": "#/definitions/ClientError" + } + }, "ServerError": { "description": "A server error occurred.", "schema": { diff --git a/pkg/gen/primev2api/primev2operations/mto_shipment/update_m_t_o_shipment.go b/pkg/gen/primev2api/primev2operations/mto_shipment/update_m_t_o_shipment.go new file mode 100644 index 00000000000..f1effe18a55 --- /dev/null +++ b/pkg/gen/primev2api/primev2operations/mto_shipment/update_m_t_o_shipment.go @@ -0,0 +1,68 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package mto_shipment + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime/middleware" +) + +// UpdateMTOShipmentHandlerFunc turns a function with the right signature into a update m t o shipment handler +type UpdateMTOShipmentHandlerFunc func(UpdateMTOShipmentParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn UpdateMTOShipmentHandlerFunc) Handle(params UpdateMTOShipmentParams) middleware.Responder { + return fn(params) +} + +// UpdateMTOShipmentHandler interface for that can handle valid update m t o shipment params +type UpdateMTOShipmentHandler interface { + Handle(UpdateMTOShipmentParams) middleware.Responder +} + +// NewUpdateMTOShipment creates a new http.Handler for the update m t o shipment operation +func NewUpdateMTOShipment(ctx *middleware.Context, handler UpdateMTOShipmentHandler) *UpdateMTOShipment { + return &UpdateMTOShipment{Context: ctx, Handler: handler} +} + +/* + UpdateMTOShipment swagger:route PATCH /mto-shipments/{mtoShipmentID} mtoShipment updateMTOShipment + +updateMTOShipment + +Updates an existing shipment for a move. + +Note that there are some restrictions on nested objects: + +* Service items: You cannot add or update service items using this endpoint. Please use [createMTOServiceItem](#operation/createMTOServiceItem) and [updateMTOServiceItem](#operation/updateMTOServiceItem) instead. +* Agents: You cannot add or update agents using this endpoint. Please use [createMTOAgent](#operation/createMTOAgent) and [updateMTOAgent](#operation/updateMTOAgent) instead. +* Addresses: You can add new addresses using this endpoint (and must use this endpoint to do so), but you cannot update existing ones. Please use [updateMTOShipmentAddress](#operation/updateMTOShipmentAddress) instead. + +These restrictions are due to our [optimistic locking/concurrency control](https://transcom.github.io/mymove-docs/docs/dev/contributing/backend/use-optimistic-locking) mechanism. + +Note that some fields cannot be manually changed but will still be updated automatically, such as `primeEstimatedWeightRecordedDate` and `requiredDeliveryDate`. +*/ +type UpdateMTOShipment struct { + Context *middleware.Context + Handler UpdateMTOShipmentHandler +} + +func (o *UpdateMTOShipment) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + *r = *rCtx + } + var Params = NewUpdateMTOShipmentParams() + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params) // actually handle the request + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/pkg/gen/primev2api/primev2operations/mto_shipment/update_m_t_o_shipment_parameters.go b/pkg/gen/primev2api/primev2operations/mto_shipment/update_m_t_o_shipment_parameters.go new file mode 100644 index 00000000000..3a431676a7e --- /dev/null +++ b/pkg/gen/primev2api/primev2operations/mto_shipment/update_m_t_o_shipment_parameters.go @@ -0,0 +1,158 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package mto_shipment + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "io" + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/validate" + + "github.com/transcom/mymove/pkg/gen/primev2messages" +) + +// NewUpdateMTOShipmentParams creates a new UpdateMTOShipmentParams object +// +// There are no default values defined in the spec. +func NewUpdateMTOShipmentParams() UpdateMTOShipmentParams { + + return UpdateMTOShipmentParams{} +} + +// UpdateMTOShipmentParams contains all the bound params for the update m t o shipment operation +// typically these are obtained from a http.Request +// +// swagger:parameters updateMTOShipment +type UpdateMTOShipmentParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /*Optimistic locking is implemented via the `If-Match` header. If the ETag header does not match the value of the resource on the server, the server rejects the change with a `412 Precondition Failed` error. + + Required: true + In: header + */ + IfMatch string + /* + Required: true + In: body + */ + Body *primev2messages.UpdateMTOShipment + /*UUID of the shipment being updated. + Required: true + In: path + */ + MtoShipmentID strfmt.UUID +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewUpdateMTOShipmentParams() beforehand. +func (o *UpdateMTOShipmentParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + if err := o.bindIfMatch(r.Header[http.CanonicalHeaderKey("If-Match")], true, route.Formats); err != nil { + res = append(res, err) + } + + if runtime.HasBody(r) { + defer r.Body.Close() + var body primev2messages.UpdateMTOShipment + if err := route.Consumer.Consume(r.Body, &body); err != nil { + if err == io.EOF { + res = append(res, errors.Required("body", "body", "")) + } else { + res = append(res, errors.NewParseError("body", "body", "", err)) + } + } else { + // validate body object + if err := body.Validate(route.Formats); err != nil { + res = append(res, err) + } + + ctx := validate.WithOperationRequest(r.Context()) + if err := body.ContextValidate(ctx, route.Formats); err != nil { + res = append(res, err) + } + + if len(res) == 0 { + o.Body = &body + } + } + } else { + res = append(res, errors.Required("body", "body", "")) + } + + rMtoShipmentID, rhkMtoShipmentID, _ := route.Params.GetOK("mtoShipmentID") + if err := o.bindMtoShipmentID(rMtoShipmentID, rhkMtoShipmentID, route.Formats); err != nil { + res = append(res, err) + } + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// bindIfMatch binds and validates parameter IfMatch from header. +func (o *UpdateMTOShipmentParams) bindIfMatch(rawData []string, hasKey bool, formats strfmt.Registry) error { + if !hasKey { + return errors.Required("If-Match", "header", rawData) + } + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: true + + if err := validate.RequiredString("If-Match", "header", raw); err != nil { + return err + } + o.IfMatch = raw + + return nil +} + +// bindMtoShipmentID binds and validates parameter MtoShipmentID from path. +func (o *UpdateMTOShipmentParams) bindMtoShipmentID(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: true + // Parameter is provided by construction from the route + + // Format: uuid + value, err := formats.Parse("uuid", raw) + if err != nil { + return errors.InvalidType("mtoShipmentID", "path", "strfmt.UUID", raw) + } + o.MtoShipmentID = *(value.(*strfmt.UUID)) + + if err := o.validateMtoShipmentID(formats); err != nil { + return err + } + + return nil +} + +// validateMtoShipmentID carries on validations for parameter MtoShipmentID +func (o *UpdateMTOShipmentParams) validateMtoShipmentID(formats strfmt.Registry) error { + + if err := validate.FormatOf("mtoShipmentID", "path", "uuid", o.MtoShipmentID.String(), formats); err != nil { + return err + } + return nil +} diff --git a/pkg/gen/primev2api/primev2operations/mto_shipment/update_m_t_o_shipment_responses.go b/pkg/gen/primev2api/primev2operations/mto_shipment/update_m_t_o_shipment_responses.go new file mode 100644 index 00000000000..18034975fa5 --- /dev/null +++ b/pkg/gen/primev2api/primev2operations/mto_shipment/update_m_t_o_shipment_responses.go @@ -0,0 +1,374 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package mto_shipment + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" + + "github.com/transcom/mymove/pkg/gen/primev2messages" +) + +// UpdateMTOShipmentOKCode is the HTTP code returned for type UpdateMTOShipmentOK +const UpdateMTOShipmentOKCode int = 200 + +/* +UpdateMTOShipmentOK Successfully updated the MTO shipment. + +swagger:response updateMTOShipmentOK +*/ +type UpdateMTOShipmentOK struct { + + /* + In: Body + */ + Payload *primev2messages.MTOShipment `json:"body,omitempty"` +} + +// NewUpdateMTOShipmentOK creates UpdateMTOShipmentOK with default headers values +func NewUpdateMTOShipmentOK() *UpdateMTOShipmentOK { + + return &UpdateMTOShipmentOK{} +} + +// WithPayload adds the payload to the update m t o shipment o k response +func (o *UpdateMTOShipmentOK) WithPayload(payload *primev2messages.MTOShipment) *UpdateMTOShipmentOK { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the update m t o shipment o k response +func (o *UpdateMTOShipmentOK) SetPayload(payload *primev2messages.MTOShipment) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *UpdateMTOShipmentOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(200) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// UpdateMTOShipmentBadRequestCode is the HTTP code returned for type UpdateMTOShipmentBadRequest +const UpdateMTOShipmentBadRequestCode int = 400 + +/* +UpdateMTOShipmentBadRequest The request payload is invalid. + +swagger:response updateMTOShipmentBadRequest +*/ +type UpdateMTOShipmentBadRequest struct { + + /* + In: Body + */ + Payload *primev2messages.ClientError `json:"body,omitempty"` +} + +// NewUpdateMTOShipmentBadRequest creates UpdateMTOShipmentBadRequest with default headers values +func NewUpdateMTOShipmentBadRequest() *UpdateMTOShipmentBadRequest { + + return &UpdateMTOShipmentBadRequest{} +} + +// WithPayload adds the payload to the update m t o shipment bad request response +func (o *UpdateMTOShipmentBadRequest) WithPayload(payload *primev2messages.ClientError) *UpdateMTOShipmentBadRequest { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the update m t o shipment bad request response +func (o *UpdateMTOShipmentBadRequest) SetPayload(payload *primev2messages.ClientError) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *UpdateMTOShipmentBadRequest) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(400) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// UpdateMTOShipmentUnauthorizedCode is the HTTP code returned for type UpdateMTOShipmentUnauthorized +const UpdateMTOShipmentUnauthorizedCode int = 401 + +/* +UpdateMTOShipmentUnauthorized The request was denied. + +swagger:response updateMTOShipmentUnauthorized +*/ +type UpdateMTOShipmentUnauthorized struct { + + /* + In: Body + */ + Payload *primev2messages.ClientError `json:"body,omitempty"` +} + +// NewUpdateMTOShipmentUnauthorized creates UpdateMTOShipmentUnauthorized with default headers values +func NewUpdateMTOShipmentUnauthorized() *UpdateMTOShipmentUnauthorized { + + return &UpdateMTOShipmentUnauthorized{} +} + +// WithPayload adds the payload to the update m t o shipment unauthorized response +func (o *UpdateMTOShipmentUnauthorized) WithPayload(payload *primev2messages.ClientError) *UpdateMTOShipmentUnauthorized { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the update m t o shipment unauthorized response +func (o *UpdateMTOShipmentUnauthorized) SetPayload(payload *primev2messages.ClientError) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *UpdateMTOShipmentUnauthorized) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(401) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// UpdateMTOShipmentForbiddenCode is the HTTP code returned for type UpdateMTOShipmentForbidden +const UpdateMTOShipmentForbiddenCode int = 403 + +/* +UpdateMTOShipmentForbidden The request was denied. + +swagger:response updateMTOShipmentForbidden +*/ +type UpdateMTOShipmentForbidden struct { + + /* + In: Body + */ + Payload *primev2messages.ClientError `json:"body,omitempty"` +} + +// NewUpdateMTOShipmentForbidden creates UpdateMTOShipmentForbidden with default headers values +func NewUpdateMTOShipmentForbidden() *UpdateMTOShipmentForbidden { + + return &UpdateMTOShipmentForbidden{} +} + +// WithPayload adds the payload to the update m t o shipment forbidden response +func (o *UpdateMTOShipmentForbidden) WithPayload(payload *primev2messages.ClientError) *UpdateMTOShipmentForbidden { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the update m t o shipment forbidden response +func (o *UpdateMTOShipmentForbidden) SetPayload(payload *primev2messages.ClientError) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *UpdateMTOShipmentForbidden) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(403) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// UpdateMTOShipmentNotFoundCode is the HTTP code returned for type UpdateMTOShipmentNotFound +const UpdateMTOShipmentNotFoundCode int = 404 + +/* +UpdateMTOShipmentNotFound The requested resource wasn't found. + +swagger:response updateMTOShipmentNotFound +*/ +type UpdateMTOShipmentNotFound struct { + + /* + In: Body + */ + Payload *primev2messages.ClientError `json:"body,omitempty"` +} + +// NewUpdateMTOShipmentNotFound creates UpdateMTOShipmentNotFound with default headers values +func NewUpdateMTOShipmentNotFound() *UpdateMTOShipmentNotFound { + + return &UpdateMTOShipmentNotFound{} +} + +// WithPayload adds the payload to the update m t o shipment not found response +func (o *UpdateMTOShipmentNotFound) WithPayload(payload *primev2messages.ClientError) *UpdateMTOShipmentNotFound { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the update m t o shipment not found response +func (o *UpdateMTOShipmentNotFound) SetPayload(payload *primev2messages.ClientError) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *UpdateMTOShipmentNotFound) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(404) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// UpdateMTOShipmentPreconditionFailedCode is the HTTP code returned for type UpdateMTOShipmentPreconditionFailed +const UpdateMTOShipmentPreconditionFailedCode int = 412 + +/* +UpdateMTOShipmentPreconditionFailed Precondition failed, likely due to a stale eTag (If-Match). Fetch the request again to get the updated eTag value. + +swagger:response updateMTOShipmentPreconditionFailed +*/ +type UpdateMTOShipmentPreconditionFailed struct { + + /* + In: Body + */ + Payload *primev2messages.ClientError `json:"body,omitempty"` +} + +// NewUpdateMTOShipmentPreconditionFailed creates UpdateMTOShipmentPreconditionFailed with default headers values +func NewUpdateMTOShipmentPreconditionFailed() *UpdateMTOShipmentPreconditionFailed { + + return &UpdateMTOShipmentPreconditionFailed{} +} + +// WithPayload adds the payload to the update m t o shipment precondition failed response +func (o *UpdateMTOShipmentPreconditionFailed) WithPayload(payload *primev2messages.ClientError) *UpdateMTOShipmentPreconditionFailed { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the update m t o shipment precondition failed response +func (o *UpdateMTOShipmentPreconditionFailed) SetPayload(payload *primev2messages.ClientError) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *UpdateMTOShipmentPreconditionFailed) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(412) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// UpdateMTOShipmentUnprocessableEntityCode is the HTTP code returned for type UpdateMTOShipmentUnprocessableEntity +const UpdateMTOShipmentUnprocessableEntityCode int = 422 + +/* +UpdateMTOShipmentUnprocessableEntity The request was unprocessable, likely due to bad input from the requester. + +swagger:response updateMTOShipmentUnprocessableEntity +*/ +type UpdateMTOShipmentUnprocessableEntity struct { + + /* + In: Body + */ + Payload *primev2messages.ValidationError `json:"body,omitempty"` +} + +// NewUpdateMTOShipmentUnprocessableEntity creates UpdateMTOShipmentUnprocessableEntity with default headers values +func NewUpdateMTOShipmentUnprocessableEntity() *UpdateMTOShipmentUnprocessableEntity { + + return &UpdateMTOShipmentUnprocessableEntity{} +} + +// WithPayload adds the payload to the update m t o shipment unprocessable entity response +func (o *UpdateMTOShipmentUnprocessableEntity) WithPayload(payload *primev2messages.ValidationError) *UpdateMTOShipmentUnprocessableEntity { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the update m t o shipment unprocessable entity response +func (o *UpdateMTOShipmentUnprocessableEntity) SetPayload(payload *primev2messages.ValidationError) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *UpdateMTOShipmentUnprocessableEntity) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(422) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// UpdateMTOShipmentInternalServerErrorCode is the HTTP code returned for type UpdateMTOShipmentInternalServerError +const UpdateMTOShipmentInternalServerErrorCode int = 500 + +/* +UpdateMTOShipmentInternalServerError A server error occurred. + +swagger:response updateMTOShipmentInternalServerError +*/ +type UpdateMTOShipmentInternalServerError struct { + + /* + In: Body + */ + Payload *primev2messages.Error `json:"body,omitempty"` +} + +// NewUpdateMTOShipmentInternalServerError creates UpdateMTOShipmentInternalServerError with default headers values +func NewUpdateMTOShipmentInternalServerError() *UpdateMTOShipmentInternalServerError { + + return &UpdateMTOShipmentInternalServerError{} +} + +// WithPayload adds the payload to the update m t o shipment internal server error response +func (o *UpdateMTOShipmentInternalServerError) WithPayload(payload *primev2messages.Error) *UpdateMTOShipmentInternalServerError { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the update m t o shipment internal server error response +func (o *UpdateMTOShipmentInternalServerError) SetPayload(payload *primev2messages.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *UpdateMTOShipmentInternalServerError) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(500) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} diff --git a/pkg/gen/primev2api/primev2operations/mto_shipment/update_m_t_o_shipment_urlbuilder.go b/pkg/gen/primev2api/primev2operations/mto_shipment/update_m_t_o_shipment_urlbuilder.go new file mode 100644 index 00000000000..563ca5598fa --- /dev/null +++ b/pkg/gen/primev2api/primev2operations/mto_shipment/update_m_t_o_shipment_urlbuilder.go @@ -0,0 +1,101 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package mto_shipment + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" + "strings" + + "github.com/go-openapi/strfmt" +) + +// UpdateMTOShipmentURL generates an URL for the update m t o shipment operation +type UpdateMTOShipmentURL struct { + MtoShipmentID strfmt.UUID + + _basePath string + // avoid unkeyed usage + _ struct{} +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *UpdateMTOShipmentURL) WithBasePath(bp string) *UpdateMTOShipmentURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *UpdateMTOShipmentURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *UpdateMTOShipmentURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/mto-shipments/{mtoShipmentID}" + + mtoShipmentID := o.MtoShipmentID.String() + if mtoShipmentID != "" { + _path = strings.Replace(_path, "{mtoShipmentID}", mtoShipmentID, -1) + } else { + return nil, errors.New("mtoShipmentId is required on UpdateMTOShipmentURL") + } + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/prime/v2" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *UpdateMTOShipmentURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *UpdateMTOShipmentURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *UpdateMTOShipmentURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on UpdateMTOShipmentURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on UpdateMTOShipmentURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *UpdateMTOShipmentURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/pkg/gen/primev2api/primev2operations/mymove_api.go b/pkg/gen/primev2api/primev2operations/mymove_api.go index 99de31bf152..b2e00bf7989 100644 --- a/pkg/gen/primev2api/primev2operations/mymove_api.go +++ b/pkg/gen/primev2api/primev2operations/mymove_api.go @@ -51,6 +51,9 @@ func NewMymoveAPI(spec *loads.Document) *MymoveAPI { MoveTaskOrderGetMoveTaskOrderHandler: move_task_order.GetMoveTaskOrderHandlerFunc(func(params move_task_order.GetMoveTaskOrderParams) middleware.Responder { return middleware.NotImplemented("operation move_task_order.GetMoveTaskOrder has not yet been implemented") }), + MtoShipmentUpdateMTOShipmentHandler: mto_shipment.UpdateMTOShipmentHandlerFunc(func(params mto_shipment.UpdateMTOShipmentParams) middleware.Responder { + return middleware.NotImplemented("operation mto_shipment.UpdateMTOShipment has not yet been implemented") + }), } } @@ -97,6 +100,8 @@ type MymoveAPI struct { MtoShipmentCreateMTOShipmentHandler mto_shipment.CreateMTOShipmentHandler // MoveTaskOrderGetMoveTaskOrderHandler sets the operation handler for the get move task order operation MoveTaskOrderGetMoveTaskOrderHandler move_task_order.GetMoveTaskOrderHandler + // MtoShipmentUpdateMTOShipmentHandler sets the operation handler for the update m t o shipment operation + MtoShipmentUpdateMTOShipmentHandler mto_shipment.UpdateMTOShipmentHandler // ServeError is called when an error is received, there is a default handler // but you can set your own with this @@ -180,6 +185,9 @@ func (o *MymoveAPI) Validate() error { if o.MoveTaskOrderGetMoveTaskOrderHandler == nil { unregistered = append(unregistered, "move_task_order.GetMoveTaskOrderHandler") } + if o.MtoShipmentUpdateMTOShipmentHandler == nil { + unregistered = append(unregistered, "mto_shipment.UpdateMTOShipmentHandler") + } if len(unregistered) > 0 { return fmt.Errorf("missing registration: %s", strings.Join(unregistered, ", ")) @@ -276,6 +284,10 @@ func (o *MymoveAPI) initHandlerCache() { o.handlers["GET"] = make(map[string]http.Handler) } o.handlers["GET"]["/move-task-orders/{moveID}"] = move_task_order.NewGetMoveTaskOrder(o.context, o.MoveTaskOrderGetMoveTaskOrderHandler) + if o.handlers["PATCH"] == nil { + o.handlers["PATCH"] = make(map[string]http.Handler) + } + o.handlers["PATCH"]["/mto-shipments/{mtoShipmentID}"] = mto_shipment.NewUpdateMTOShipment(o.context, o.MtoShipmentUpdateMTOShipmentHandler) } // Serve creates a http handler to serve the API over HTTP diff --git a/pkg/gen/primev2client/mto_shipment/mto_shipment_client.go b/pkg/gen/primev2client/mto_shipment/mto_shipment_client.go index dfee782cd4f..57a78b05570 100644 --- a/pkg/gen/primev2client/mto_shipment/mto_shipment_client.go +++ b/pkg/gen/primev2client/mto_shipment/mto_shipment_client.go @@ -32,6 +32,8 @@ type ClientOption func(*runtime.ClientOperation) type ClientService interface { CreateMTOShipment(params *CreateMTOShipmentParams, opts ...ClientOption) (*CreateMTOShipmentOK, error) + UpdateMTOShipment(params *UpdateMTOShipmentParams, opts ...ClientOption) (*UpdateMTOShipmentOK, error) + SetTransport(transport runtime.ClientTransport) } @@ -87,6 +89,56 @@ func (a *Client) CreateMTOShipment(params *CreateMTOShipmentParams, opts ...Clie panic(msg) } +/* + UpdateMTOShipment updates m t o shipment + + Updates an existing shipment for a move. + +Note that there are some restrictions on nested objects: + +* Service items: You cannot add or update service items using this endpoint. Please use [createMTOServiceItem](#operation/createMTOServiceItem) and [updateMTOServiceItem](#operation/updateMTOServiceItem) instead. +* Agents: You cannot add or update agents using this endpoint. Please use [createMTOAgent](#operation/createMTOAgent) and [updateMTOAgent](#operation/updateMTOAgent) instead. +* Addresses: You can add new addresses using this endpoint (and must use this endpoint to do so), but you cannot update existing ones. Please use [updateMTOShipmentAddress](#operation/updateMTOShipmentAddress) instead. + +These restrictions are due to our [optimistic locking/concurrency control](https://transcom.github.io/mymove-docs/docs/dev/contributing/backend/use-optimistic-locking) mechanism. + +Note that some fields cannot be manually changed but will still be updated automatically, such as `primeEstimatedWeightRecordedDate` and `requiredDeliveryDate`. +*/ +func (a *Client) UpdateMTOShipment(params *UpdateMTOShipmentParams, opts ...ClientOption) (*UpdateMTOShipmentOK, error) { + // TODO: Validate the params before sending + if params == nil { + params = NewUpdateMTOShipmentParams() + } + op := &runtime.ClientOperation{ + ID: "updateMTOShipment", + Method: "PATCH", + PathPattern: "/mto-shipments/{mtoShipmentID}", + ProducesMediaTypes: []string{"application/json"}, + ConsumesMediaTypes: []string{"application/json"}, + Schemes: []string{"http"}, + Params: params, + Reader: &UpdateMTOShipmentReader{formats: a.formats}, + Context: params.Context, + Client: params.HTTPClient, + } + for _, opt := range opts { + opt(op) + } + + result, err := a.transport.Submit(op) + if err != nil { + return nil, err + } + success, ok := result.(*UpdateMTOShipmentOK) + if ok { + return success, nil + } + // unexpected success response + // safeguard: normally, absent a default response, unknown success responses return an error above: so this is a codegen issue + msg := fmt.Sprintf("unexpected success response for updateMTOShipment: API contract not enforced by server. Client expected to get an error, but got: %T", result) + panic(msg) +} + // SetTransport changes the transport on the client func (a *Client) SetTransport(transport runtime.ClientTransport) { a.transport = transport diff --git a/pkg/gen/primev2client/mto_shipment/update_m_t_o_shipment_parameters.go b/pkg/gen/primev2client/mto_shipment/update_m_t_o_shipment_parameters.go new file mode 100644 index 00000000000..0d4dfd95650 --- /dev/null +++ b/pkg/gen/primev2client/mto_shipment/update_m_t_o_shipment_parameters.go @@ -0,0 +1,197 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package mto_shipment + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + "net/http" + "time" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + cr "github.com/go-openapi/runtime/client" + "github.com/go-openapi/strfmt" + + "github.com/transcom/mymove/pkg/gen/primev2messages" +) + +// NewUpdateMTOShipmentParams creates a new UpdateMTOShipmentParams object, +// with the default timeout for this client. +// +// Default values are not hydrated, since defaults are normally applied by the API server side. +// +// To enforce default values in parameter, use SetDefaults or WithDefaults. +func NewUpdateMTOShipmentParams() *UpdateMTOShipmentParams { + return &UpdateMTOShipmentParams{ + timeout: cr.DefaultTimeout, + } +} + +// NewUpdateMTOShipmentParamsWithTimeout creates a new UpdateMTOShipmentParams object +// with the ability to set a timeout on a request. +func NewUpdateMTOShipmentParamsWithTimeout(timeout time.Duration) *UpdateMTOShipmentParams { + return &UpdateMTOShipmentParams{ + timeout: timeout, + } +} + +// NewUpdateMTOShipmentParamsWithContext creates a new UpdateMTOShipmentParams object +// with the ability to set a context for a request. +func NewUpdateMTOShipmentParamsWithContext(ctx context.Context) *UpdateMTOShipmentParams { + return &UpdateMTOShipmentParams{ + Context: ctx, + } +} + +// NewUpdateMTOShipmentParamsWithHTTPClient creates a new UpdateMTOShipmentParams object +// with the ability to set a custom HTTPClient for a request. +func NewUpdateMTOShipmentParamsWithHTTPClient(client *http.Client) *UpdateMTOShipmentParams { + return &UpdateMTOShipmentParams{ + HTTPClient: client, + } +} + +/* +UpdateMTOShipmentParams contains all the parameters to send to the API endpoint + + for the update m t o shipment operation. + + Typically these are written to a http.Request. +*/ +type UpdateMTOShipmentParams struct { + + /* IfMatch. + + Optimistic locking is implemented via the `If-Match` header. If the ETag header does not match the value of the resource on the server, the server rejects the change with a `412 Precondition Failed` error. + + */ + IfMatch string + + // Body. + Body *primev2messages.UpdateMTOShipment + + /* MtoShipmentID. + + UUID of the shipment being updated. + + Format: uuid + */ + MtoShipmentID strfmt.UUID + + timeout time.Duration + Context context.Context + HTTPClient *http.Client +} + +// WithDefaults hydrates default values in the update m t o shipment params (not the query body). +// +// All values with no default are reset to their zero value. +func (o *UpdateMTOShipmentParams) WithDefaults() *UpdateMTOShipmentParams { + o.SetDefaults() + return o +} + +// SetDefaults hydrates default values in the update m t o shipment params (not the query body). +// +// All values with no default are reset to their zero value. +func (o *UpdateMTOShipmentParams) SetDefaults() { + // no default values defined for this parameter +} + +// WithTimeout adds the timeout to the update m t o shipment params +func (o *UpdateMTOShipmentParams) WithTimeout(timeout time.Duration) *UpdateMTOShipmentParams { + o.SetTimeout(timeout) + return o +} + +// SetTimeout adds the timeout to the update m t o shipment params +func (o *UpdateMTOShipmentParams) SetTimeout(timeout time.Duration) { + o.timeout = timeout +} + +// WithContext adds the context to the update m t o shipment params +func (o *UpdateMTOShipmentParams) WithContext(ctx context.Context) *UpdateMTOShipmentParams { + o.SetContext(ctx) + return o +} + +// SetContext adds the context to the update m t o shipment params +func (o *UpdateMTOShipmentParams) SetContext(ctx context.Context) { + o.Context = ctx +} + +// WithHTTPClient adds the HTTPClient to the update m t o shipment params +func (o *UpdateMTOShipmentParams) WithHTTPClient(client *http.Client) *UpdateMTOShipmentParams { + o.SetHTTPClient(client) + return o +} + +// SetHTTPClient adds the HTTPClient to the update m t o shipment params +func (o *UpdateMTOShipmentParams) SetHTTPClient(client *http.Client) { + o.HTTPClient = client +} + +// WithIfMatch adds the ifMatch to the update m t o shipment params +func (o *UpdateMTOShipmentParams) WithIfMatch(ifMatch string) *UpdateMTOShipmentParams { + o.SetIfMatch(ifMatch) + return o +} + +// SetIfMatch adds the ifMatch to the update m t o shipment params +func (o *UpdateMTOShipmentParams) SetIfMatch(ifMatch string) { + o.IfMatch = ifMatch +} + +// WithBody adds the body to the update m t o shipment params +func (o *UpdateMTOShipmentParams) WithBody(body *primev2messages.UpdateMTOShipment) *UpdateMTOShipmentParams { + o.SetBody(body) + return o +} + +// SetBody adds the body to the update m t o shipment params +func (o *UpdateMTOShipmentParams) SetBody(body *primev2messages.UpdateMTOShipment) { + o.Body = body +} + +// WithMtoShipmentID adds the mtoShipmentID to the update m t o shipment params +func (o *UpdateMTOShipmentParams) WithMtoShipmentID(mtoShipmentID strfmt.UUID) *UpdateMTOShipmentParams { + o.SetMtoShipmentID(mtoShipmentID) + return o +} + +// SetMtoShipmentID adds the mtoShipmentId to the update m t o shipment params +func (o *UpdateMTOShipmentParams) SetMtoShipmentID(mtoShipmentID strfmt.UUID) { + o.MtoShipmentID = mtoShipmentID +} + +// WriteToRequest writes these params to a swagger request +func (o *UpdateMTOShipmentParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { + + if err := r.SetTimeout(o.timeout); err != nil { + return err + } + var res []error + + // header param If-Match + if err := r.SetHeaderParam("If-Match", o.IfMatch); err != nil { + return err + } + if o.Body != nil { + if err := r.SetBodyParam(o.Body); err != nil { + return err + } + } + + // path param mtoShipmentID + if err := r.SetPathParam("mtoShipmentID", o.MtoShipmentID.String()); err != nil { + return err + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/pkg/gen/primev2client/mto_shipment/update_m_t_o_shipment_responses.go b/pkg/gen/primev2client/mto_shipment/update_m_t_o_shipment_responses.go new file mode 100644 index 00000000000..3d3c9f9e198 --- /dev/null +++ b/pkg/gen/primev2client/mto_shipment/update_m_t_o_shipment_responses.go @@ -0,0 +1,621 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package mto_shipment + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "fmt" + "io" + + "github.com/go-openapi/runtime" + "github.com/go-openapi/strfmt" + + "github.com/transcom/mymove/pkg/gen/primev2messages" +) + +// UpdateMTOShipmentReader is a Reader for the UpdateMTOShipment structure. +type UpdateMTOShipmentReader struct { + formats strfmt.Registry +} + +// ReadResponse reads a server response into the received o. +func (o *UpdateMTOShipmentReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + switch response.Code() { + case 200: + result := NewUpdateMTOShipmentOK() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return result, nil + case 400: + result := NewUpdateMTOShipmentBadRequest() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + case 401: + result := NewUpdateMTOShipmentUnauthorized() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + case 403: + result := NewUpdateMTOShipmentForbidden() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + case 404: + result := NewUpdateMTOShipmentNotFound() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + case 412: + result := NewUpdateMTOShipmentPreconditionFailed() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + case 422: + result := NewUpdateMTOShipmentUnprocessableEntity() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + case 500: + result := NewUpdateMTOShipmentInternalServerError() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + default: + return nil, runtime.NewAPIError("[PATCH /mto-shipments/{mtoShipmentID}] updateMTOShipment", response, response.Code()) + } +} + +// NewUpdateMTOShipmentOK creates a UpdateMTOShipmentOK with default headers values +func NewUpdateMTOShipmentOK() *UpdateMTOShipmentOK { + return &UpdateMTOShipmentOK{} +} + +/* +UpdateMTOShipmentOK describes a response with status code 200, with default header values. + +Successfully updated the MTO shipment. +*/ +type UpdateMTOShipmentOK struct { + Payload *primev2messages.MTOShipment +} + +// IsSuccess returns true when this update m t o shipment o k response has a 2xx status code +func (o *UpdateMTOShipmentOK) IsSuccess() bool { + return true +} + +// IsRedirect returns true when this update m t o shipment o k response has a 3xx status code +func (o *UpdateMTOShipmentOK) IsRedirect() bool { + return false +} + +// IsClientError returns true when this update m t o shipment o k response has a 4xx status code +func (o *UpdateMTOShipmentOK) IsClientError() bool { + return false +} + +// IsServerError returns true when this update m t o shipment o k response has a 5xx status code +func (o *UpdateMTOShipmentOK) IsServerError() bool { + return false +} + +// IsCode returns true when this update m t o shipment o k response a status code equal to that given +func (o *UpdateMTOShipmentOK) IsCode(code int) bool { + return code == 200 +} + +// Code gets the status code for the update m t o shipment o k response +func (o *UpdateMTOShipmentOK) Code() int { + return 200 +} + +func (o *UpdateMTOShipmentOK) Error() string { + return fmt.Sprintf("[PATCH /mto-shipments/{mtoShipmentID}][%d] updateMTOShipmentOK %+v", 200, o.Payload) +} + +func (o *UpdateMTOShipmentOK) String() string { + return fmt.Sprintf("[PATCH /mto-shipments/{mtoShipmentID}][%d] updateMTOShipmentOK %+v", 200, o.Payload) +} + +func (o *UpdateMTOShipmentOK) GetPayload() *primev2messages.MTOShipment { + return o.Payload +} + +func (o *UpdateMTOShipmentOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(primev2messages.MTOShipment) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewUpdateMTOShipmentBadRequest creates a UpdateMTOShipmentBadRequest with default headers values +func NewUpdateMTOShipmentBadRequest() *UpdateMTOShipmentBadRequest { + return &UpdateMTOShipmentBadRequest{} +} + +/* +UpdateMTOShipmentBadRequest describes a response with status code 400, with default header values. + +The request payload is invalid. +*/ +type UpdateMTOShipmentBadRequest struct { + Payload *primev2messages.ClientError +} + +// IsSuccess returns true when this update m t o shipment bad request response has a 2xx status code +func (o *UpdateMTOShipmentBadRequest) IsSuccess() bool { + return false +} + +// IsRedirect returns true when this update m t o shipment bad request response has a 3xx status code +func (o *UpdateMTOShipmentBadRequest) IsRedirect() bool { + return false +} + +// IsClientError returns true when this update m t o shipment bad request response has a 4xx status code +func (o *UpdateMTOShipmentBadRequest) IsClientError() bool { + return true +} + +// IsServerError returns true when this update m t o shipment bad request response has a 5xx status code +func (o *UpdateMTOShipmentBadRequest) IsServerError() bool { + return false +} + +// IsCode returns true when this update m t o shipment bad request response a status code equal to that given +func (o *UpdateMTOShipmentBadRequest) IsCode(code int) bool { + return code == 400 +} + +// Code gets the status code for the update m t o shipment bad request response +func (o *UpdateMTOShipmentBadRequest) Code() int { + return 400 +} + +func (o *UpdateMTOShipmentBadRequest) Error() string { + return fmt.Sprintf("[PATCH /mto-shipments/{mtoShipmentID}][%d] updateMTOShipmentBadRequest %+v", 400, o.Payload) +} + +func (o *UpdateMTOShipmentBadRequest) String() string { + return fmt.Sprintf("[PATCH /mto-shipments/{mtoShipmentID}][%d] updateMTOShipmentBadRequest %+v", 400, o.Payload) +} + +func (o *UpdateMTOShipmentBadRequest) GetPayload() *primev2messages.ClientError { + return o.Payload +} + +func (o *UpdateMTOShipmentBadRequest) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(primev2messages.ClientError) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewUpdateMTOShipmentUnauthorized creates a UpdateMTOShipmentUnauthorized with default headers values +func NewUpdateMTOShipmentUnauthorized() *UpdateMTOShipmentUnauthorized { + return &UpdateMTOShipmentUnauthorized{} +} + +/* +UpdateMTOShipmentUnauthorized describes a response with status code 401, with default header values. + +The request was denied. +*/ +type UpdateMTOShipmentUnauthorized struct { + Payload *primev2messages.ClientError +} + +// IsSuccess returns true when this update m t o shipment unauthorized response has a 2xx status code +func (o *UpdateMTOShipmentUnauthorized) IsSuccess() bool { + return false +} + +// IsRedirect returns true when this update m t o shipment unauthorized response has a 3xx status code +func (o *UpdateMTOShipmentUnauthorized) IsRedirect() bool { + return false +} + +// IsClientError returns true when this update m t o shipment unauthorized response has a 4xx status code +func (o *UpdateMTOShipmentUnauthorized) IsClientError() bool { + return true +} + +// IsServerError returns true when this update m t o shipment unauthorized response has a 5xx status code +func (o *UpdateMTOShipmentUnauthorized) IsServerError() bool { + return false +} + +// IsCode returns true when this update m t o shipment unauthorized response a status code equal to that given +func (o *UpdateMTOShipmentUnauthorized) IsCode(code int) bool { + return code == 401 +} + +// Code gets the status code for the update m t o shipment unauthorized response +func (o *UpdateMTOShipmentUnauthorized) Code() int { + return 401 +} + +func (o *UpdateMTOShipmentUnauthorized) Error() string { + return fmt.Sprintf("[PATCH /mto-shipments/{mtoShipmentID}][%d] updateMTOShipmentUnauthorized %+v", 401, o.Payload) +} + +func (o *UpdateMTOShipmentUnauthorized) String() string { + return fmt.Sprintf("[PATCH /mto-shipments/{mtoShipmentID}][%d] updateMTOShipmentUnauthorized %+v", 401, o.Payload) +} + +func (o *UpdateMTOShipmentUnauthorized) GetPayload() *primev2messages.ClientError { + return o.Payload +} + +func (o *UpdateMTOShipmentUnauthorized) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(primev2messages.ClientError) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewUpdateMTOShipmentForbidden creates a UpdateMTOShipmentForbidden with default headers values +func NewUpdateMTOShipmentForbidden() *UpdateMTOShipmentForbidden { + return &UpdateMTOShipmentForbidden{} +} + +/* +UpdateMTOShipmentForbidden describes a response with status code 403, with default header values. + +The request was denied. +*/ +type UpdateMTOShipmentForbidden struct { + Payload *primev2messages.ClientError +} + +// IsSuccess returns true when this update m t o shipment forbidden response has a 2xx status code +func (o *UpdateMTOShipmentForbidden) IsSuccess() bool { + return false +} + +// IsRedirect returns true when this update m t o shipment forbidden response has a 3xx status code +func (o *UpdateMTOShipmentForbidden) IsRedirect() bool { + return false +} + +// IsClientError returns true when this update m t o shipment forbidden response has a 4xx status code +func (o *UpdateMTOShipmentForbidden) IsClientError() bool { + return true +} + +// IsServerError returns true when this update m t o shipment forbidden response has a 5xx status code +func (o *UpdateMTOShipmentForbidden) IsServerError() bool { + return false +} + +// IsCode returns true when this update m t o shipment forbidden response a status code equal to that given +func (o *UpdateMTOShipmentForbidden) IsCode(code int) bool { + return code == 403 +} + +// Code gets the status code for the update m t o shipment forbidden response +func (o *UpdateMTOShipmentForbidden) Code() int { + return 403 +} + +func (o *UpdateMTOShipmentForbidden) Error() string { + return fmt.Sprintf("[PATCH /mto-shipments/{mtoShipmentID}][%d] updateMTOShipmentForbidden %+v", 403, o.Payload) +} + +func (o *UpdateMTOShipmentForbidden) String() string { + return fmt.Sprintf("[PATCH /mto-shipments/{mtoShipmentID}][%d] updateMTOShipmentForbidden %+v", 403, o.Payload) +} + +func (o *UpdateMTOShipmentForbidden) GetPayload() *primev2messages.ClientError { + return o.Payload +} + +func (o *UpdateMTOShipmentForbidden) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(primev2messages.ClientError) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewUpdateMTOShipmentNotFound creates a UpdateMTOShipmentNotFound with default headers values +func NewUpdateMTOShipmentNotFound() *UpdateMTOShipmentNotFound { + return &UpdateMTOShipmentNotFound{} +} + +/* +UpdateMTOShipmentNotFound describes a response with status code 404, with default header values. + +The requested resource wasn't found. +*/ +type UpdateMTOShipmentNotFound struct { + Payload *primev2messages.ClientError +} + +// IsSuccess returns true when this update m t o shipment not found response has a 2xx status code +func (o *UpdateMTOShipmentNotFound) IsSuccess() bool { + return false +} + +// IsRedirect returns true when this update m t o shipment not found response has a 3xx status code +func (o *UpdateMTOShipmentNotFound) IsRedirect() bool { + return false +} + +// IsClientError returns true when this update m t o shipment not found response has a 4xx status code +func (o *UpdateMTOShipmentNotFound) IsClientError() bool { + return true +} + +// IsServerError returns true when this update m t o shipment not found response has a 5xx status code +func (o *UpdateMTOShipmentNotFound) IsServerError() bool { + return false +} + +// IsCode returns true when this update m t o shipment not found response a status code equal to that given +func (o *UpdateMTOShipmentNotFound) IsCode(code int) bool { + return code == 404 +} + +// Code gets the status code for the update m t o shipment not found response +func (o *UpdateMTOShipmentNotFound) Code() int { + return 404 +} + +func (o *UpdateMTOShipmentNotFound) Error() string { + return fmt.Sprintf("[PATCH /mto-shipments/{mtoShipmentID}][%d] updateMTOShipmentNotFound %+v", 404, o.Payload) +} + +func (o *UpdateMTOShipmentNotFound) String() string { + return fmt.Sprintf("[PATCH /mto-shipments/{mtoShipmentID}][%d] updateMTOShipmentNotFound %+v", 404, o.Payload) +} + +func (o *UpdateMTOShipmentNotFound) GetPayload() *primev2messages.ClientError { + return o.Payload +} + +func (o *UpdateMTOShipmentNotFound) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(primev2messages.ClientError) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewUpdateMTOShipmentPreconditionFailed creates a UpdateMTOShipmentPreconditionFailed with default headers values +func NewUpdateMTOShipmentPreconditionFailed() *UpdateMTOShipmentPreconditionFailed { + return &UpdateMTOShipmentPreconditionFailed{} +} + +/* +UpdateMTOShipmentPreconditionFailed describes a response with status code 412, with default header values. + +Precondition failed, likely due to a stale eTag (If-Match). Fetch the request again to get the updated eTag value. +*/ +type UpdateMTOShipmentPreconditionFailed struct { + Payload *primev2messages.ClientError +} + +// IsSuccess returns true when this update m t o shipment precondition failed response has a 2xx status code +func (o *UpdateMTOShipmentPreconditionFailed) IsSuccess() bool { + return false +} + +// IsRedirect returns true when this update m t o shipment precondition failed response has a 3xx status code +func (o *UpdateMTOShipmentPreconditionFailed) IsRedirect() bool { + return false +} + +// IsClientError returns true when this update m t o shipment precondition failed response has a 4xx status code +func (o *UpdateMTOShipmentPreconditionFailed) IsClientError() bool { + return true +} + +// IsServerError returns true when this update m t o shipment precondition failed response has a 5xx status code +func (o *UpdateMTOShipmentPreconditionFailed) IsServerError() bool { + return false +} + +// IsCode returns true when this update m t o shipment precondition failed response a status code equal to that given +func (o *UpdateMTOShipmentPreconditionFailed) IsCode(code int) bool { + return code == 412 +} + +// Code gets the status code for the update m t o shipment precondition failed response +func (o *UpdateMTOShipmentPreconditionFailed) Code() int { + return 412 +} + +func (o *UpdateMTOShipmentPreconditionFailed) Error() string { + return fmt.Sprintf("[PATCH /mto-shipments/{mtoShipmentID}][%d] updateMTOShipmentPreconditionFailed %+v", 412, o.Payload) +} + +func (o *UpdateMTOShipmentPreconditionFailed) String() string { + return fmt.Sprintf("[PATCH /mto-shipments/{mtoShipmentID}][%d] updateMTOShipmentPreconditionFailed %+v", 412, o.Payload) +} + +func (o *UpdateMTOShipmentPreconditionFailed) GetPayload() *primev2messages.ClientError { + return o.Payload +} + +func (o *UpdateMTOShipmentPreconditionFailed) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(primev2messages.ClientError) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewUpdateMTOShipmentUnprocessableEntity creates a UpdateMTOShipmentUnprocessableEntity with default headers values +func NewUpdateMTOShipmentUnprocessableEntity() *UpdateMTOShipmentUnprocessableEntity { + return &UpdateMTOShipmentUnprocessableEntity{} +} + +/* +UpdateMTOShipmentUnprocessableEntity describes a response with status code 422, with default header values. + +The request was unprocessable, likely due to bad input from the requester. +*/ +type UpdateMTOShipmentUnprocessableEntity struct { + Payload *primev2messages.ValidationError +} + +// IsSuccess returns true when this update m t o shipment unprocessable entity response has a 2xx status code +func (o *UpdateMTOShipmentUnprocessableEntity) IsSuccess() bool { + return false +} + +// IsRedirect returns true when this update m t o shipment unprocessable entity response has a 3xx status code +func (o *UpdateMTOShipmentUnprocessableEntity) IsRedirect() bool { + return false +} + +// IsClientError returns true when this update m t o shipment unprocessable entity response has a 4xx status code +func (o *UpdateMTOShipmentUnprocessableEntity) IsClientError() bool { + return true +} + +// IsServerError returns true when this update m t o shipment unprocessable entity response has a 5xx status code +func (o *UpdateMTOShipmentUnprocessableEntity) IsServerError() bool { + return false +} + +// IsCode returns true when this update m t o shipment unprocessable entity response a status code equal to that given +func (o *UpdateMTOShipmentUnprocessableEntity) IsCode(code int) bool { + return code == 422 +} + +// Code gets the status code for the update m t o shipment unprocessable entity response +func (o *UpdateMTOShipmentUnprocessableEntity) Code() int { + return 422 +} + +func (o *UpdateMTOShipmentUnprocessableEntity) Error() string { + return fmt.Sprintf("[PATCH /mto-shipments/{mtoShipmentID}][%d] updateMTOShipmentUnprocessableEntity %+v", 422, o.Payload) +} + +func (o *UpdateMTOShipmentUnprocessableEntity) String() string { + return fmt.Sprintf("[PATCH /mto-shipments/{mtoShipmentID}][%d] updateMTOShipmentUnprocessableEntity %+v", 422, o.Payload) +} + +func (o *UpdateMTOShipmentUnprocessableEntity) GetPayload() *primev2messages.ValidationError { + return o.Payload +} + +func (o *UpdateMTOShipmentUnprocessableEntity) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(primev2messages.ValidationError) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewUpdateMTOShipmentInternalServerError creates a UpdateMTOShipmentInternalServerError with default headers values +func NewUpdateMTOShipmentInternalServerError() *UpdateMTOShipmentInternalServerError { + return &UpdateMTOShipmentInternalServerError{} +} + +/* +UpdateMTOShipmentInternalServerError describes a response with status code 500, with default header values. + +A server error occurred. +*/ +type UpdateMTOShipmentInternalServerError struct { + Payload *primev2messages.Error +} + +// IsSuccess returns true when this update m t o shipment internal server error response has a 2xx status code +func (o *UpdateMTOShipmentInternalServerError) IsSuccess() bool { + return false +} + +// IsRedirect returns true when this update m t o shipment internal server error response has a 3xx status code +func (o *UpdateMTOShipmentInternalServerError) IsRedirect() bool { + return false +} + +// IsClientError returns true when this update m t o shipment internal server error response has a 4xx status code +func (o *UpdateMTOShipmentInternalServerError) IsClientError() bool { + return false +} + +// IsServerError returns true when this update m t o shipment internal server error response has a 5xx status code +func (o *UpdateMTOShipmentInternalServerError) IsServerError() bool { + return true +} + +// IsCode returns true when this update m t o shipment internal server error response a status code equal to that given +func (o *UpdateMTOShipmentInternalServerError) IsCode(code int) bool { + return code == 500 +} + +// Code gets the status code for the update m t o shipment internal server error response +func (o *UpdateMTOShipmentInternalServerError) Code() int { + return 500 +} + +func (o *UpdateMTOShipmentInternalServerError) Error() string { + return fmt.Sprintf("[PATCH /mto-shipments/{mtoShipmentID}][%d] updateMTOShipmentInternalServerError %+v", 500, o.Payload) +} + +func (o *UpdateMTOShipmentInternalServerError) String() string { + return fmt.Sprintf("[PATCH /mto-shipments/{mtoShipmentID}][%d] updateMTOShipmentInternalServerError %+v", 500, o.Payload) +} + +func (o *UpdateMTOShipmentInternalServerError) GetPayload() *primev2messages.Error { + return o.Payload +} + +func (o *UpdateMTOShipmentInternalServerError) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(primev2messages.Error) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} diff --git a/pkg/handlers/ghcapi/mto_shipment.go b/pkg/handlers/ghcapi/mto_shipment.go index 47e09cf5302..656f8974b4c 100644 --- a/pkg/handlers/ghcapi/mto_shipment.go +++ b/pkg/handlers/ghcapi/mto_shipment.go @@ -287,7 +287,7 @@ func (h UpdateShipmentHandler) Handle(params mtoshipmentops.UpdateMTOShipmentPar ), err } } - updatedMtoShipment, err := h.ShipmentUpdater.UpdateShipment(appCtx, mtoShipment, params.IfMatch) + updatedMtoShipment, err := h.ShipmentUpdater.UpdateShipment(appCtx, mtoShipment, params.IfMatch, "ghc") if err != nil { return handleError(err) } diff --git a/pkg/handlers/ghcapi/mto_shipment_test.go b/pkg/handlers/ghcapi/mto_shipment_test.go index 770eb7e26ac..776ac38ad61 100644 --- a/pkg/handlers/ghcapi/mto_shipment_test.go +++ b/pkg/handlers/ghcapi/mto_shipment_test.go @@ -3873,6 +3873,7 @@ func (suite *HandlerSuite) TestUpdateShipmentHandler() { mock.AnythingOfType("*appcontext.appContext"), mock.Anything, mock.Anything, + mock.Anything, ).Return(nil, err) oldShipment := factory.BuildMTOShipment(suite.DB(), []factory.Customization{ diff --git a/pkg/handlers/internalapi/mto_shipment.go b/pkg/handlers/internalapi/mto_shipment.go index 973f34c13ab..c28c67bb030 100644 --- a/pkg/handlers/internalapi/mto_shipment.go +++ b/pkg/handlers/internalapi/mto_shipment.go @@ -145,7 +145,7 @@ func (h UpdateMTOShipmentHandler) Handle(params mtoshipmentops.UpdateMTOShipment h.GetTraceIDFromRequest(params.HTTPRequest))), invalidShipmentStatusErr } - updatedMTOShipment, err := h.shipmentUpdater.UpdateShipment(appCtx, mtoShipment, params.IfMatch) + updatedMTOShipment, err := h.shipmentUpdater.UpdateShipment(appCtx, mtoShipment, params.IfMatch, "internal") if err != nil { appCtx.Logger().Error("internalapi.UpdateMTOShipmentHandler", zap.Error(err)) diff --git a/pkg/handlers/internalapi/mto_shipment_test.go b/pkg/handlers/internalapi/mto_shipment_test.go index b9c12798a1d..5b6f847772c 100644 --- a/pkg/handlers/internalapi/mto_shipment_test.go +++ b/pkg/handlers/internalapi/mto_shipment_test.go @@ -1056,10 +1056,10 @@ func (suite *HandlerSuite) TestUpdateMTOShipmentHandler() { }, "Allows updates to W2 Address": { setUpOriginalPPM: func() models.PPMShipment { - address := factory.BuildAddress(suite.DB(), nil, nil) + buildAddress := factory.BuildAddress(suite.DB(), nil, nil) return factory.BuildMinimalPPMShipment(suite.DB(), []factory.Customization{ { - Model: address, + Model: buildAddress, LinkOnly: true, Type: &factory.Addresses.W2Address, }, @@ -1309,6 +1309,7 @@ func (suite *HandlerSuite) TestUpdateMTOShipmentHandler() { mock.AnythingOfType("*appcontext.appContext"), mock.AnythingOfType("*models.MTOShipment"), mock.AnythingOfType("string"), + mock.AnythingOfType("string"), ).Return(nil, err) subtestData := getDefaultMTOShipmentAndParams(&mockUpdater) diff --git a/pkg/handlers/primeapi/mto_shipment.go b/pkg/handlers/primeapi/mto_shipment.go index 7604496e51e..815ce2fd8d0 100644 --- a/pkg/handlers/primeapi/mto_shipment.go +++ b/pkg/handlers/primeapi/mto_shipment.go @@ -192,7 +192,7 @@ func (h UpdateMTOShipmentHandler) Handle(params mtoshipmentops.UpdateMTOShipment mtoShipment.ShipmentType = dbShipment.ShipmentType appCtx.Logger().Info("primeapi.UpdateMTOShipmentHandler info", zap.String("pointOfContact", params.Body.PointOfContact)) - mtoShipment, err = h.ShipmentUpdater.UpdateShipment(appCtx, mtoShipment, params.IfMatch) + mtoShipment, err = h.ShipmentUpdater.UpdateShipment(appCtx, mtoShipment, params.IfMatch, "prime") if err != nil { appCtx.Logger().Error("primeapi.UpdateMTOShipmentHandler error", zap.Error(err)) switch e := err.(type) { diff --git a/pkg/handlers/primeapiv2/api.go b/pkg/handlers/primeapiv2/api.go index 52954377511..794c1c57d9f 100644 --- a/pkg/handlers/primeapiv2/api.go +++ b/pkg/handlers/primeapiv2/api.go @@ -9,12 +9,15 @@ import ( "github.com/transcom/mymove/pkg/gen/primev2api/primev2operations" "github.com/transcom/mymove/pkg/handlers" paymentrequesthelper "github.com/transcom/mymove/pkg/payment_request" + "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/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" "github.com/transcom/mymove/pkg/services/orchestrators/shipment" + paymentrequest "github.com/transcom/mymove/pkg/services/payment_request" "github.com/transcom/mymove/pkg/services/ppmshipment" "github.com/transcom/mymove/pkg/services/query" ) @@ -57,6 +60,32 @@ func NewPrimeAPI(handlerConfig handlers.HandlerConfig) *primev2operations.Mymove shipmentCreator, movetaskorder.NewMoveTaskOrderChecker(), } + paymentRequestRecalculator := paymentrequest.NewPaymentRequestRecalculator( + paymentrequest.NewPaymentRequestCreator( + handlerConfig.HHGPlanner(), + ghcrateengine.NewServiceItemPricer(), + ), + paymentrequest.NewPaymentRequestStatusUpdater(queryBuilder), + ) + paymentRequestShipmentRecalculator := paymentrequest.NewPaymentRequestShipmentRecalculator(paymentRequestRecalculator) + moveWeights := move.NewMoveWeights(mtoshipment.NewShipmentReweighRequester()) + mtoShipmentUpdater := mtoshipment.NewPrimeMTOShipmentUpdater( + builder, + fetcher, + handlerConfig.HHGPlanner(), + moveRouter, + moveWeights, + handlerConfig.NotificationSender(), + paymentRequestShipmentRecalculator, + ) + addressCreator := address.NewAddressCreator() + addressUpdater := address.NewAddressUpdater() + ppmShipmentUpdater := ppmshipment.NewPPMShipmentUpdater(ppmEstimator, addressCreator, addressUpdater) + shipmentUpdater := shipment.NewShipmentUpdater(mtoShipmentUpdater, ppmShipmentUpdater) + primeAPIV2.MtoShipmentUpdateMTOShipmentHandler = UpdateMTOShipmentHandler{ + handlerConfig, + shipmentUpdater, + } return primeAPIV2 } diff --git a/pkg/handlers/primeapiv2/mto_shipment.go b/pkg/handlers/primeapiv2/mto_shipment.go index b790112a9f8..688e259cfa8 100644 --- a/pkg/handlers/primeapiv2/mto_shipment.go +++ b/pkg/handlers/primeapiv2/mto_shipment.go @@ -10,12 +10,14 @@ import ( "github.com/transcom/mymove/pkg/appcontext" "github.com/transcom/mymove/pkg/apperror" + "github.com/transcom/mymove/pkg/db/utilities" mtoshipmentops "github.com/transcom/mymove/pkg/gen/primev2api/primev2operations/mto_shipment" "github.com/transcom/mymove/pkg/handlers" "github.com/transcom/mymove/pkg/handlers/primeapi" "github.com/transcom/mymove/pkg/handlers/primeapiv2/payloads" "github.com/transcom/mymove/pkg/models" "github.com/transcom/mymove/pkg/services" + mtoshipment "github.com/transcom/mymove/pkg/services/mto_shipment" ) // CreateMTOShipmentHandler is the handler to create MTO shipments @@ -102,3 +104,60 @@ func (h CreateMTOShipmentHandler) Handle(params mtoshipmentops.CreateMTOShipment return mtoshipmentops.NewCreateMTOShipmentOK().WithPayload(returnPayload), nil }) } + +// UpdateMTOShipmentHandler is the handler to update MTO shipments +type UpdateMTOShipmentHandler struct { + handlers.HandlerConfig + services.ShipmentUpdater +} + +// Handle handler that updates a mto shipment +func (h UpdateMTOShipmentHandler) Handle(params mtoshipmentops.UpdateMTOShipmentParams) middleware.Responder { + return h.AuditableAppContextFromRequestWithErrors(params.HTTPRequest, + func(appCtx appcontext.AppContext) (middleware.Responder, error) { + mtoShipment := payloads.MTOShipmentModelFromUpdate(params.Body, params.MtoShipmentID) + + dbShipment, err := mtoshipment.FindShipment(appCtx, mtoShipment.ID, "DestinationAddress", + "SecondaryPickupAddress", + "SecondaryDeliveryAddress", + "StorageFacility", + "PPMShipment") + if err != nil { + return mtoshipmentops.NewUpdateMTOShipmentNotFound().WithPayload( + payloads.ClientError(handlers.NotFoundMessage, err.Error(), h.GetTraceIDFromRequest(params.HTTPRequest))), err + } + + var agents []models.MTOAgent + err = appCtx.DB().Scope(utilities.ExcludeDeletedScope()).Where("mto_shipment_id = ?", mtoShipment.ID).All(&agents) + if err != nil { + return mtoshipmentops.NewUpdateMTOShipmentInternalServerError().WithPayload( + payloads.InternalServerError(nil, h.GetTraceIDFromRequest(params.HTTPRequest))), err + } + dbShipment.MTOAgents = agents + + // Validate further prime restrictions on model + mtoShipment.ShipmentType = dbShipment.ShipmentType + + appCtx.Logger().Info("primeapi.UpdateMTOShipmentHandler info", zap.String("pointOfContact", params.Body.PointOfContact)) + mtoShipment, err = h.ShipmentUpdater.UpdateShipment(appCtx, mtoShipment, params.IfMatch, "prime-v2") + if err != nil { + appCtx.Logger().Error("primeapi.UpdateMTOShipmentHandler error", zap.Error(err)) + switch e := err.(type) { + case apperror.NotFoundError: + return mtoshipmentops.NewUpdateMTOShipmentNotFound().WithPayload( + payloads.ClientError(handlers.NotFoundMessage, err.Error(), h.GetTraceIDFromRequest(params.HTTPRequest))), err + case apperror.InvalidInputError: + payload := payloads.ValidationError(err.Error(), h.GetTraceIDFromRequest(params.HTTPRequest), e.ValidationErrors) + return mtoshipmentops.NewUpdateMTOShipmentUnprocessableEntity().WithPayload(payload), err + case apperror.PreconditionFailedError: + return mtoshipmentops.NewUpdateMTOShipmentPreconditionFailed().WithPayload( + payloads.ClientError(handlers.PreconditionErrMessage, err.Error(), h.GetTraceIDFromRequest(params.HTTPRequest))), err + default: + return mtoshipmentops.NewUpdateMTOShipmentInternalServerError().WithPayload( + payloads.InternalServerError(nil, h.GetTraceIDFromRequest(params.HTTPRequest))), err + } + } + mtoShipmentPayload := payloads.MTOShipment(mtoShipment) + return mtoshipmentops.NewUpdateMTOShipmentOK().WithPayload(mtoShipmentPayload), nil + }) +} diff --git a/pkg/services/mocks/MTOShipmentUpdater.go b/pkg/services/mocks/MTOShipmentUpdater.go index 78eb18ce030..2b385559b6f 100644 --- a/pkg/services/mocks/MTOShipmentUpdater.go +++ b/pkg/services/mocks/MTOShipmentUpdater.go @@ -40,25 +40,25 @@ func (_m *MTOShipmentUpdater) MTOShipmentsMTOAvailableToPrime(appCtx appcontext. return r0, r1 } -// UpdateMTOShipment provides a mock function with given fields: appCtx, mtoShipment, eTag -func (_m *MTOShipmentUpdater) UpdateMTOShipment(appCtx appcontext.AppContext, mtoShipment *models.MTOShipment, eTag string) (*models.MTOShipment, error) { - ret := _m.Called(appCtx, mtoShipment, eTag) +// UpdateMTOShipment provides a mock function with given fields: appCtx, mtoShipment, eTag, api +func (_m *MTOShipmentUpdater) UpdateMTOShipment(appCtx appcontext.AppContext, mtoShipment *models.MTOShipment, eTag string, api string) (*models.MTOShipment, error) { + ret := _m.Called(appCtx, mtoShipment, eTag, api) var r0 *models.MTOShipment var r1 error - if rf, ok := ret.Get(0).(func(appcontext.AppContext, *models.MTOShipment, string) (*models.MTOShipment, error)); ok { - return rf(appCtx, mtoShipment, eTag) + if rf, ok := ret.Get(0).(func(appcontext.AppContext, *models.MTOShipment, string, string) (*models.MTOShipment, error)); ok { + return rf(appCtx, mtoShipment, eTag, api) } - if rf, ok := ret.Get(0).(func(appcontext.AppContext, *models.MTOShipment, string) *models.MTOShipment); ok { - r0 = rf(appCtx, mtoShipment, eTag) + if rf, ok := ret.Get(0).(func(appcontext.AppContext, *models.MTOShipment, string, string) *models.MTOShipment); ok { + r0 = rf(appCtx, mtoShipment, eTag, api) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*models.MTOShipment) } } - if rf, ok := ret.Get(1).(func(appcontext.AppContext, *models.MTOShipment, string) error); ok { - r1 = rf(appCtx, mtoShipment, eTag) + if rf, ok := ret.Get(1).(func(appcontext.AppContext, *models.MTOShipment, string, string) error); ok { + r1 = rf(appCtx, mtoShipment, eTag, api) } else { r1 = ret.Error(1) } diff --git a/pkg/services/mocks/ShipmentUpdater.go b/pkg/services/mocks/ShipmentUpdater.go index 62df5297265..9ea48b83353 100644 --- a/pkg/services/mocks/ShipmentUpdater.go +++ b/pkg/services/mocks/ShipmentUpdater.go @@ -14,25 +14,25 @@ type ShipmentUpdater struct { mock.Mock } -// UpdateShipment provides a mock function with given fields: appCtx, shipment, eTag -func (_m *ShipmentUpdater) UpdateShipment(appCtx appcontext.AppContext, shipment *models.MTOShipment, eTag string) (*models.MTOShipment, error) { - ret := _m.Called(appCtx, shipment, eTag) +// UpdateShipment provides a mock function with given fields: appCtx, shipment, eTag, api +func (_m *ShipmentUpdater) UpdateShipment(appCtx appcontext.AppContext, shipment *models.MTOShipment, eTag string, api string) (*models.MTOShipment, error) { + ret := _m.Called(appCtx, shipment, eTag, api) var r0 *models.MTOShipment var r1 error - if rf, ok := ret.Get(0).(func(appcontext.AppContext, *models.MTOShipment, string) (*models.MTOShipment, error)); ok { - return rf(appCtx, shipment, eTag) + if rf, ok := ret.Get(0).(func(appcontext.AppContext, *models.MTOShipment, string, string) (*models.MTOShipment, error)); ok { + return rf(appCtx, shipment, eTag, api) } - if rf, ok := ret.Get(0).(func(appcontext.AppContext, *models.MTOShipment, string) *models.MTOShipment); ok { - r0 = rf(appCtx, shipment, eTag) + if rf, ok := ret.Get(0).(func(appcontext.AppContext, *models.MTOShipment, string, string) *models.MTOShipment); ok { + r0 = rf(appCtx, shipment, eTag, api) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*models.MTOShipment) } } - if rf, ok := ret.Get(1).(func(appcontext.AppContext, *models.MTOShipment, string) error); ok { - r1 = rf(appCtx, shipment, eTag) + if rf, ok := ret.Get(1).(func(appcontext.AppContext, *models.MTOShipment, string, string) error); ok { + r1 = rf(appCtx, shipment, eTag, api) } else { r1 = ret.Error(1) } diff --git a/pkg/services/mto_shipment.go b/pkg/services/mto_shipment.go index 648f41d22b0..5bb0e039197 100644 --- a/pkg/services/mto_shipment.go +++ b/pkg/services/mto_shipment.go @@ -24,7 +24,7 @@ type MTOShipmentFetcher interface { //go:generate mockery --name MTOShipmentUpdater type MTOShipmentUpdater interface { MTOShipmentsMTOAvailableToPrime(appCtx appcontext.AppContext, mtoShipmentID uuid.UUID) (bool, error) - UpdateMTOShipment(appCtx appcontext.AppContext, mtoShipment *models.MTOShipment, eTag string) (*models.MTOShipment, error) + UpdateMTOShipment(appCtx appcontext.AppContext, mtoShipment *models.MTOShipment, eTag string, api string) (*models.MTOShipment, error) } // BillableWeightInputs is a type for capturing what should be returned when a shipments billable weight is calculated diff --git a/pkg/services/mto_shipment/mto_shipment_updater.go b/pkg/services/mto_shipment/mto_shipment_updater.go index abcb11e37fd..4266d6de414 100644 --- a/pkg/services/mto_shipment/mto_shipment_updater.go +++ b/pkg/services/mto_shipment/mto_shipment_updater.go @@ -296,7 +296,7 @@ func (e StaleIdentifierError) Error() string { } // UpdateMTOShipment updates the mto shipment -func (f *mtoShipmentUpdater) UpdateMTOShipment(appCtx appcontext.AppContext, mtoShipment *models.MTOShipment, eTag string) (*models.MTOShipment, error) { +func (f *mtoShipmentUpdater) UpdateMTOShipment(appCtx appcontext.AppContext, mtoShipment *models.MTOShipment, eTag string, api string) (*models.MTOShipment, error) { eagerAssociations := []string{"MoveTaskOrder", "PickupAddress", "DestinationAddress", @@ -358,9 +358,15 @@ func (f *mtoShipmentUpdater) UpdateMTOShipment(appCtx appcontext.AppContext, mto } updatedShipment.MTOAgents = updatedAgents - err = UpdateDestinationSITServiceItemsAddress(appCtx, updatedShipment) - if err != nil { - return nil, err + // As the API is passed through, we want to apply a breaking change without duplicating lots of code. + // 'prime' is the V1 version of this endpoint. All endpoints besides the prime should be utilizing new logic + // of this function where it no longer calls UpdateDestinationSITServiceItemsAddress. UpdateDestinationSITServiceItemsAddress + // has been deprecated out of this function per E-04819 + if api == "prime" { + err = UpdateDestinationSITServiceItemsAddress(appCtx, updatedShipment) + if err != nil { + return nil, err + } } return updatedShipment, nil diff --git a/pkg/services/mto_shipment/mto_shipment_updater_test.go b/pkg/services/mto_shipment/mto_shipment_updater_test.go index 6ab45de9cc2..391c4e4dbf6 100644 --- a/pkg/services/mto_shipment/mto_shipment_updater_test.go +++ b/pkg/services/mto_shipment/mto_shipment_updater_test.go @@ -144,7 +144,7 @@ func (suite *MTOShipmentServiceSuite) TestMTOShipmentUpdater() { eTag := etag.GenerateEtag(time.Now()) session := auth.Session{} - _, err := mtoShipmentUpdaterCustomer.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &mtoShipment, eTag) + _, err := mtoShipmentUpdaterCustomer.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &mtoShipment, eTag, "test") suite.Error(err) suite.IsType(apperror.PreconditionFailedError{}, err) // Verify that shipment recalculate was handled correctly @@ -168,7 +168,7 @@ func (suite *MTOShipmentServiceSuite) TestMTOShipmentUpdater() { LinkOnly: true, }, }, nil) - updatedShipment, err := mtoShipmentUpdaterCustomer.UpdateMTOShipment(session, &shipment, eTag) + updatedShipment, err := mtoShipmentUpdaterCustomer.UpdateMTOShipment(session, &shipment, eTag, "test") suite.Error(err) suite.Nil(updatedShipment) suite.IsType(apperror.NotFoundError{}, err) @@ -180,7 +180,7 @@ func (suite *MTOShipmentServiceSuite) TestMTOShipmentUpdater() { eTag := etag.GenerateEtag(oldMTOShipment.UpdatedAt) session := auth.Session{} - updatedMTOShipment, err := mtoShipmentUpdaterCustomer.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &mtoShipment, eTag) + updatedMTOShipment, err := mtoShipmentUpdaterCustomer.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &mtoShipment, eTag, "test") suite.Require().NoError(err) suite.Equal(updatedMTOShipment.ID, oldMTOShipment.ID) @@ -207,7 +207,7 @@ func (suite *MTOShipmentServiceSuite) TestMTOShipmentUpdater() { eTag := etag.GenerateEtag(oldMTOShipment2.UpdatedAt) session := auth.Session{} - updatedMTOShipment, err := mtoShipmentUpdaterCustomer.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &mtoShipment2, eTag) + updatedMTOShipment, err := mtoShipmentUpdaterCustomer.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &mtoShipment2, eTag, "test") suite.Require().NoError(err) suite.Equal(updatedMTOShipment.ID, oldMTOShipment2.ID) @@ -247,7 +247,7 @@ func (suite *MTOShipmentServiceSuite) TestMTOShipmentUpdater() { } session := auth.Session{} - newShipment, err := mtoShipmentUpdaterCustomer.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &updatedShipment, eTag) + newShipment, err := mtoShipmentUpdaterCustomer.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &updatedShipment, eTag, "test") suite.Require().NoError(err) suite.FatalNotNil(newShipment.HasSecondaryPickupAddress) @@ -284,7 +284,7 @@ func (suite *MTOShipmentServiceSuite) TestMTOShipmentUpdater() { } session := auth.Session{} - newShipment, err := mtoShipmentUpdaterCustomer.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &updatedShipment, eTag) + newShipment, err := mtoShipmentUpdaterCustomer.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &updatedShipment, eTag, "test") suite.Require().NoError(err) suite.FatalNotNil(newShipment.HasSecondaryDeliveryAddress) @@ -314,7 +314,7 @@ func (suite *MTOShipmentServiceSuite) TestMTOShipmentUpdater() { SecondaryDeliveryAddressID: &secondaryDeliveryAddress.ID, } session := auth.Session{} - updatedShipment, err := mtoShipmentUpdaterCustomer.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), updatedShipment, eTag) + updatedShipment, err := mtoShipmentUpdaterCustomer.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), updatedShipment, eTag, "test") suite.Require().NoError(err) suite.Equal(newDestinationAddress.ID, *updatedShipment.DestinationAddressID) @@ -372,7 +372,7 @@ func (suite *MTOShipmentServiceSuite) TestMTOShipmentUpdater() { } session := auth.Session{} - newShipment, err := mtoShipmentUpdaterCustomer.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &updatedShipment, eTag) + newShipment, err := mtoShipmentUpdaterCustomer.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &updatedShipment, eTag, "test") suite.Require().NoError(err) suite.True(requestedPickupDate.Equal(*newShipment.RequestedPickupDate)) @@ -434,7 +434,7 @@ func (suite *MTOShipmentServiceSuite) TestMTOShipmentUpdater() { CounselorRemarks: &counselorRemarks, } session := auth.Session{} - newShipment, err := mtoShipmentUpdaterCustomer.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &updatedShipment, eTag) + newShipment, err := mtoShipmentUpdaterCustomer.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &updatedShipment, eTag, "test") suite.Require().NoError(err) suite.NotEmpty(newShipment.ApprovedDate) @@ -488,7 +488,7 @@ func (suite *MTOShipmentServiceSuite) TestMTOShipmentUpdater() { OfficeUserID: too.ID, } session.Roles = append(session.Roles, too.User.Roles...) - newShipment, err := mtoShipmentUpdaterOffice.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &updatedShipment, eTag) + newShipment, err := mtoShipmentUpdaterOffice.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &updatedShipment, eTag, "test") suite.Require().NoError(err) suite.Equal(destinationType, *newShipment.DestinationType) @@ -546,7 +546,7 @@ func (suite *MTOShipmentServiceSuite) TestMTOShipmentUpdater() { } session := auth.Session{} - updatedMTOShipment, err := mtoShipmentUpdaterCustomer.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &updatedShipment, eTag) + updatedMTOShipment, err := mtoShipmentUpdaterCustomer.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &updatedShipment, eTag, "test") suite.Require().NoError(err) suite.NotZero(updatedMTOShipment.ID, oldMTOShipment.ID) @@ -599,7 +599,7 @@ func (suite *MTOShipmentServiceSuite) TestMTOShipmentUpdater() { } session := auth.Session{} - updatedMTOShipment, err := mtoShipmentUpdaterCustomer.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &updatedShipment, eTag) + updatedMTOShipment, err := mtoShipmentUpdaterCustomer.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &updatedShipment, eTag, "test") suite.Require().NoError(err) suite.NotZero(updatedMTOShipment.ID, oldMTOShipment.ID) @@ -659,7 +659,7 @@ func (suite *MTOShipmentServiceSuite) TestMTOShipmentUpdater() { } session := auth.Session{} - updatedMTOShipment, err := mtoShipmentUpdaterCustomer.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &updatedShipment, eTag) + updatedMTOShipment, err := mtoShipmentUpdaterCustomer.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &updatedShipment, eTag, "test") suite.Require().NoError(err) suite.NotZero(updatedMTOShipment.ID, oldMTOShipment.ID) @@ -703,7 +703,7 @@ func (suite *MTOShipmentServiceSuite) TestMTOShipmentUpdater() { OfficeUserID: too.ID, } session.Roles = append(session.Roles, too.User.Roles...) - updatedMTOShipment, err := mtoShipmentUpdaterOffice.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &updatedShipment, eTag) + updatedMTOShipment, err := mtoShipmentUpdaterOffice.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &updatedShipment, eTag, "test") suite.Require().NoError(err) suite.NotZero(updatedMTOShipment.ID, oldMTOShipment.ID) @@ -770,7 +770,7 @@ func (suite *MTOShipmentServiceSuite) TestMTOShipmentUpdater() { OfficeUserID: too.ID, } session.Roles = append(session.Roles, too.User.Roles...) - updatedShipment, err := mtoShipmentUpdaterOffice.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &newShipment, eTag) + updatedShipment, err := mtoShipmentUpdaterOffice.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &newShipment, eTag, "test") suite.Require().NoError(err) suite.NotEqual(uuid.Nil, updatedShipment.ID) suite.Equal(&newEmail, updatedShipment.StorageFacility.Email) @@ -802,7 +802,7 @@ func (suite *MTOShipmentServiceSuite) TestMTOShipmentUpdater() { OfficeUserID: too.ID, } session.Roles = append(session.Roles, too.User.Roles...) - updatedMTOShipment, err := mtoShipmentUpdaterOffice.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &updatedShipment, eTag) + updatedMTOShipment, err := mtoShipmentUpdaterOffice.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &updatedShipment, eTag, "test") suite.Require().NoError(err) suite.NotZero(updatedMTOShipment.ID, oldMTOShipment.ID) @@ -834,7 +834,7 @@ func (suite *MTOShipmentServiceSuite) TestMTOShipmentUpdater() { OfficeUserID: too.ID, } session.Roles = append(session.Roles, too.User.Roles...) - updatedMTOShipment, err := mtoShipmentUpdaterOffice.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &updatedShipment, eTag) + updatedMTOShipment, err := mtoShipmentUpdaterOffice.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &updatedShipment, eTag, "test") suite.Require().Error(err) suite.Nil(updatedMTOShipment) @@ -878,7 +878,7 @@ func (suite *MTOShipmentServiceSuite) TestMTOShipmentUpdater() { Diversion: true, } session := auth.Session{} - updatedShipment, err := mtoShipmentUpdaterCustomer.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &shipmentInput, eTag) + updatedShipment, err := mtoShipmentUpdaterCustomer.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &shipmentInput, eTag, "test") suite.Require().NotNil(updatedShipment) suite.NoError(err) @@ -957,7 +957,7 @@ func (suite *MTOShipmentServiceSuite) TestMTOShipmentUpdater() { suite.FatalNoError(err) session := auth.Session{} - newShipment, err := mtoShipmentUpdaterPrime.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &updatedShipment, eTag) + newShipment, err := mtoShipmentUpdaterPrime.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &updatedShipment, eTag, "test") suite.Require().NoError(err) suite.NotEmpty(newShipment.ApprovedDate) @@ -1036,7 +1036,7 @@ func (suite *MTOShipmentServiceSuite) TestMTOShipmentUpdater() { suite.FatalNoError(err) session := auth.Session{} - _, err = mtoShipmentUpdaterPrime.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &updatedShipment, eTag) + _, err = mtoShipmentUpdaterPrime.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &updatedShipment, eTag, "test") suite.Error(err) suite.Contains(err.Error(), "cannot be updated after initial estimation") @@ -1069,7 +1069,7 @@ func (suite *MTOShipmentServiceSuite) TestMTOShipmentUpdater() { } session := auth.Session{} - newShipment, err := mtoShipmentUpdaterPrime.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &updatedShipment, eTag) + newShipment, err := mtoShipmentUpdaterPrime.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &updatedShipment, eTag, "test") suite.Require().NoError(err) suite.NotEmpty(newShipment.Reweigh) @@ -1134,7 +1134,7 @@ func (suite *MTOShipmentServiceSuite) TestMTOShipmentUpdater() { suite.FatalNoError(err) session := auth.Session{} - _, err = mtoShipmentUpdaterPrime.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &updatedShipment, eTag) + _, err = mtoShipmentUpdaterPrime.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &updatedShipment, eTag, "test") suite.Error(err) suite.Contains(err.Error(), "the time period for updating the estimated weight for a shipment has expired, please contact the TOO directly to request updates to this shipment’s estimated weight") @@ -1208,7 +1208,7 @@ func (suite *MTOShipmentServiceSuite) TestMTOShipmentUpdater() { suite.FatalNoError(err) session := auth.Session{} - _, err = mtoShipmentUpdaterPrime.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &updatedShipment, eTag) + _, err = mtoShipmentUpdaterPrime.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &updatedShipment, eTag, "test") suite.Error(err) suite.Contains(err.Error(), "cannot add or update MTO agents to a shipment") @@ -1272,7 +1272,7 @@ func (suite *MTOShipmentServiceSuite) TestMTOShipmentUpdater() { suite.FatalNoError(err) session := auth.Session{} - _, err = mtoShipmentUpdaterPrime.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &updatedShipment, eTag) + _, err = mtoShipmentUpdaterPrime.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &updatedShipment, eTag, "test") suite.Error(err) suite.Contains(err.Error(), "the pickup address already exists and cannot be updated with this endpoint") @@ -1326,7 +1326,7 @@ func (suite *MTOShipmentServiceSuite) TestMTOShipmentUpdater() { } session := auth.Session{} - _, err := mtoShipmentUpdaterPrime.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &updatedShipment, eTag) + _, err := mtoShipmentUpdaterPrime.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &updatedShipment, eTag, "test") suite.Error(err) suite.Contains(err.Error(), "failed to find transit time for shipment of 9000 lbs weight and 1000 mile distance") @@ -1390,7 +1390,7 @@ func (suite *MTOShipmentServiceSuite) TestMTOShipmentUpdater() { suite.FatalNoError(err) session := auth.Session{} - newShipment, err := mtoShipmentUpdaterPrime.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &updatedShipment, eTag) + newShipment, err := mtoShipmentUpdaterPrime.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &updatedShipment, eTag, "test") suite.Require().NoError(err) suite.NotEmpty(newShipment.ApprovedDate) @@ -1463,7 +1463,7 @@ func (suite *MTOShipmentServiceSuite) TestMTOShipmentUpdater() { suite.FatalNoError(err) session := auth.Session{} - newShipment, err := mtoShipmentUpdaterPrime.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &updatedShipment, eTag) + newShipment, err := mtoShipmentUpdaterPrime.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &updatedShipment, eTag, "test") suite.Require().NoError(err) suite.NotEmpty(newShipment.ApprovedDate) suite.True(requestedPickupDate.Equal(*newShipment.RequestedPickupDate)) @@ -2325,7 +2325,7 @@ func (suite *MTOShipmentServiceSuite) TestUpdateShipmentEstimatedWeightMoveExces suite.Equal(models.MoveStatusAPPROVED, primeShipment.MoveTaskOrder.Status) session := auth.Session{} - _, err := mtoShipmentUpdaterPrime.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &primeShipment, etag.GenerateEtag(primeShipment.UpdatedAt)) + _, err := mtoShipmentUpdaterPrime.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &primeShipment, etag.GenerateEtag(primeShipment.UpdatedAt), "test") suite.NoError(err) err = suite.DB().Reload(&primeShipment.MoveTaskOrder) @@ -2369,7 +2369,7 @@ func (suite *MTOShipmentServiceSuite) TestUpdateShipmentEstimatedWeightMoveExces suite.Nil(primeShipment.MoveTaskOrder.ExcessWeightQualifiedAt) session := auth.Session{} - _, err := mockedUpdater.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &primeShipment, etag.GenerateEtag(primeShipment.UpdatedAt)) + _, err := mockedUpdater.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &primeShipment, etag.GenerateEtag(primeShipment.UpdatedAt), "test") suite.NoError(err) moveWeights.AssertNotCalled(suite.T(), "CheckExcessWeight") @@ -2408,7 +2408,7 @@ func (suite *MTOShipmentServiceSuite) TestUpdateShipmentEstimatedWeightMoveExces suite.Nil(primeShipment.MoveTaskOrder.ExcessWeightQualifiedAt) session := auth.Session{} - _, err := mockedUpdater.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &primeShipment, etag.GenerateEtag(primeShipment.UpdatedAt)) + _, err := mockedUpdater.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &primeShipment, etag.GenerateEtag(primeShipment.UpdatedAt), "test") suite.Error(err) suite.Contains(err.Error(), "cannot be updated after initial estimation") @@ -2458,7 +2458,7 @@ func (suite *MTOShipmentServiceSuite) TestUpdateShipmentActualWeightAutoReweigh( primeShipment.PrimeActualWeight = &actualWeight session := auth.Session{} - _, err := mtoShipmentUpdaterPrime.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &primeShipment, etag.GenerateEtag(primeShipment.UpdatedAt)) + _, err := mtoShipmentUpdaterPrime.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &primeShipment, etag.GenerateEtag(primeShipment.UpdatedAt), "test") suite.NoError(err) err = suite.DB().Eager("Reweigh").Reload(&primeShipment) @@ -2502,7 +2502,7 @@ func (suite *MTOShipmentServiceSuite) TestUpdateShipmentActualWeightAutoReweigh( moveWeights.On("CheckExcessWeight", mock.AnythingOfType("*appcontext.appContext"), primeShipment.MoveTaskOrderID, mock.AnythingOfType("models.MTOShipment")).Return(&primeShipment.MoveTaskOrder, nil, nil) session := auth.Session{} - _, err := mockedUpdater.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &primeShipment, etag.GenerateEtag(primeShipment.UpdatedAt)) + _, err := mockedUpdater.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &primeShipment, etag.GenerateEtag(primeShipment.UpdatedAt), "test") suite.NoError(err) moveWeights.AssertNotCalled(suite.T(), "CheckAutoReweigh") @@ -2539,7 +2539,7 @@ func (suite *MTOShipmentServiceSuite) TestUpdateShipmentActualWeightAutoReweigh( primeShipment.PrimeActualWeight = &actualWeight session := auth.Session{} - _, err := mockedUpdater.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &primeShipment, etag.GenerateEtag(primeShipment.UpdatedAt)) + _, err := mockedUpdater.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), &primeShipment, etag.GenerateEtag(primeShipment.UpdatedAt), "test") suite.NoError(err) moveWeights.AssertNotCalled(suite.T(), "CheckAutoReweigh") @@ -2590,7 +2590,7 @@ func (suite *MTOShipmentServiceSuite) TestUpdateShipmentNullableFields() { OfficeUserID: too.ID, } session.Roles = append(session.Roles, too.User.Roles...) - _, err := mockedUpdater.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), requestedUpdate, etag.GenerateEtag(ntsMove.MTOShipments[0].UpdatedAt)) + _, err := mockedUpdater.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), requestedUpdate, etag.GenerateEtag(ntsMove.MTOShipments[0].UpdatedAt), "test") suite.NoError(err) suite.Equal(nil, nil) suite.Equal(nil, nil) @@ -2627,7 +2627,7 @@ func (suite *MTOShipmentServiceSuite) TestUpdateShipmentNullableFields() { OfficeUserID: too.ID, } session.Roles = append(session.Roles, too.User.Roles...) - updatedMtoShipment, err := mockedUpdater.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), requestedUpdate, etag.GenerateEtag(shipment.UpdatedAt)) + updatedMtoShipment, err := mockedUpdater.UpdateMTOShipment(suite.AppContextWithSessionForTest(&session), requestedUpdate, etag.GenerateEtag(shipment.UpdatedAt), "test") suite.NoError(err) suite.Equal(*requestedUpdate.TACType, *updatedMtoShipment.TACType) suite.Equal(*shipment.SACType, *updatedMtoShipment.SACType) diff --git a/pkg/services/orchestrators/shipment/shipment_updater.go b/pkg/services/orchestrators/shipment/shipment_updater.go index 11889e53531..21e3d3cb12f 100644 --- a/pkg/services/orchestrators/shipment/shipment_updater.go +++ b/pkg/services/orchestrators/shipment/shipment_updater.go @@ -23,7 +23,7 @@ func NewShipmentUpdater(mtoShipmentUpdater services.MTOShipmentUpdater, ppmShipm } // UpdateShipment updates a shipment, taking into account different shipment types and their needs. -func (s *shipmentUpdater) UpdateShipment(appCtx appcontext.AppContext, shipment *models.MTOShipment, eTag string) (*models.MTOShipment, error) { +func (s *shipmentUpdater) UpdateShipment(appCtx appcontext.AppContext, shipment *models.MTOShipment, eTag string, api string) (*models.MTOShipment, error) { if err := validateShipment(appCtx, *shipment, s.checks...); err != nil { return nil, err } @@ -31,7 +31,7 @@ func (s *shipmentUpdater) UpdateShipment(appCtx appcontext.AppContext, shipment var mtoShipment *models.MTOShipment txErr := appCtx.NewTransaction(func(txnAppCtx appcontext.AppContext) (err error) { - mtoShipment, err = s.mtoShipmentUpdater.UpdateMTOShipment(txnAppCtx, shipment, eTag) + mtoShipment, err = s.mtoShipmentUpdater.UpdateMTOShipment(txnAppCtx, shipment, eTag, api) if err != nil { return err diff --git a/pkg/services/orchestrators/shipment/shipment_updater_test.go b/pkg/services/orchestrators/shipment/shipment_updater_test.go index 829bb6961ca..f35b63f2f91 100644 --- a/pkg/services/orchestrators/shipment/shipment_updater_test.go +++ b/pkg/services/orchestrators/shipment/shipment_updater_test.go @@ -49,6 +49,7 @@ func (suite *ShipmentSuite) TestUpdateShipment() { updateMTOShipmentMethodName, mock.AnythingOfType("*appcontext.appContext"), mock.AnythingOfType("*models.MTOShipment"), + mock.AnythingOfType("string"), mock.AnythingOfType("string")). Return(nil, subtestData.fakeError) } else { @@ -57,20 +58,12 @@ func (suite *ShipmentSuite) TestUpdateShipment() { updateMTOShipmentMethodName, mock.AnythingOfType("*appcontext.appContext"), mock.AnythingOfType("*models.MTOShipment"), + mock.AnythingOfType("string"), mock.AnythingOfType("string")). Return( - func(_ appcontext.AppContext, ship *models.MTOShipment, _ string) *models.MTOShipment { - // Mimicking how the MTOShipment updater actually returns a new pointer so that we can test - // a bit more realistically while still using mocks. - updatedShip := *ship - updatedShip.PPMShipment = nil // Currently returns an MTOShipment without PPMShipment info - - return &updatedShip - }, - func(_ appcontext.AppContext, ship *models.MTOShipment, _ string) error { - return nil - }, - ) + &models.MTOShipment{ + ID: uuid.Must(uuid.FromString("a5e95c1d-97c3-4f79-8097-c12dd2557ac7")), + }, nil) } if returnErrorForPPMShipment { @@ -91,6 +84,7 @@ func (suite *ShipmentSuite) TestUpdateShipment() { mock.AnythingOfType("*appcontext.appContext"), mock.AnythingOfType("*models.PPMShipment"), mock.AnythingOfType("uuid.UUID"), + mock.AnythingOfType("string"), ). Return( func(_ appcontext.AppContext, ship *models.PPMShipment, _ uuid.UUID) *models.PPMShipment { @@ -119,7 +113,7 @@ func (suite *ShipmentSuite) TestUpdateShipment() { // Set invalid data, can't pass in blank to the generator above (it'll default to HHG if blank) so we're setting it afterward. shipment.ShipmentType = "" - updatedShipment, err := subtestData.shipmentUpdaterOrchestrator.UpdateShipment(appCtx, &shipment, etag.GenerateEtag(shipment.UpdatedAt)) + updatedShipment, err := subtestData.shipmentUpdaterOrchestrator.UpdateShipment(appCtx, &shipment, etag.GenerateEtag(shipment.UpdatedAt), "test") suite.Nil(updatedShipment) @@ -156,6 +150,7 @@ func (suite *ShipmentSuite) TestUpdateShipment() { shipment = factory.BuildMTOShipment(appCtx.DB(), []factory.Customization{ { Model: models.MTOShipment{ + ID: uuid.Must(uuid.FromString("a5e95c1d-97c3-4f79-8097-c12dd2557ac7")), ShipmentType: shipmentType, }, }, @@ -166,7 +161,7 @@ func (suite *ShipmentSuite) TestUpdateShipment() { // Need to start a transaction so we can assert the call with the correct appCtx err := appCtx.NewTransaction(func(txAppCtx appcontext.AppContext) error { - mtoShipment, err := subtestData.shipmentUpdaterOrchestrator.UpdateShipment(txAppCtx, &shipment, eTag) + mtoShipment, err := subtestData.shipmentUpdaterOrchestrator.UpdateShipment(txAppCtx, &shipment, eTag, "test") suite.NoError(err) suite.NotNil(mtoShipment) @@ -177,6 +172,7 @@ func (suite *ShipmentSuite) TestUpdateShipment() { txAppCtx, &shipment, eTag, + "test", ) if isPPMShipment { @@ -185,7 +181,7 @@ func (suite *ShipmentSuite) TestUpdateShipment() { updatePPMShipmentMethodName, txAppCtx, shipment.PPMShipment, - shipment.ID, + uuid.Must(uuid.FromString("a5e95c1d-97c3-4f79-8097-c12dd2557ac7")), ) } else { subtestData.mockPPMShipmentUpdater.AssertNotCalled( @@ -194,6 +190,7 @@ func (suite *ShipmentSuite) TestUpdateShipment() { mock.AnythingOfType("*appcontext.appContext"), mock.AnythingOfType("*models.PPMShipment"), mock.AnythingOfType("uuid.UUID"), + mock.AnythingOfType("string"), ) } @@ -223,7 +220,7 @@ func (suite *ShipmentSuite) TestUpdateShipment() { // set new field to update shipment.PPMShipment.HasProGear = models.BoolPointer(false) - mtoShipment, err := subtestData.shipmentUpdaterOrchestrator.UpdateShipment(appCtx, &shipment, etag.GenerateEtag(shipment.UpdatedAt)) + mtoShipment, err := subtestData.shipmentUpdaterOrchestrator.UpdateShipment(appCtx, &shipment, etag.GenerateEtag(shipment.UpdatedAt), "test") suite.NoError(err) @@ -280,7 +277,7 @@ func (suite *ShipmentSuite) TestUpdateShipment() { }, nil) } - mtoShipment, err := subtestData.shipmentUpdaterOrchestrator.UpdateShipment(appCtx, &shipment, etag.GenerateEtag(shipment.UpdatedAt)) + mtoShipment, err := subtestData.shipmentUpdaterOrchestrator.UpdateShipment(appCtx, &shipment, etag.GenerateEtag(shipment.UpdatedAt), "test") suite.Nil(mtoShipment) @@ -304,7 +301,7 @@ func (suite *ShipmentSuite) TestUpdateShipment() { eTag := etag.GenerateEtag(shipment.UpdatedAt) - mtoShipment, err := subtestData.shipmentUpdaterOrchestrator.UpdateShipment(appCtx, &shipment, eTag) + mtoShipment, err := subtestData.shipmentUpdaterOrchestrator.UpdateShipment(appCtx, &shipment, eTag, "test") suite.Nil(mtoShipment) @@ -317,6 +314,7 @@ func (suite *ShipmentSuite) TestUpdateShipment() { mock.AnythingOfType("*appcontext.appContext"), &shipment, eTag, + "test", ) subtestData.mockPPMShipmentUpdater.AssertNotCalled( diff --git a/pkg/services/shipment_orchestrator.go b/pkg/services/shipment_orchestrator.go index c1df4f333b4..69168e8f997 100644 --- a/pkg/services/shipment_orchestrator.go +++ b/pkg/services/shipment_orchestrator.go @@ -16,5 +16,5 @@ type ShipmentCreator interface { // //go:generate mockery --name ShipmentUpdater type ShipmentUpdater interface { - UpdateShipment(appCtx appcontext.AppContext, shipment *models.MTOShipment, eTag string) (*models.MTOShipment, error) + UpdateShipment(appCtx appcontext.AppContext, shipment *models.MTOShipment, eTag string, api string) (*models.MTOShipment, error) } diff --git a/swagger-def/prime.yaml b/swagger-def/prime.yaml index b95cbc7bf02..d36a073d27d 100644 --- a/swagger-def/prime.yaml +++ b/swagger-def/prime.yaml @@ -320,6 +320,14 @@ paths: patch: summary: updateMTOShipment description: | + _[Deprecated: sunset on August 5th, 2024]_ This endpoint is deprecated and will be removed in a future version. + Please use the new endpoint at `/prime/v2/updateMTOShipment` instead. + + **DEPRECATION ON AUGUST 5TH, 2024** + Following deprecation, there is an edge case scenario where a PPM shipment with no addresses could be updated and it would also update the final destination SIT address + for SIT service items. This edge case has been removed as you should not be able to update items using this endpoint. Third-party APIs have confirmed they will require + deprecation for this change. + Updates an existing shipment for a move. Note that there are some restrictions on nested objects: diff --git a/swagger-def/prime_v2.yaml b/swagger-def/prime_v2.yaml index 493cbe90371..9586aa21fcb 100644 --- a/swagger-def/prime_v2.yaml +++ b/swagger-def/prime_v2.yaml @@ -169,6 +169,123 @@ paths: $ref: 'responses/UnprocessableEntity.yaml' '500': $ref: '#/responses/ServerError' + /mto-shipments/{mtoShipmentID}: + patch: + summary: updateMTOShipment + description: | + Updates an existing shipment for a move. + + Note that there are some restrictions on nested objects: + + * Service items: You cannot add or update service items using this endpoint. Please use [createMTOServiceItem](#operation/createMTOServiceItem) and [updateMTOServiceItem](#operation/updateMTOServiceItem) instead. + * Agents: You cannot add or update agents using this endpoint. Please use [createMTOAgent](#operation/createMTOAgent) and [updateMTOAgent](#operation/updateMTOAgent) instead. + * Addresses: You can add new addresses using this endpoint (and must use this endpoint to do so), but you cannot update existing ones. Please use [updateMTOShipmentAddress](#operation/updateMTOShipmentAddress) instead. + + These restrictions are due to our [optimistic locking/concurrency control](https://transcom.github.io/mymove-docs/docs/dev/contributing/backend/use-optimistic-locking) mechanism. + + Note that some fields cannot be manually changed but will still be updated automatically, such as `primeEstimatedWeightRecordedDate` and `requiredDeliveryDate`. + operationId: updateMTOShipment + tags: + - mtoShipment + consumes: + - application/json + produces: + - application/json + parameters: + - in: path + name: mtoShipmentID + description: UUID of the shipment being updated. + required: true + format: uuid + type: string + - in: body + name: body + required: true + schema: + $ref: '#/definitions/UpdateMTOShipment' + x-examples: + application/json: + hhg: + summary: HHG + value: + { + 'scheduledPickupDate': '2022-12-30', + 'actualPickupDate': '2022-12-29', + 'firstAvailableDeliveryDate': '2023-01-04', + 'primeEstimatedWeight': 4250, + 'primeActualWeight': 4500, + 'destinationAddress': + { + 'streetAddress1': '6622 Airport Way S', + 'streetAddress2': '#1430', + 'city': 'Great Bend', + 'state': 'NY', + 'postalCode': '13643', + }, + 'pointOfContact': 'peyton.wing@example.com', + } + nts: + summary: NTS + value: + { + 'moveTaskOrderId': '5691c951-c35c-49a8-a1d5-a4b7ea7b7ad8', + 'scheduledPickupDate': '2022-12-30', + 'actualPickupDate': '2022-12-29', + 'estimatedWeight': 4250, + 'actualWeight': 4500, + 'counselorRemarks': 'Beware of dogs on property', + } + nts-r: + summary: NTS Release + value: + { + 'moveTaskOrderId': '5691c951-c35c-49a8-a1d5-a4b7ea7b7ad8', + 'ntsRecordedWeight': 4500, + 'destinationAddress': + { + 'streetAddress1': '812 S 129th Street', + 'city': 'San Antonio', + 'state': 'TX', + 'postalCode': '78245', + }, + } + ppm: + summary: PPM + value: + { + 'moveTaskOrderId': '5691c951-c35c-49a8-a1d5-a4b7ea7b7ad8', + 'ppmShipment': + { + 'hasProGear': true, + 'proGearWeight': 830, + 'spouseProGearWeight': 366, + 'sitExpected': true, + 'sitLocation': 'DESTINATION', + 'sitEstimatedWeight': 1760, + 'sitEstimatedEntryDate': '2022-10-06', + 'sitEstimatedDepartureDate': '2022-10-13', + }, + } + - $ref: 'parameters/ifMatch.yaml' + responses: + '200': + description: Successfully updated the MTO shipment. + schema: + $ref: '#/definitions/MTOShipment' + '400': + $ref: '#/responses/InvalidRequest' + '401': + $ref: 'responses/PermissionDenied.yaml' + '403': + $ref: 'responses/PermissionDenied.yaml' + '404': + $ref: 'responses/NotFound.yaml' + '412': + $ref: '#/responses/PreconditionFailed' + '422': + $ref: 'responses/UnprocessableEntity.yaml' + '500': + $ref: '#/responses/ServerError' definitions: MTOServiceItemBasic: # spectral oas2-unused-definition is OK here due to polymorphism $ref: 'definitions/prime/MTOServiceItemBasic.yaml' @@ -781,3 +898,7 @@ responses: description: The request payload is invalid. schema: $ref: 'definitions/ClientError.yaml' + PreconditionFailed: + description: Precondition failed, likely due to a stale eTag (If-Match). Fetch the request again to get the updated eTag value. + schema: + $ref: 'definitions/ClientError.yaml' diff --git a/swagger/prime.yaml b/swagger/prime.yaml index 92ac50161de..2d3e9a15807 100644 --- a/swagger/prime.yaml +++ b/swagger/prime.yaml @@ -394,6 +394,25 @@ paths: patch: summary: updateMTOShipment description: > + _[Deprecated: sunset on August 5th, 2024]_ This endpoint is deprecated + and will be removed in a future version. + + Please use the new endpoint at `/prime/v2/updateMTOShipment` instead. + + + **DEPRECATION ON AUGUST 5TH, 2024** + + Following deprecation, there is an edge case scenario where a PPM + shipment with no addresses could be updated and it would also update the + final destination SIT address + + for SIT service items. This edge case has been removed as you should not + be able to update items using this endpoint. Third-party APIs have + confirmed they will require + + deprecation for this change. + + Updates an existing shipment for a move. diff --git a/swagger/prime_v2.yaml b/swagger/prime_v2.yaml index a6e6fe6faad..1795274e3e2 100644 --- a/swagger/prime_v2.yaml +++ b/swagger/prime_v2.yaml @@ -201,6 +201,126 @@ paths: $ref: '#/responses/UnprocessableEntity' '500': $ref: '#/responses/ServerError' + /mto-shipments/{mtoShipmentID}: + patch: + summary: updateMTOShipment + description: > + Updates an existing shipment for a move. + + + Note that there are some restrictions on nested objects: + + + * Service items: You cannot add or update service items using this + endpoint. Please use + [createMTOServiceItem](#operation/createMTOServiceItem) and + [updateMTOServiceItem](#operation/updateMTOServiceItem) instead. + + * Agents: You cannot add or update agents using this endpoint. Please + use [createMTOAgent](#operation/createMTOAgent) and + [updateMTOAgent](#operation/updateMTOAgent) instead. + + * Addresses: You can add new addresses using this endpoint (and must use + this endpoint to do so), but you cannot update existing ones. Please use + [updateMTOShipmentAddress](#operation/updateMTOShipmentAddress) instead. + + + These restrictions are due to our [optimistic locking/concurrency + control](https://transcom.github.io/mymove-docs/docs/dev/contributing/backend/use-optimistic-locking) + mechanism. + + + Note that some fields cannot be manually changed but will still be + updated automatically, such as `primeEstimatedWeightRecordedDate` and + `requiredDeliveryDate`. + operationId: updateMTOShipment + tags: + - mtoShipment + consumes: + - application/json + produces: + - application/json + parameters: + - in: path + name: mtoShipmentID + description: UUID of the shipment being updated. + required: true + format: uuid + type: string + - in: body + name: body + required: true + schema: + $ref: '#/definitions/UpdateMTOShipment' + x-examples: + application/json: + hhg: + summary: HHG + value: + scheduledPickupDate: '2022-12-30' + actualPickupDate: '2022-12-29' + firstAvailableDeliveryDate: '2023-01-04' + primeEstimatedWeight: 4250 + primeActualWeight: 4500 + destinationAddress: + streetAddress1: 6622 Airport Way S + streetAddress2: '#1430' + city: Great Bend + state: NY + postalCode: '13643' + pointOfContact: peyton.wing@example.com + nts: + summary: NTS + value: + moveTaskOrderId: 5691c951-c35c-49a8-a1d5-a4b7ea7b7ad8 + scheduledPickupDate: '2022-12-30' + actualPickupDate: '2022-12-29' + estimatedWeight: 4250 + actualWeight: 4500 + counselorRemarks: Beware of dogs on property + nts-r: + summary: NTS Release + value: + moveTaskOrderId: 5691c951-c35c-49a8-a1d5-a4b7ea7b7ad8 + ntsRecordedWeight: 4500 + destinationAddress: + streetAddress1: 812 S 129th Street + city: San Antonio + state: TX + postalCode: '78245' + ppm: + summary: PPM + value: + moveTaskOrderId: 5691c951-c35c-49a8-a1d5-a4b7ea7b7ad8 + ppmShipment: + hasProGear: true + proGearWeight: 830 + spouseProGearWeight: 366 + sitExpected: true + sitLocation: DESTINATION + sitEstimatedWeight: 1760 + sitEstimatedEntryDate: '2022-10-06' + sitEstimatedDepartureDate: '2022-10-13' + - $ref: '#/parameters/ifMatch' + responses: + '200': + description: Successfully updated the MTO shipment. + schema: + $ref: '#/definitions/MTOShipment' + '400': + $ref: '#/responses/InvalidRequest' + '401': + $ref: '#/responses/PermissionDenied' + '403': + $ref: '#/responses/PermissionDenied' + '404': + $ref: '#/responses/NotFound' + '412': + $ref: '#/responses/PreconditionFailed' + '422': + $ref: '#/responses/UnprocessableEntity' + '500': + $ref: '#/responses/ServerError' definitions: MTOServiceItemBasic: description: Describes a basic service item subtype of a MTOServiceItem. @@ -2945,6 +3065,12 @@ responses: description: The request payload is invalid. schema: $ref: '#/definitions/ClientError' + PreconditionFailed: + description: >- + Precondition failed, likely due to a stale eTag (If-Match). Fetch the + request again to get the updated eTag value. + schema: + $ref: '#/definitions/ClientError' PermissionDenied: description: The request was denied. schema: @@ -2957,3 +3083,13 @@ responses: description: The request was unprocessable, likely due to bad input from the requester. schema: $ref: '#/definitions/ValidationError' +parameters: + ifMatch: + in: header + name: If-Match + type: string + required: true + description: > + Optimistic locking is implemented via the `If-Match` header. If the ETag + header does not match the value of the resource on the server, the server + rejects the change with a `412 Precondition Failed` error.