Beispiel #1
0
func updatePortsOfCallHistory(shipName string, changes []interface{}) {
	var store hist.Eventstore
	var err error
	if useDynamo {
		store, err = dynamostore.DynamoStore(eventstoreTable, region, endpoint)
		failIf(err)
	} else {
		store, err = filestore.FileStore(dataStoreDirectory)
		failIf(err)
	}
	for _, event := range changes {
		jsonEvent, err := json.Marshal(event)
		failIf(err)
		store.Save("Ship", shipName, reflect.TypeOf(event).String(), []byte(jsonEvent))
	}
}
Beispiel #2
0
func getPortsOfCallHistory(shipName string) []interface{} {
	var store hist.Eventstore
	var err error
	if useDynamo {
		store, err = dynamostore.DynamoStore(eventstoreTable, region, endpoint)
		failIf(err)
	} else {
		store, err = filestore.FileStore(dataStoreDirectory)
		failIf(err)
	}

	eventHistory, err := store.Get(shipAggregateType, shipName)
	failIf(err)

	var events []interface{}
	for _, item := range eventHistory {
		if item.Type == "ship.Registered" {
			var event ship.Registered
			err := json.Unmarshal(item.Data, &event)
			failIf(err)
			events = append(events, event)
		}
		if item.Type == "ship.Arrived" {
			var event ship.Arrived
			err := json.Unmarshal(item.Data, &event)
			failIf(err)
			events = append(events, event)
		}
		if item.Type == "ship.Departed" {
			var event ship.Departed
			err := json.Unmarshal(item.Data, &event)
			failIf(err)
			events = append(events, event)
		}
	}
	return events
}