Created
April 18, 2022 10:12
-
-
Save liampulles/e84c51c77699c9c929dfdf5467202c9d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// FromInventoryItemView converts a view to JSON | |
func (e *EncoderServiceImpl) FromInventoryItemView(view *inventory.ViewVO) ([]byte, error) { | |
intermediary := mapViewIntermediary(view) | |
bytes, err := json.Marshal(intermediary) | |
if err != nil { | |
return nil, fmt.Errorf("could not convert inventory item view to json - marshal error: %w", err) | |
} | |
return bytes, nil | |
} | |
func mapViewIntermediary(view *inventory.ViewVO) *jsonViewVO { | |
return &jsonViewVO{ | |
ID: view.ID, | |
Name: view.Name, | |
Location: view.Location, | |
Available: view.Available, | |
} | |
} | |
type jsonViewVO struct { | |
ID entity.ID `json:"id"` | |
Name string `json:"name"` | |
Location string `json:"location"` | |
Available bool `json:"available"` | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment