From 376061061e8466055f911a5acbcc47f9640eb6bc Mon Sep 17 00:00:00 2001 From: Maria Traskowsky Date: Thu, 1 Feb 2024 22:44:33 +0000 Subject: [PATCH 1/2] check dest service codes in validators, update tests, udpate docs --- pkg/gen/primeapi/embedded_spec.go | 4 +- .../update_m_t_o_service_item.go | 3 +- .../mto_service_item_client.go | 3 +- .../mto_service_item_validators.go | 9 +- .../mto_service_item_validators_test.go | 84 +++++++++++++++++-- swagger-def/prime.yaml | 3 +- swagger/prime.yaml | 9 +- 7 files changed, 89 insertions(+), 26 deletions(-) diff --git a/pkg/gen/primeapi/embedded_spec.go b/pkg/gen/primeapi/embedded_spec.go index 6abaf019d3f..d23775cb803 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.\n\nTo create a service item, please use [createMTOServiceItem](#operation/createMTOServiceItem)) endpoint.\n", "consumes": [ "application/json" ], @@ -5211,7 +5211,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.\n\nTo create a service item, please use [createMTOServiceItem](#operation/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..9756fb5c34a 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,8 +40,7 @@ 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. To create a service item, please use [createMTOServiceItem](#operation/createMTOServiceItem)) endpoint. */ 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..698bdfae634 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,8 +220,7 @@ 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. To create a service item, please use [createMTOServiceItem](#operation/createMTOServiceItem)) endpoint. */ 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 0e9e2e709aa..c904e01284c 100644 --- a/swagger-def/prime.yaml +++ b/swagger-def/prime.yaml @@ -1036,8 +1036,7 @@ 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. To create a service item, please use [createMTOServiceItem](#operation/createMTOServiceItem)) endpoint. operationId: updateMTOServiceItem diff --git a/swagger/prime.yaml b/swagger/prime.yaml index 3e671168551..b29ea10978f 100644 --- a/swagger/prime.yaml +++ b/swagger/prime.yaml @@ -1235,13 +1235,8 @@ 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. - - Please use - [createSITAddressUpdateRequest](#operation/createSITAddressUpdateRequest) - instead. + * Addresses: To update a destination service item's SIT destination + final address, update the shipment destination address. To create a service item, please use From e209ff33a73caad2ac3c09f75c7470308cda189c Mon Sep 17 00:00:00 2001 From: Maria Traskowsky Date: Fri, 2 Feb 2024 15:44:35 +0000 Subject: [PATCH 2/2] expanded description, fixed links --- pkg/gen/primeapi/embedded_spec.go | 4 ++-- .../mto_service_item/update_m_t_o_service_item.go | 4 +++- .../mto_service_item/mto_service_item_client.go | 4 +++- swagger-def/prime.yaml | 4 +++- swagger/prime.yaml | 8 +++++++- 5 files changed, 18 insertions(+), 6 deletions(-) diff --git a/pkg/gen/primeapi/embedded_spec.go b/pkg/gen/primeapi/embedded_spec.go index d23775cb803..880667d7f33 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: To update a destination service item's SIT destination final address, update the shipment destination address.\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" ], @@ -5211,7 +5211,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: To update a destination service item's SIT destination final address, update the shipment destination address.\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 9756fb5c34a..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 @@ -41,8 +41,10 @@ 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: 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 698bdfae634..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 @@ -221,8 +221,10 @@ 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: 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/swagger-def/prime.yaml b/swagger-def/prime.yaml index c904e01284c..037da9c35c6 100644 --- a/swagger-def/prime.yaml +++ b/swagger-def/prime.yaml @@ -1037,8 +1037,10 @@ paths: to the service item you wish to update and the documentation will update with the new definition. * 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 b29ea10978f..b19c883c1a1 100644 --- a/swagger/prime.yaml +++ b/swagger/prime.yaml @@ -1238,9 +1238,15 @@ paths: * 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. + [createMTOServiceItem](#mtoServiceItem/createMTOServiceItem)) endpoint. operationId: updateMTOServiceItem tags: - mtoServiceItem