diff --git a/pkg/gen/primeapi/embedded_spec.go b/pkg/gen/primeapi/embedded_spec.go index 078047d49db..40ab33d6356 100644 --- a/pkg/gen/primeapi/embedded_spec.go +++ b/pkg/gen/primeapi/embedded_spec.go @@ -343,7 +343,7 @@ func init() { }, "/mto-service-items/{mtoServiceItemID}": { "patch": { - "description": "Updates MTOServiceItems after creation. Not all service items or fields may be updated, please see details below.\n\nThis endpoint supports different body definitions. In the modelType field below, select the modelType corresponding\n to the service item you wish to update and the documentation will update with the new definition.\n\n* Addresses: You can add a new SIT Destination final address using this endpoint (and must use this endpoint to do so), but you cannot update an existing one.\nPlease use [createSITAddressUpdateRequest](#operation/createSITAddressUpdateRequest) instead.\n\nTo create a service item, please use [createMTOServiceItem](#operation/createMTOServiceItem)) endpoint.\n", + "description": "Updates MTOServiceItems after creation. Not all service items or fields may be updated, please see details below.\n\nThis endpoint supports different body definitions. In the modelType field below, select the modelType corresponding\n to the service item you wish to update and the documentation will update with the new definition.\n\n* Addresses: To update a destination service item's SIT destination final address, update the shipment destination address.\nFor approved shipments, please use [updateShipmentDestinationAddress](#mtoShipment/updateShipmentDestinationAddress).\nFor shipments not yet approved, please use [updateMTOShipmentAddress](#mtoShipment/updateMTOShipmentAddress).\n\nTo create a service item, please use [createMTOServiceItem](#mtoServiceItem/createMTOServiceItem)) endpoint.\n", "consumes": [ "application/json" ], @@ -5096,7 +5096,7 @@ func init() { }, "/mto-service-items/{mtoServiceItemID}": { "patch": { - "description": "Updates MTOServiceItems after creation. Not all service items or fields may be updated, please see details below.\n\nThis endpoint supports different body definitions. In the modelType field below, select the modelType corresponding\n to the service item you wish to update and the documentation will update with the new definition.\n\n* Addresses: You can add a new SIT Destination final address using this endpoint (and must use this endpoint to do so), but you cannot update an existing one.\nPlease use [createSITAddressUpdateRequest](#operation/createSITAddressUpdateRequest) instead.\n\nTo create a service item, please use [createMTOServiceItem](#operation/createMTOServiceItem)) endpoint.\n", + "description": "Updates MTOServiceItems after creation. Not all service items or fields may be updated, please see details below.\n\nThis endpoint supports different body definitions. In the modelType field below, select the modelType corresponding\n to the service item you wish to update and the documentation will update with the new definition.\n\n* Addresses: To update a destination service item's SIT destination final address, update the shipment destination address.\nFor approved shipments, please use [updateShipmentDestinationAddress](#mtoShipment/updateShipmentDestinationAddress).\nFor shipments not yet approved, please use [updateMTOShipmentAddress](#mtoShipment/updateMTOShipmentAddress).\n\nTo create a service item, please use [createMTOServiceItem](#mtoServiceItem/createMTOServiceItem)) endpoint.\n", "consumes": [ "application/json" ], diff --git a/pkg/gen/primeapi/primeoperations/mto_service_item/update_m_t_o_service_item.go b/pkg/gen/primeapi/primeoperations/mto_service_item/update_m_t_o_service_item.go index e56e48d8c18..58599c58b35 100644 --- a/pkg/gen/primeapi/primeoperations/mto_service_item/update_m_t_o_service_item.go +++ b/pkg/gen/primeapi/primeoperations/mto_service_item/update_m_t_o_service_item.go @@ -40,10 +40,11 @@ This endpoint supports different body definitions. In the modelType field below, to the service item you wish to update and the documentation will update with the new definition. -* Addresses: You can add a new SIT Destination final address using this endpoint (and must use this endpoint to do so), but you cannot update an existing one. -Please use [createSITAddressUpdateRequest](#operation/createSITAddressUpdateRequest) instead. +* Addresses: To update a destination service item's SIT destination final address, update the shipment destination address. +For approved shipments, please use [updateShipmentDestinationAddress](#mtoShipment/updateShipmentDestinationAddress). +For shipments not yet approved, please use [updateMTOShipmentAddress](#mtoShipment/updateMTOShipmentAddress). -To create a service item, please use [createMTOServiceItem](#operation/createMTOServiceItem)) endpoint. +To create a service item, please use [createMTOServiceItem](#mtoServiceItem/createMTOServiceItem)) endpoint. */ type UpdateMTOServiceItem struct { Context *middleware.Context diff --git a/pkg/gen/primeclient/mto_service_item/mto_service_item_client.go b/pkg/gen/primeclient/mto_service_item/mto_service_item_client.go index 94b9a7d78a1..25d289f4999 100644 --- a/pkg/gen/primeclient/mto_service_item/mto_service_item_client.go +++ b/pkg/gen/primeclient/mto_service_item/mto_service_item_client.go @@ -220,10 +220,11 @@ This endpoint supports different body definitions. In the modelType field below, to the service item you wish to update and the documentation will update with the new definition. -* Addresses: You can add a new SIT Destination final address using this endpoint (and must use this endpoint to do so), but you cannot update an existing one. -Please use [createSITAddressUpdateRequest](#operation/createSITAddressUpdateRequest) instead. +* Addresses: To update a destination service item's SIT destination final address, update the shipment destination address. +For approved shipments, please use [updateShipmentDestinationAddress](#mtoShipment/updateShipmentDestinationAddress). +For shipments not yet approved, please use [updateMTOShipmentAddress](#mtoShipment/updateMTOShipmentAddress). -To create a service item, please use [createMTOServiceItem](#operation/createMTOServiceItem)) endpoint. +To create a service item, please use [createMTOServiceItem](#mtoServiceItem/createMTOServiceItem)) endpoint. */ func (a *Client) UpdateMTOServiceItem(params *UpdateMTOServiceItemParams, opts ...ClientOption) (*UpdateMTOServiceItemOK, error) { // TODO: Validate the params before sending diff --git a/pkg/services/mto_service_item/mto_service_item_validators.go b/pkg/services/mto_service_item/mto_service_item_validators.go index 7365563e253..f99aeb4c0db 100644 --- a/pkg/services/mto_service_item/mto_service_item_validators.go +++ b/pkg/services/mto_service_item/mto_service_item_validators.go @@ -377,15 +377,16 @@ func (v *updateMTOServiceItemData) checkSITDestinationFinalAddress(_ appcontext. return nil // the SITDestinationFinalAddress is being created, so we're fine here } - if v.oldServiceItem.ReService.Code != models.ReServiceCodeDDDSIT { - return apperror.NewConflictError(v.updatedServiceItem.ID, - fmt.Sprintf("- SIT Destination Final Address may only be manually created for %s service items.", models.ReServiceCodeDDDSIT)) + reServiceCodesDestination := []models.ReServiceCode{models.ReServiceCodeDDDSIT, models.ReServiceCodeDDASIT, models.ReServiceCodeDDFSIT, models.ReServiceCodeDDSFSC} + if slices.Contains(reServiceCodesDestination, v.oldServiceItem.ReService.Code) { + v.verrs.Add("SITDestinationFinalAddress", "Update the shipment destination address to update the service item's SIT final destination address.") + return nil } if *v.oldServiceItem.SITDestinationFinalAddressID != uuid.Nil && v.updatedServiceItem.SITDestinationFinalAddress != nil && v.updatedServiceItem.SITDestinationFinalAddress.ID != *v.oldServiceItem.SITDestinationFinalAddressID { - v.verrs.Add("SITDestinationFinalAddress", "cannot be updated") + v.verrs.Add("SITDestinationFinalAddress", "Update the shipment destination address to update the service item's SIT final destination address.") } return nil diff --git a/pkg/services/mto_service_item/mto_service_item_validators_test.go b/pkg/services/mto_service_item/mto_service_item_validators_test.go index b311ebfcc9a..11cd6d39fc3 100644 --- a/pkg/services/mto_service_item/mto_service_item_validators_test.go +++ b/pkg/services/mto_service_item/mto_service_item_validators_test.go @@ -613,7 +613,7 @@ func (suite *MTOServiceItemServiceSuite) TestUpdateMTOServiceItemData() { } }) - suite.Run("checkSITDestinationFinalAddress - adding SITDestinationFinalAddress", func() { + suite.Run("checkSITDestinationFinalAddress - adding SITDestinationFinalAddress for origin SIT service item", func() { oldServiceItemPrime := factory.BuildMTOServiceItem(suite.DB(), []factory.Customization{ { Model: factory.BuildAvailableToPrimeMove(suite.DB(), nil, nil), @@ -621,7 +621,7 @@ func (suite *MTOServiceItemServiceSuite) TestUpdateMTOServiceItemData() { }, { Model: models.ReService{ - Code: models.ReServiceCodeDDDSIT, + Code: models.ReServiceCodeDOPSIT, }, }, }, nil) @@ -642,7 +642,7 @@ func (suite *MTOServiceItemServiceSuite) TestUpdateMTOServiceItemData() { suite.NoError(err) }) - suite.Run("checkSITDestinationFinalAddress - invalid input failure: SITDestinationFinalAddress", func() { + suite.Run("checkSITDestinationFinalAddress - invalid input failure: updating SITDestinationFinalAddress for DDASIT", func() { oldServiceItemPrime := factory.BuildMTOServiceItem(suite.DB(), []factory.Customization{ { Model: factory.BuildAvailableToPrimeMove(suite.DB(), nil, nil), @@ -672,12 +672,12 @@ func (suite *MTOServiceItemServiceSuite) TestUpdateMTOServiceItemData() { } err := serviceItemData.checkSITDestinationFinalAddress(suite.AppContextForTest()) - suite.Error(err) - conflictError := apperror.ConflictError{} - suite.IsType(conflictError, err) + suite.NoError(err) + suite.True(serviceItemData.verrs.HasAny()) + suite.Contains(serviceItemData.verrs.Keys(), "SITDestinationFinalAddress") }) - suite.Run("checkSITDestinationFinalAddress - invalid input failure: SITDestinationFinalAddress", func() { + suite.Run("checkSITDestinationFinalAddress - invalid input failure: updating SITDestinationFinalAddress for DDDSIT ", func() { oldServiceItemPrime := factory.BuildMTOServiceItem(suite.DB(), []factory.Customization{ { Model: factory.BuildAvailableToPrimeMove(suite.DB(), nil, nil), @@ -712,6 +712,76 @@ func (suite *MTOServiceItemServiceSuite) TestUpdateMTOServiceItemData() { suite.Contains(serviceItemData.verrs.Keys(), "SITDestinationFinalAddress") }) + suite.Run("checkSITDestinationFinalAddress - invalid input failure: updating SITDestinationFinalAddress for DDFSIT ", func() { + oldServiceItemPrime := factory.BuildMTOServiceItem(suite.DB(), []factory.Customization{ + { + Model: factory.BuildAvailableToPrimeMove(suite.DB(), nil, nil), + LinkOnly: true, + }, + { + Model: models.Address{}, + Type: &factory.Addresses.SITDestinationFinalAddress, + }, + { + Model: models.ReService{ + Code: models.ReServiceCodeDDFSIT, + }, + }, + }, nil) + newServiceItemPrime := oldServiceItemPrime + + // Try to update SITDestinationFinalAddress + newAddress := factory.BuildAddress(suite.DB(), nil, []factory.Trait{factory.GetTraitAddress3}) + newServiceItemPrime.SITDestinationFinalAddress = &newAddress + + serviceItemData := updateMTOServiceItemData{ + updatedServiceItem: newServiceItemPrime, + oldServiceItem: oldServiceItemPrime, + verrs: validate.NewErrors(), + availabilityChecker: checker, + } + err := serviceItemData.checkSITDestinationFinalAddress(suite.AppContextForTest()) + + suite.NoError(err) + suite.True(serviceItemData.verrs.HasAny()) + suite.Contains(serviceItemData.verrs.Keys(), "SITDestinationFinalAddress") + }) + + suite.Run("checkSITDestinationFinalAddress - invalid input failure: updating SITDestinationFinalAddress for DDSFSC ", func() { + oldServiceItemPrime := factory.BuildMTOServiceItem(suite.DB(), []factory.Customization{ + { + Model: factory.BuildAvailableToPrimeMove(suite.DB(), nil, nil), + LinkOnly: true, + }, + { + Model: models.Address{}, + Type: &factory.Addresses.SITDestinationFinalAddress, + }, + { + Model: models.ReService{ + Code: models.ReServiceCodeDDSFSC, + }, + }, + }, nil) + newServiceItemPrime := oldServiceItemPrime + + // Try to update SITDestinationFinalAddress + newAddress := factory.BuildAddress(suite.DB(), nil, []factory.Trait{factory.GetTraitAddress3}) + newServiceItemPrime.SITDestinationFinalAddress = &newAddress + + serviceItemData := updateMTOServiceItemData{ + updatedServiceItem: newServiceItemPrime, + oldServiceItem: oldServiceItemPrime, + verrs: validate.NewErrors(), + availabilityChecker: checker, + } + err := serviceItemData.checkSITDestinationFinalAddress(suite.AppContextForTest()) + + suite.NoError(err) + suite.True(serviceItemData.verrs.HasAny()) + suite.Contains(serviceItemData.verrs.Keys(), "SITDestinationFinalAddress") + }) + suite.Run("checkSITDestinationOriginalAddress - invalid input failure: adding SITDestinationOriginalAddress", func() { oldServiceItemPrime := factory.BuildMTOServiceItem(suite.DB(), []factory.Customization{ { diff --git a/swagger-def/prime.yaml b/swagger-def/prime.yaml index 83ac6377152..ba6ebc557ff 100644 --- a/swagger-def/prime.yaml +++ b/swagger-def/prime.yaml @@ -995,10 +995,11 @@ paths: This endpoint supports different body definitions. In the modelType field below, select the modelType corresponding to the service item you wish to update and the documentation will update with the new definition. - * Addresses: You can add a new SIT Destination final address using this endpoint (and must use this endpoint to do so), but you cannot update an existing one. - Please use [createSITAddressUpdateRequest](#operation/createSITAddressUpdateRequest) instead. + * Addresses: To update a destination service item's SIT destination final address, update the shipment destination address. + For approved shipments, please use [updateShipmentDestinationAddress](#mtoShipment/updateShipmentDestinationAddress). + For shipments not yet approved, please use [updateMTOShipmentAddress](#mtoShipment/updateMTOShipmentAddress). - To create a service item, please use [createMTOServiceItem](#operation/createMTOServiceItem)) endpoint. + To create a service item, please use [createMTOServiceItem](#mtoServiceItem/createMTOServiceItem)) endpoint. operationId: updateMTOServiceItem tags: - mtoServiceItem diff --git a/swagger/prime.yaml b/swagger/prime.yaml index 62a7d3a19b7..e8bc73079f8 100644 --- a/swagger/prime.yaml +++ b/swagger/prime.yaml @@ -1188,17 +1188,18 @@ paths: field below, select the modelType corresponding to the service item you wish to update and the documentation will update with the new definition. - * Addresses: You can add a new SIT Destination final address using this - endpoint (and must use this endpoint to do so), but you cannot update an - existing one. + * Addresses: To update a destination service item's SIT destination + final address, update the shipment destination address. - Please use - [createSITAddressUpdateRequest](#operation/createSITAddressUpdateRequest) - instead. + For approved shipments, please use + [updateShipmentDestinationAddress](#mtoShipment/updateShipmentDestinationAddress). + + For shipments not yet approved, please use + [updateMTOShipmentAddress](#mtoShipment/updateMTOShipmentAddress). To create a service item, please use - [createMTOServiceItem](#operation/createMTOServiceItem)) endpoint. + [createMTOServiceItem](#mtoServiceItem/createMTOServiceItem)) endpoint. operationId: updateMTOServiceItem tags: - mtoServiceItem