in inventory-release/main.go [74:104]
func getTransaction(ctx context.Context, orderID string) (models.Inventory, error) {
inventory := models.Inventory{}
input := &dynamodb.QueryInput{
ExpressionAttributeValues: map[string]*dynamodb.AttributeValue{
":v1": {
S: aws.String(orderID),
},
":v2": {
S: aws.String("Reserve"),
},
},
KeyConditionExpression: aws.String("order_id = :v1 AND transaction_type = :v2"),
TableName: aws.String(os.Getenv("TABLE_NAME")),
IndexName: aws.String("orderIDIndex"),
}
// Get payment transaction from database
result, err := dynamoDB.QueryWithContext(ctx, input)
if err != nil {
return inventory, err
}
err = dynamodbattribute.UnmarshalMap(result.Items[0], &inventory)
if err != nil {
return inventory, fmt.Errorf("failed to DynamoDB unmarshal Record, %v", err.(awserr.Error))
}
return inventory, nil
}