From cb704e593a4f6c16a038f242f3eb8842b59bc369 Mon Sep 17 00:00:00 2001 From: Tae Jung Date: Mon, 19 Aug 2024 20:33:35 +0000 Subject: [PATCH 1/3] ghc crud api changes for boat shipment --- pkg/gen/ghcapi/embedded_spec.go | 228 +++++++++++++++++ pkg/gen/ghcmessages/create_boat_shipment.go | 229 ++++++++++++++++++ pkg/gen/ghcmessages/create_m_t_o_shipment.go | 51 ++++ pkg/gen/ghcmessages/update_boat_shipment.go | 129 ++++++++++ pkg/gen/ghcmessages/update_shipment.go | 51 ++++ .../internal/payloads/model_to_payload.go | 27 +++ .../internal/payloads/payload_to_model.go | 107 ++++++++ pkg/handlers/ghcapi/mto_shipment.go | 6 +- pkg/services/boat_shipment/rules.go | 5 + pkg/services/boat_shipment/rules_test.go | 16 ++ pkg/services/boat_shipment/validation.go | 5 +- swagger-def/ghc.yaml | 87 +++++++ swagger/ghc.yaml | 87 +++++++ 13 files changed, 1026 insertions(+), 2 deletions(-) create mode 100644 pkg/gen/ghcmessages/create_boat_shipment.go create mode 100644 pkg/gen/ghcmessages/update_boat_shipment.go diff --git a/pkg/gen/ghcapi/embedded_spec.go b/pkg/gen/ghcapi/embedded_spec.go index 39985c3e91a..69594b19093 100644 --- a/pkg/gen/ghcapi/embedded_spec.go +++ b/pkg/gen/ghcapi/embedded_spec.go @@ -6334,6 +6334,61 @@ func init() { } } }, + "CreateBoatShipment": { + "description": "Boat shipment information for the move.", + "required": [ + "type", + "year", + "make", + "model", + "lengthInInches", + "widthInInches", + "heightInInches", + "hasTrailer" + ], + "properties": { + "hasTrailer": { + "description": "Does the boat have a trailer", + "type": "boolean" + }, + "heightInInches": { + "description": "Height of the Boat in inches", + "type": "integer" + }, + "isRoadworthy": { + "description": "Is the trailer roadworthy", + "type": "boolean", + "x-nullable": true + }, + "lengthInInches": { + "description": "Length of the Boat in inches", + "type": "integer" + }, + "make": { + "description": "Make of the Boat", + "type": "string" + }, + "model": { + "description": "Model of the Boat", + "type": "string" + }, + "type": { + "type": "string", + "enum": [ + "HAUL_AWAY", + "TOW_AWAY" + ] + }, + "widthInInches": { + "description": "Width of the Boat in inches", + "type": "integer" + }, + "year": { + "description": "Year of the Boat", + "type": "integer" + } + } + }, "CreateCustomerPayload": { "type": "object", "properties": { @@ -6459,6 +6514,9 @@ func init() { "agents": { "$ref": "#/definitions/MTOAgents" }, + "boatShipment": { + "$ref": "#/definitions/CreateBoatShipment" + }, "counselorRemarks": { "description": "The counselor can use the counselor remarks field to inform the movers about any\nspecial circumstances for this shipment. Typical examples:\n * bulky or fragile items,\n * weapons,\n * access info for their address.\nCounselors enters this information when creating or editing an MTO Shipment. Optional field.\n", "type": "string", @@ -12410,6 +12468,59 @@ func init() { } } }, + "UpdateBoatShipment": { + "type": "object", + "properties": { + "hasTrailer": { + "description": "Does the boat have a trailer", + "type": "boolean", + "x-nullable": true + }, + "heightInInches": { + "description": "Height of the Boat in inches", + "type": "integer", + "x-nullable": true + }, + "isRoadworthy": { + "description": "Is the trailer roadworthy", + "type": "boolean", + "x-nullable": true + }, + "lengthInInches": { + "description": "Length of the Boat in inches", + "type": "integer", + "x-nullable": true + }, + "make": { + "description": "Make of the Boat", + "type": "string", + "x-nullable": true + }, + "model": { + "description": "Model of the Boat", + "type": "string", + "x-nullable": true + }, + "type": { + "type": "string", + "enum": [ + "HAUL_AWAY", + "TOW_AWAY" + ], + "x-nullable": true + }, + "widthInInches": { + "description": "Width of the Boat in inches", + "type": "integer", + "x-nullable": true + }, + "year": { + "description": "Year of the Boat", + "type": "integer", + "x-nullable": true + } + } + }, "UpdateCustomerPayload": { "type": "object", "properties": { @@ -12921,6 +13032,9 @@ func init() { "x-nullable": true, "example": "more weight than expected" }, + "boatShipment": { + "$ref": "#/definitions/UpdateBoatShipment" + }, "counselorRemarks": { "type": "string", "x-nullable": true, @@ -21250,6 +21364,61 @@ func init() { } } }, + "CreateBoatShipment": { + "description": "Boat shipment information for the move.", + "required": [ + "type", + "year", + "make", + "model", + "lengthInInches", + "widthInInches", + "heightInInches", + "hasTrailer" + ], + "properties": { + "hasTrailer": { + "description": "Does the boat have a trailer", + "type": "boolean" + }, + "heightInInches": { + "description": "Height of the Boat in inches", + "type": "integer" + }, + "isRoadworthy": { + "description": "Is the trailer roadworthy", + "type": "boolean", + "x-nullable": true + }, + "lengthInInches": { + "description": "Length of the Boat in inches", + "type": "integer" + }, + "make": { + "description": "Make of the Boat", + "type": "string" + }, + "model": { + "description": "Model of the Boat", + "type": "string" + }, + "type": { + "type": "string", + "enum": [ + "HAUL_AWAY", + "TOW_AWAY" + ] + }, + "widthInInches": { + "description": "Width of the Boat in inches", + "type": "integer" + }, + "year": { + "description": "Year of the Boat", + "type": "integer" + } + } + }, "CreateCustomerPayload": { "type": "object", "properties": { @@ -21375,6 +21544,9 @@ func init() { "agents": { "$ref": "#/definitions/MTOAgents" }, + "boatShipment": { + "$ref": "#/definitions/CreateBoatShipment" + }, "counselorRemarks": { "description": "The counselor can use the counselor remarks field to inform the movers about any\nspecial circumstances for this shipment. Typical examples:\n * bulky or fragile items,\n * weapons,\n * access info for their address.\nCounselors enters this information when creating or editing an MTO Shipment. Optional field.\n", "type": "string", @@ -27457,6 +27629,59 @@ func init() { } } }, + "UpdateBoatShipment": { + "type": "object", + "properties": { + "hasTrailer": { + "description": "Does the boat have a trailer", + "type": "boolean", + "x-nullable": true + }, + "heightInInches": { + "description": "Height of the Boat in inches", + "type": "integer", + "x-nullable": true + }, + "isRoadworthy": { + "description": "Is the trailer roadworthy", + "type": "boolean", + "x-nullable": true + }, + "lengthInInches": { + "description": "Length of the Boat in inches", + "type": "integer", + "x-nullable": true + }, + "make": { + "description": "Make of the Boat", + "type": "string", + "x-nullable": true + }, + "model": { + "description": "Model of the Boat", + "type": "string", + "x-nullable": true + }, + "type": { + "type": "string", + "enum": [ + "HAUL_AWAY", + "TOW_AWAY" + ], + "x-nullable": true + }, + "widthInInches": { + "description": "Width of the Boat in inches", + "type": "integer", + "x-nullable": true + }, + "year": { + "description": "Year of the Boat", + "type": "integer", + "x-nullable": true + } + } + }, "UpdateCustomerPayload": { "type": "object", "properties": { @@ -27969,6 +28194,9 @@ func init() { "x-nullable": true, "example": "more weight than expected" }, + "boatShipment": { + "$ref": "#/definitions/UpdateBoatShipment" + }, "counselorRemarks": { "type": "string", "x-nullable": true, diff --git a/pkg/gen/ghcmessages/create_boat_shipment.go b/pkg/gen/ghcmessages/create_boat_shipment.go new file mode 100644 index 00000000000..20a5708a369 --- /dev/null +++ b/pkg/gen/ghcmessages/create_boat_shipment.go @@ -0,0 +1,229 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package ghcmessages + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + "encoding/json" + + "github.com/go-openapi/errors" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" + "github.com/go-openapi/validate" +) + +// CreateBoatShipment Boat shipment information for the move. +// +// swagger:model CreateBoatShipment +type CreateBoatShipment struct { + + // Does the boat have a trailer + // Required: true + HasTrailer *bool `json:"hasTrailer"` + + // Height of the Boat in inches + // Required: true + HeightInInches *int64 `json:"heightInInches"` + + // Is the trailer roadworthy + IsRoadworthy *bool `json:"isRoadworthy,omitempty"` + + // Length of the Boat in inches + // Required: true + LengthInInches *int64 `json:"lengthInInches"` + + // Make of the Boat + // Required: true + Make *string `json:"make"` + + // Model of the Boat + // Required: true + Model *string `json:"model"` + + // type + // Required: true + // Enum: [HAUL_AWAY TOW_AWAY] + Type *string `json:"type"` + + // Width of the Boat in inches + // Required: true + WidthInInches *int64 `json:"widthInInches"` + + // Year of the Boat + // Required: true + Year *int64 `json:"year"` +} + +// Validate validates this create boat shipment +func (m *CreateBoatShipment) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateHasTrailer(formats); err != nil { + res = append(res, err) + } + + if err := m.validateHeightInInches(formats); err != nil { + res = append(res, err) + } + + if err := m.validateLengthInInches(formats); err != nil { + res = append(res, err) + } + + if err := m.validateMake(formats); err != nil { + res = append(res, err) + } + + if err := m.validateModel(formats); err != nil { + res = append(res, err) + } + + if err := m.validateType(formats); err != nil { + res = append(res, err) + } + + if err := m.validateWidthInInches(formats); err != nil { + res = append(res, err) + } + + if err := m.validateYear(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *CreateBoatShipment) validateHasTrailer(formats strfmt.Registry) error { + + if err := validate.Required("hasTrailer", "body", m.HasTrailer); err != nil { + return err + } + + return nil +} + +func (m *CreateBoatShipment) validateHeightInInches(formats strfmt.Registry) error { + + if err := validate.Required("heightInInches", "body", m.HeightInInches); err != nil { + return err + } + + return nil +} + +func (m *CreateBoatShipment) validateLengthInInches(formats strfmt.Registry) error { + + if err := validate.Required("lengthInInches", "body", m.LengthInInches); err != nil { + return err + } + + return nil +} + +func (m *CreateBoatShipment) validateMake(formats strfmt.Registry) error { + + if err := validate.Required("make", "body", m.Make); err != nil { + return err + } + + return nil +} + +func (m *CreateBoatShipment) validateModel(formats strfmt.Registry) error { + + if err := validate.Required("model", "body", m.Model); err != nil { + return err + } + + return nil +} + +var createBoatShipmentTypeTypePropEnum []interface{} + +func init() { + var res []string + if err := json.Unmarshal([]byte(`["HAUL_AWAY","TOW_AWAY"]`), &res); err != nil { + panic(err) + } + for _, v := range res { + createBoatShipmentTypeTypePropEnum = append(createBoatShipmentTypeTypePropEnum, v) + } +} + +const ( + + // CreateBoatShipmentTypeHAULAWAY captures enum value "HAUL_AWAY" + CreateBoatShipmentTypeHAULAWAY string = "HAUL_AWAY" + + // CreateBoatShipmentTypeTOWAWAY captures enum value "TOW_AWAY" + CreateBoatShipmentTypeTOWAWAY string = "TOW_AWAY" +) + +// prop value enum +func (m *CreateBoatShipment) validateTypeEnum(path, location string, value string) error { + if err := validate.EnumCase(path, location, value, createBoatShipmentTypeTypePropEnum, true); err != nil { + return err + } + return nil +} + +func (m *CreateBoatShipment) validateType(formats strfmt.Registry) error { + + if err := validate.Required("type", "body", m.Type); err != nil { + return err + } + + // value enum + if err := m.validateTypeEnum("type", "body", *m.Type); err != nil { + return err + } + + return nil +} + +func (m *CreateBoatShipment) validateWidthInInches(formats strfmt.Registry) error { + + if err := validate.Required("widthInInches", "body", m.WidthInInches); err != nil { + return err + } + + return nil +} + +func (m *CreateBoatShipment) validateYear(formats strfmt.Registry) error { + + if err := validate.Required("year", "body", m.Year); err != nil { + return err + } + + return nil +} + +// ContextValidate validates this create boat shipment based on context it is used +func (m *CreateBoatShipment) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *CreateBoatShipment) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *CreateBoatShipment) UnmarshalBinary(b []byte) error { + var res CreateBoatShipment + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/pkg/gen/ghcmessages/create_m_t_o_shipment.go b/pkg/gen/ghcmessages/create_m_t_o_shipment.go index 324adce0b25..da26b513baf 100644 --- a/pkg/gen/ghcmessages/create_m_t_o_shipment.go +++ b/pkg/gen/ghcmessages/create_m_t_o_shipment.go @@ -22,6 +22,9 @@ type CreateMTOShipment struct { // agents Agents MTOAgents `json:"agents,omitempty"` + // boat shipment + BoatShipment *CreateBoatShipment `json:"boatShipment,omitempty"` + // The counselor can use the counselor remarks field to inform the movers about any // special circumstances for this shipment. Typical examples: // * bulky or fragile items, @@ -145,6 +148,10 @@ func (m *CreateMTOShipment) Validate(formats strfmt.Registry) error { res = append(res, err) } + if err := m.validateBoatShipment(formats); err != nil { + res = append(res, err) + } + if err := m.validateDestinationAddress(formats); err != nil { res = append(res, err) } @@ -236,6 +243,25 @@ func (m *CreateMTOShipment) validateAgents(formats strfmt.Registry) error { return nil } +func (m *CreateMTOShipment) validateBoatShipment(formats strfmt.Registry) error { + if swag.IsZero(m.BoatShipment) { // not required + return nil + } + + if m.BoatShipment != nil { + if err := m.BoatShipment.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("boatShipment") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("boatShipment") + } + return err + } + } + + return nil +} + func (m *CreateMTOShipment) validateDestinationAddress(formats strfmt.Registry) error { if swag.IsZero(m.DestinationAddress) { // not required return nil @@ -484,6 +510,10 @@ func (m *CreateMTOShipment) ContextValidate(ctx context.Context, formats strfmt. res = append(res, err) } + if err := m.contextValidateBoatShipment(ctx, formats); err != nil { + res = append(res, err) + } + if err := m.contextValidateDestinationAddress(ctx, formats); err != nil { res = append(res, err) } @@ -560,6 +590,27 @@ func (m *CreateMTOShipment) contextValidateAgents(ctx context.Context, formats s return nil } +func (m *CreateMTOShipment) contextValidateBoatShipment(ctx context.Context, formats strfmt.Registry) error { + + if m.BoatShipment != nil { + + if swag.IsZero(m.BoatShipment) { // not required + return nil + } + + if err := m.BoatShipment.ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("boatShipment") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("boatShipment") + } + return err + } + } + + return nil +} + func (m *CreateMTOShipment) contextValidateDestinationAddress(ctx context.Context, formats strfmt.Registry) error { return nil diff --git a/pkg/gen/ghcmessages/update_boat_shipment.go b/pkg/gen/ghcmessages/update_boat_shipment.go new file mode 100644 index 00000000000..bcc443a6e6c --- /dev/null +++ b/pkg/gen/ghcmessages/update_boat_shipment.go @@ -0,0 +1,129 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package ghcmessages + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + "encoding/json" + + "github.com/go-openapi/errors" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" + "github.com/go-openapi/validate" +) + +// UpdateBoatShipment update boat shipment +// +// swagger:model UpdateBoatShipment +type UpdateBoatShipment struct { + + // Does the boat have a trailer + HasTrailer *bool `json:"hasTrailer,omitempty"` + + // Height of the Boat in inches + HeightInInches *int64 `json:"heightInInches,omitempty"` + + // Is the trailer roadworthy + IsRoadworthy *bool `json:"isRoadworthy,omitempty"` + + // Length of the Boat in inches + LengthInInches *int64 `json:"lengthInInches,omitempty"` + + // Make of the Boat + Make *string `json:"make,omitempty"` + + // Model of the Boat + Model *string `json:"model,omitempty"` + + // type + // Enum: [HAUL_AWAY TOW_AWAY] + Type *string `json:"type,omitempty"` + + // Width of the Boat in inches + WidthInInches *int64 `json:"widthInInches,omitempty"` + + // Year of the Boat + Year *int64 `json:"year,omitempty"` +} + +// Validate validates this update boat shipment +func (m *UpdateBoatShipment) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateType(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +var updateBoatShipmentTypeTypePropEnum []interface{} + +func init() { + var res []string + if err := json.Unmarshal([]byte(`["HAUL_AWAY","TOW_AWAY"]`), &res); err != nil { + panic(err) + } + for _, v := range res { + updateBoatShipmentTypeTypePropEnum = append(updateBoatShipmentTypeTypePropEnum, v) + } +} + +const ( + + // UpdateBoatShipmentTypeHAULAWAY captures enum value "HAUL_AWAY" + UpdateBoatShipmentTypeHAULAWAY string = "HAUL_AWAY" + + // UpdateBoatShipmentTypeTOWAWAY captures enum value "TOW_AWAY" + UpdateBoatShipmentTypeTOWAWAY string = "TOW_AWAY" +) + +// prop value enum +func (m *UpdateBoatShipment) validateTypeEnum(path, location string, value string) error { + if err := validate.EnumCase(path, location, value, updateBoatShipmentTypeTypePropEnum, true); err != nil { + return err + } + return nil +} + +func (m *UpdateBoatShipment) validateType(formats strfmt.Registry) error { + if swag.IsZero(m.Type) { // not required + return nil + } + + // value enum + if err := m.validateTypeEnum("type", "body", *m.Type); err != nil { + return err + } + + return nil +} + +// ContextValidate validates this update boat shipment based on context it is used +func (m *UpdateBoatShipment) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *UpdateBoatShipment) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *UpdateBoatShipment) UnmarshalBinary(b []byte) error { + var res UpdateBoatShipment + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/pkg/gen/ghcmessages/update_shipment.go b/pkg/gen/ghcmessages/update_shipment.go index 7d4cba77794..4b495c46229 100644 --- a/pkg/gen/ghcmessages/update_shipment.go +++ b/pkg/gen/ghcmessages/update_shipment.go @@ -37,6 +37,9 @@ type UpdateShipment struct { // Example: more weight than expected BillableWeightJustification *string `json:"billableWeightJustification,omitempty"` + // boat shipment + BoatShipment *UpdateBoatShipment `json:"boatShipment,omitempty"` + // counselor remarks // Example: counselor approved CounselorRemarks *string `json:"counselorRemarks,omitempty"` @@ -133,6 +136,10 @@ func (m *UpdateShipment) Validate(formats strfmt.Registry) error { res = append(res, err) } + if err := m.validateBoatShipment(formats); err != nil { + res = append(res, err) + } + if err := m.validateDestinationAddress(formats); err != nil { res = append(res, err) } @@ -212,6 +219,25 @@ func (m *UpdateShipment) validateAgents(formats strfmt.Registry) error { return nil } +func (m *UpdateShipment) validateBoatShipment(formats strfmt.Registry) error { + if swag.IsZero(m.BoatShipment) { // not required + return nil + } + + if m.BoatShipment != nil { + if err := m.BoatShipment.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("boatShipment") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("boatShipment") + } + return err + } + } + + return nil +} + func (m *UpdateShipment) validateDestinationAddress(formats strfmt.Registry) error { if swag.IsZero(m.DestinationAddress) { // not required return nil @@ -400,6 +426,10 @@ func (m *UpdateShipment) ContextValidate(ctx context.Context, formats strfmt.Reg res = append(res, err) } + if err := m.contextValidateBoatShipment(ctx, formats); err != nil { + res = append(res, err) + } + if err := m.contextValidateDestinationAddress(ctx, formats); err != nil { res = append(res, err) } @@ -468,6 +498,27 @@ func (m *UpdateShipment) contextValidateAgents(ctx context.Context, formats strf return nil } +func (m *UpdateShipment) contextValidateBoatShipment(ctx context.Context, formats strfmt.Registry) error { + + if m.BoatShipment != nil { + + if swag.IsZero(m.BoatShipment) { // not required + return nil + } + + if err := m.BoatShipment.ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("boatShipment") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("boatShipment") + } + return err + } + } + + return nil +} + func (m *UpdateShipment) contextValidateDestinationAddress(ctx context.Context, formats strfmt.Registry) error { return nil diff --git a/pkg/handlers/ghcapi/internal/payloads/model_to_payload.go b/pkg/handlers/ghcapi/internal/payloads/model_to_payload.go index 6c329a38ae0..e82d37cc3ab 100644 --- a/pkg/handlers/ghcapi/internal/payloads/model_to_payload.go +++ b/pkg/handlers/ghcapi/internal/payloads/model_to_payload.go @@ -917,6 +917,32 @@ func PPMShipment(_ storage.FileStorer, ppmShipment *models.PPMShipment) *ghcmess return payloadPPMShipment } +// BoatShipment payload +func BoatShipment(storer storage.FileStorer, boatShipment *models.BoatShipment) *ghcmessages.BoatShipment { + if boatShipment == nil || boatShipment.ID.IsNil() { + return nil + } + + payloadBoatShipment := &ghcmessages.BoatShipment{ + ID: *handlers.FmtUUID(boatShipment.ID), + ShipmentID: *handlers.FmtUUID(boatShipment.ShipmentID), + CreatedAt: strfmt.DateTime(boatShipment.CreatedAt), + UpdatedAt: strfmt.DateTime(boatShipment.UpdatedAt), + Type: models.StringPointer(string(boatShipment.Type)), + Year: handlers.FmtIntPtrToInt64(boatShipment.Year), + Make: boatShipment.Make, + Model: boatShipment.Model, + LengthInInches: handlers.FmtIntPtrToInt64(boatShipment.LengthInInches), + WidthInInches: handlers.FmtIntPtrToInt64(boatShipment.WidthInInches), + HeightInInches: handlers.FmtIntPtrToInt64(boatShipment.HeightInInches), + HasTrailer: boatShipment.HasTrailer, + IsRoadworthy: boatShipment.IsRoadworthy, + ETag: etag.GenerateEtag(boatShipment.UpdatedAt), + } + + return payloadBoatShipment +} + // ProGearWeightTickets sets up a ProGearWeightTicket slice for the api using model data. func ProGearWeightTickets(storer storage.FileStorer, proGearWeightTickets models.ProgearWeightTickets) []*ghcmessages.ProGearWeightTicket { payload := make([]*ghcmessages.ProGearWeightTicket, len(proGearWeightTickets)) @@ -1338,6 +1364,7 @@ func MTOShipment(storer storage.FileStorer, mtoShipment *models.MTOShipment, sit ServiceOrderNumber: mtoShipment.ServiceOrderNumber, StorageFacility: StorageFacility(mtoShipment.StorageFacility), PpmShipment: PPMShipment(storer, mtoShipment.PPMShipment), + BoatShipment: BoatShipment(storer, mtoShipment.BoatShipment), DeliveryAddressUpdate: ShipmentAddressUpdate(mtoShipment.DeliveryAddressUpdate), ShipmentLocator: handlers.FmtStringPtr(mtoShipment.ShipmentLocator), } diff --git a/pkg/handlers/ghcapi/internal/payloads/payload_to_model.go b/pkg/handlers/ghcapi/internal/payloads/payload_to_model.go index 2e50c7724f4..5ae0fd4f514 100644 --- a/pkg/handlers/ghcapi/internal/payloads/payload_to_model.go +++ b/pkg/handlers/ghcapi/internal/payloads/payload_to_model.go @@ -259,6 +259,9 @@ func MTOShipmentModelFromCreate(mtoShipment *ghcmessages.CreateMTOShipment) *mod if mtoShipment.PpmShipment != nil { model.PPMShipment = PPMShipmentModelFromCreate(mtoShipment.PpmShipment) model.PPMShipment.Shipment = *model + } else if mtoShipment.BoatShipment != nil { + model.BoatShipment = BoatShipmentModelFromCreate(mtoShipment.BoatShipment) + model.BoatShipment.Shipment = *model } return model @@ -345,6 +348,51 @@ func PPMShipmentModelFromCreate(ppmShipment *ghcmessages.CreatePPMShipment) *mod return model } +// BoatShipmentModelFromCreate model +func BoatShipmentModelFromCreate(boatShipment *ghcmessages.CreateBoatShipment) *models.BoatShipment { + if boatShipment == nil { + return nil + } + var year *int + if boatShipment.Year != nil { + val := int(*boatShipment.Year) + year = &val + } + var lengthInInches *int + if boatShipment.LengthInInches != nil { + val := int(*boatShipment.LengthInInches) + lengthInInches = &val + } + var widthInInches *int + if boatShipment.WidthInInches != nil { + val := int(*boatShipment.WidthInInches) + widthInInches = &val + } + var heightInInches *int + if boatShipment.HeightInInches != nil { + val := int(*boatShipment.HeightInInches) + heightInInches = &val + } + + model := &models.BoatShipment{ + Type: models.BoatShipmentType(*boatShipment.Type), + Year: year, + Make: boatShipment.Make, + Model: boatShipment.Model, + LengthInInches: lengthInInches, + WidthInInches: widthInInches, + HeightInInches: heightInInches, + HasTrailer: boatShipment.HasTrailer, + IsRoadworthy: boatShipment.IsRoadworthy, + } + + if model.HasTrailer == models.BoolPointer(false) { + model.IsRoadworthy = nil + } + + return model +} + func CustomerSupportRemarkModelFromCreate(remark *ghcmessages.CreateCustomerSupportRemark) *models.CustomerSupportRemark { if remark == nil { return nil @@ -465,6 +513,17 @@ func MTOShipmentModelFromUpdate(mtoShipment *ghcmessages.UpdateShipment) *models model.PPMShipment.Shipment = *model } + // making sure both shipmentType and boatShipment.Type match + if mtoShipment.BoatShipment != nil && mtoShipment.BoatShipment.Type != nil { + if *mtoShipment.BoatShipment.Type == string(models.BoatShipmentTypeHaulAway) { + model.ShipmentType = models.MTOShipmentTypeBoatHaulAway + } else { + model.ShipmentType = models.MTOShipmentTypeBoatTowAway + } + model.BoatShipment = BoatShipmentModelFromUpdate(mtoShipment.BoatShipment) + model.BoatShipment.Shipment = *model + } + return model } @@ -567,6 +626,54 @@ func PPMShipmentModelFromUpdate(ppmShipment *ghcmessages.UpdatePPMShipment) *mod return model } +// BoatShipmentModelFromUpdate model +func BoatShipmentModelFromUpdate(boatShipment *ghcmessages.UpdateBoatShipment) *models.BoatShipment { + if boatShipment == nil { + return nil + } + var year *int + if boatShipment.Year != nil { + val := int(*boatShipment.Year) + year = &val + } + var lengthInInches *int + if boatShipment.LengthInInches != nil { + val := int(*boatShipment.LengthInInches) + lengthInInches = &val + } + var widthInInches *int + if boatShipment.WidthInInches != nil { + val := int(*boatShipment.WidthInInches) + widthInInches = &val + } + var heightInInches *int + if boatShipment.HeightInInches != nil { + val := int(*boatShipment.HeightInInches) + heightInInches = &val + } + + boatModel := &models.BoatShipment{ + Year: year, + Make: boatShipment.Make, + Model: boatShipment.Model, + LengthInInches: lengthInInches, + WidthInInches: widthInInches, + HeightInInches: heightInInches, + HasTrailer: boatShipment.HasTrailer, + IsRoadworthy: boatShipment.IsRoadworthy, + } + + if boatShipment.Type != nil { + boatModel.Type = models.BoatShipmentType(*boatShipment.Type) + } + + if boatShipment.HasTrailer == models.BoolPointer(false) { + boatModel.IsRoadworthy = nil + } + + return boatModel +} + // ProgearWeightTicketModelFromUpdate model func ProgearWeightTicketModelFromUpdate(progearWeightTicket *ghcmessages.UpdateProGearWeightTicket) *models.ProgearWeightTicket { if progearWeightTicket == nil { diff --git a/pkg/handlers/ghcapi/mto_shipment.go b/pkg/handlers/ghcapi/mto_shipment.go index ce6329def35..2a07ab928dc 100644 --- a/pkg/handlers/ghcapi/mto_shipment.go +++ b/pkg/handlers/ghcapi/mto_shipment.go @@ -128,6 +128,7 @@ func (h GetMTOShipmentHandler) Handle(params mtoshipmentops.GetShipmentParams) m "MTOServiceItems.CustomerContacts", "StorageFacility.Address", "PPMShipment", + "BoatShipment", "Distance"} shipmentID := uuid.FromStringOrNil(params.ShipmentID.String()) @@ -285,7 +286,10 @@ func (h UpdateShipmentHandler) Handle(params mtoshipmentops.UpdateMTOShipmentPar mtoShipment := payloads.MTOShipmentModelFromUpdate(payload) mtoShipment.ID = shipmentID - mtoShipment.ShipmentType = oldShipment.ShipmentType + isBoatShipment := mtoShipment.ShipmentType == models.MTOShipmentTypeBoatHaulAway || mtoShipment.ShipmentType == models.MTOShipmentTypeBoatTowAway + if !isBoatShipment { + mtoShipment.ShipmentType = oldShipment.ShipmentType + } //MTOShipmentModelFromUpdate defaults UsesExternalVendor to false if it's nil in the payload if payload.UsesExternalVendor == nil { diff --git a/pkg/services/boat_shipment/rules.go b/pkg/services/boat_shipment/rules.go index 2a655546e92..7e8b0ceb580 100644 --- a/pkg/services/boat_shipment/rules.go +++ b/pkg/services/boat_shipment/rules.go @@ -83,6 +83,11 @@ func checkRequiredFields() boatShipmentValidator { verrs.Add("lengthInInches", "One of these criteria must be met for it to be a boat shipment: lengthInInches > 168, widthInInches > 82, or heightInInches > 77.") } } + if newBoatShipment.HasTrailer != nil && *newBoatShipment.HasTrailer == true { + if newBoatShipment.IsRoadworthy == nil { + verrs.Add("isRoadworthy", "isRoadworthy is required if hasTrailer is true") + } + } return verrs }) } diff --git a/pkg/services/boat_shipment/rules_test.go b/pkg/services/boat_shipment/rules_test.go index f91d78c763a..238c6317ba1 100644 --- a/pkg/services/boat_shipment/rules_test.go +++ b/pkg/services/boat_shipment/rules_test.go @@ -291,6 +291,22 @@ func (suite *BoatShipmentSuite) TestValidationRules() { }, "heightInInches", "One of these criteria must be met for it to be a boat shipment: lengthInInches > 168, widthInInches > 82, or heightInInches > 77."}, + { + + "Invalid isRoadworthy Expected value", + models.BoatShipment{ + ShipmentID: shipmentID, + Year: models.IntPointer(2000), + Make: models.StringPointer("Boat Make"), + Model: models.StringPointer("Boat Model"), + LengthInInches: models.IntPointer(1000), + WidthInInches: models.IntPointer(10), + HeightInInches: models.IntPointer(10), + HasTrailer: models.BoolPointer(true), + IsRoadworthy: nil, + }, + "isRoadworthy", + "isRoadworthy is required if hasTrailer is true"}, } for _, tc := range testCases { diff --git a/pkg/services/boat_shipment/validation.go b/pkg/services/boat_shipment/validation.go index 6b9e126e434..7568e3d10c8 100644 --- a/pkg/services/boat_shipment/validation.go +++ b/pkg/services/boat_shipment/validation.go @@ -83,10 +83,13 @@ func mergeBoatShipment(newBoatShipment models.BoatShipment, oldBoatShipment *mod if newBoatShipment.HeightInInches != nil { boatShipment.HeightInInches = newBoatShipment.HeightInInches } + boatShipment.IsRoadworthy = newBoatShipment.IsRoadworthy if newBoatShipment.HasTrailer != nil { boatShipment.HasTrailer = newBoatShipment.HasTrailer + if *boatShipment.HasTrailer == false { + boatShipment.IsRoadworthy = nil + } } - boatShipment.IsRoadworthy = newBoatShipment.IsRoadworthy return &boatShipment, err } diff --git a/swagger-def/ghc.yaml b/swagger-def/ghc.yaml index 7d7ce67fcef..53425c98888 100644 --- a/swagger-def/ghc.yaml +++ b/swagger-def/ghc.yaml @@ -5698,6 +5698,8 @@ definitions: $ref: 'definitions/StorageFacility.yaml' ppmShipment: $ref: '#/definitions/UpdatePPMShipment' + boatShipment: + $ref: '#/definitions/UpdateBoatShipment' UpdatePPMShipment: type: object properties: @@ -5825,6 +5827,47 @@ definitions: advanceStatus: $ref: 'definitions/PPMAdvanceStatus.yaml' x-nullable: true + UpdateBoatShipment: + type: object + properties: + type: + type: string + enum: + - HAUL_AWAY + - TOW_AWAY + x-nullable: true + year: + type: integer + description: Year of the Boat + x-nullable: true + make: + type: string + description: Make of the Boat + x-nullable: true + model: + type: string + description: Model of the Boat + x-nullable: true + lengthInInches: + type: integer + description: Length of the Boat in inches + x-nullable: true + widthInInches: + type: integer + description: Width of the Boat in inches + x-nullable: true + heightInInches: + type: integer + description: Height of the Boat in inches + x-nullable: true + hasTrailer: + type: boolean + description: Does the boat have a trailer + x-nullable: true + isRoadworthy: + type: boolean + description: Is the trailer roadworthy + x-nullable: true UpdateWeightTicket: type: object properties: @@ -6044,6 +6087,8 @@ definitions: $ref: '#/definitions/CreateMobileHome' ppmShipment: $ref: '#/definitions/CreatePPMShipment' + boatShipment: + $ref: "#/definitions/CreateBoatShipment" required: - moveTaskOrderID - shipmentType @@ -6130,6 +6175,48 @@ definitions: - sitExpected - estimatedWeight - hasProGear + CreateBoatShipment: + description: Boat shipment information for the move. + properties: + type: + type: string + enum: + - HAUL_AWAY + - TOW_AWAY + year: + type: integer + description: Year of the Boat + make: + type: string + description: Make of the Boat + model: + type: string + description: Model of the Boat + lengthInInches: + type: integer + description: Length of the Boat in inches + widthInInches: + type: integer + description: Width of the Boat in inches + heightInInches: + type: integer + description: Height of the Boat in inches + hasTrailer: + type: boolean + description: Does the boat have a trailer + isRoadworthy: + type: boolean + description: Is the trailer roadworthy + x-nullable: true + required: + - type + - year + - make + - model + - lengthInInches + - widthInInches + - heightInInches + - hasTrailer RejectShipment: properties: rejectionReason: diff --git a/swagger/ghc.yaml b/swagger/ghc.yaml index 133f0a21f4c..88a1e6f03c5 100644 --- a/swagger/ghc.yaml +++ b/swagger/ghc.yaml @@ -5927,6 +5927,8 @@ definitions: $ref: '#/definitions/StorageFacility' ppmShipment: $ref: '#/definitions/UpdatePPMShipment' + boatShipment: + $ref: '#/definitions/UpdateBoatShipment' UpdatePPMShipment: type: object properties: @@ -6056,6 +6058,47 @@ definitions: advanceStatus: $ref: '#/definitions/PPMAdvanceStatus' x-nullable: true + UpdateBoatShipment: + type: object + properties: + type: + type: string + enum: + - HAUL_AWAY + - TOW_AWAY + x-nullable: true + year: + type: integer + description: Year of the Boat + x-nullable: true + make: + type: string + description: Make of the Boat + x-nullable: true + model: + type: string + description: Model of the Boat + x-nullable: true + lengthInInches: + type: integer + description: Length of the Boat in inches + x-nullable: true + widthInInches: + type: integer + description: Width of the Boat in inches + x-nullable: true + heightInInches: + type: integer + description: Height of the Boat in inches + x-nullable: true + hasTrailer: + type: boolean + description: Does the boat have a trailer + x-nullable: true + isRoadworthy: + type: boolean + description: Is the trailer roadworthy + x-nullable: true UpdateWeightTicket: type: object properties: @@ -6297,6 +6340,8 @@ definitions: $ref: '#/definitions/MobileHome' ppmShipment: $ref: '#/definitions/CreatePPMShipment' + boatShipment: + $ref: '#/definitions/CreateBoatShipment' required: - moveTaskOrderID - shipmentType @@ -6385,6 +6430,48 @@ definitions: - sitExpected - estimatedWeight - hasProGear + CreateBoatShipment: + description: Boat shipment information for the move. + properties: + type: + type: string + enum: + - HAUL_AWAY + - TOW_AWAY + year: + type: integer + description: Year of the Boat + make: + type: string + description: Make of the Boat + model: + type: string + description: Model of the Boat + lengthInInches: + type: integer + description: Length of the Boat in inches + widthInInches: + type: integer + description: Width of the Boat in inches + heightInInches: + type: integer + description: Height of the Boat in inches + hasTrailer: + type: boolean + description: Does the boat have a trailer + isRoadworthy: + type: boolean + description: Is the trailer roadworthy + x-nullable: true + required: + - type + - year + - make + - model + - lengthInInches + - widthInInches + - heightInInches + - hasTrailer RejectShipment: properties: rejectionReason: From 60ddc53252d8d6324bef0665c0c02d60cfd78842 Mon Sep 17 00:00:00 2001 From: Tae Jung Date: Mon, 19 Aug 2024 21:17:03 +0000 Subject: [PATCH 2/3] test fixes --- pkg/services/boat_shipment/boat_shipment_updater_test.go | 3 +-- pkg/services/boat_shipment/rules.go | 2 +- pkg/services/boat_shipment/validation.go | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/pkg/services/boat_shipment/boat_shipment_updater_test.go b/pkg/services/boat_shipment/boat_shipment_updater_test.go index 25f667e8554..863677b02c3 100644 --- a/pkg/services/boat_shipment/boat_shipment_updater_test.go +++ b/pkg/services/boat_shipment/boat_shipment_updater_test.go @@ -29,7 +29,6 @@ func (suite *BoatShipmentSuite) TestUpdateBoatShipment() { WidthInInches: models.IntPointer(11), HeightInInches: models.IntPointer(1), HasTrailer: models.BoolPointer(false), - IsRoadworthy: models.BoolPointer(false), } updatedBoat, err := boatShipmentUpdater.UpdateBoatShipmentWithDefaultCheck(appCtx, &newBoat, originalBoat.ShipmentID) @@ -43,7 +42,7 @@ func (suite *BoatShipmentSuite) TestUpdateBoatShipment() { suite.Equal(newBoat.WidthInInches, updatedBoat.WidthInInches) suite.Equal(newBoat.HeightInInches, updatedBoat.HeightInInches) suite.Equal(newBoat.HasTrailer, updatedBoat.HasTrailer) - suite.Equal(newBoat.IsRoadworthy, updatedBoat.IsRoadworthy) + suite.Equal(nil, updatedBoat.IsRoadworthy) }) suite.Run("Can't update if Shipment can't be found", func() { diff --git a/pkg/services/boat_shipment/rules.go b/pkg/services/boat_shipment/rules.go index 7e8b0ceb580..78019965d5d 100644 --- a/pkg/services/boat_shipment/rules.go +++ b/pkg/services/boat_shipment/rules.go @@ -83,7 +83,7 @@ func checkRequiredFields() boatShipmentValidator { verrs.Add("lengthInInches", "One of these criteria must be met for it to be a boat shipment: lengthInInches > 168, widthInInches > 82, or heightInInches > 77.") } } - if newBoatShipment.HasTrailer != nil && *newBoatShipment.HasTrailer == true { + if newBoatShipment.HasTrailer != nil && *newBoatShipment.HasTrailer { if newBoatShipment.IsRoadworthy == nil { verrs.Add("isRoadworthy", "isRoadworthy is required if hasTrailer is true") } diff --git a/pkg/services/boat_shipment/validation.go b/pkg/services/boat_shipment/validation.go index 7568e3d10c8..bb8b003fe0a 100644 --- a/pkg/services/boat_shipment/validation.go +++ b/pkg/services/boat_shipment/validation.go @@ -86,7 +86,7 @@ func mergeBoatShipment(newBoatShipment models.BoatShipment, oldBoatShipment *mod boatShipment.IsRoadworthy = newBoatShipment.IsRoadworthy if newBoatShipment.HasTrailer != nil { boatShipment.HasTrailer = newBoatShipment.HasTrailer - if *boatShipment.HasTrailer == false { + if !*boatShipment.HasTrailer { boatShipment.IsRoadworthy = nil } } From 63ada5fdfc7fc01835dc6d11b059b134f197a652 Mon Sep 17 00:00:00 2001 From: Tae Jung Date: Mon, 19 Aug 2024 21:34:15 +0000 Subject: [PATCH 3/3] test nil fix --- pkg/services/boat_shipment/boat_shipment_updater_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/services/boat_shipment/boat_shipment_updater_test.go b/pkg/services/boat_shipment/boat_shipment_updater_test.go index 863677b02c3..995f914751f 100644 --- a/pkg/services/boat_shipment/boat_shipment_updater_test.go +++ b/pkg/services/boat_shipment/boat_shipment_updater_test.go @@ -42,7 +42,7 @@ func (suite *BoatShipmentSuite) TestUpdateBoatShipment() { suite.Equal(newBoat.WidthInInches, updatedBoat.WidthInInches) suite.Equal(newBoat.HeightInInches, updatedBoat.HeightInInches) suite.Equal(newBoat.HasTrailer, updatedBoat.HasTrailer) - suite.Equal(nil, updatedBoat.IsRoadworthy) + suite.Nil(updatedBoat.IsRoadworthy) }) suite.Run("Can't update if Shipment can't be found", func() {