Skip to content

Instantly share code, notes, and snippets.

@fitomad
Created April 23, 2019 10:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fitomad/8a086755e859133b8037c4d2102b23d8 to your computer and use it in GitHub Desktop.
Save fitomad/8a086755e859133b8037c4d2102b23d8 to your computer and use it in GitHub Desktop.
var store = AppleStore()
var database = Database()
print(store)
store.apply(action: .venta, to: .iPhone, quantity: 2)
print(store)
store.apply(action: .venta, to: .iPhone, quantity: 10)
print(store)
store.apply(action: .devolucion, to: .iPhone, quantity: 3)
print(store)
//
// Ahora vamos a recepcionar productos en la Apple Store
// Vamos a guardar el estado de la tienda
let mementoBefore = store.createMemento()
print("$$$ Guardamos este memento")
database.saveMemento(mementoBefore)
store.apply(action: .reposicion, to: .iPhone, quantity: 200)
store.apply(action: .reposicion, to: .iPad, quantity: 200)
store.apply(action: .reposicion, to: .appleTV, quantity: 200)
print(store)
//
// La etiquetas QR de las cajas tenían un error.
// Pone que cada una contenía 200 items, pero en realidad son 20
// Vamos a volver al estado previo
//
if let mementoRollback = database.lastMemento()
{
print("$$$ Restauramos al memento anterior")
store.restore(from: mementoRollback)
}
//
// Veamos si hemos vuelto al estado anterior
//
print(store)
//
// Ahora los añadimos bien
//
store.apply(action: .reposicion, to: .iPhone, quantity: 20)
store.apply(action: .reposicion, to: .iPad, quantity: 20)
store.apply(action: .reposicion, to: .appleTV, quantity: 20)
//
// A ver cómo estamos ahora...
//
print(store)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment