feat(collection): auto assignment id to new Product in CollectonManager
This commit is contained in:
@@ -8,9 +8,12 @@ class CollectionManager(
|
|||||||
private val io: IOHandler,
|
private val io: IOHandler,
|
||||||
) {
|
) {
|
||||||
private val list = LinkedList<Product>()
|
private val list = LinkedList<Product>()
|
||||||
|
private var currId = 1L
|
||||||
|
|
||||||
fun addProduct(product: Product) {
|
fun addProduct(product: Product) {
|
||||||
list.add(product)
|
val productWithId = product.copy(id = currId)
|
||||||
|
list.add(productWithId)
|
||||||
|
currId++
|
||||||
io.println(list.toString())
|
io.println(list.toString())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user