Skip to content

Instantly share code, notes, and snippets.

@liampulles
Created April 18, 2022 10:12
Show Gist options
  • Save liampulles/e84c51c77699c9c929dfdf5467202c9d to your computer and use it in GitHub Desktop.
Save liampulles/e84c51c77699c9c929dfdf5467202c9d to your computer and use it in GitHub Desktop.
// 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