def add()

in auctionServer/src/main/scala/com/google/example/services/auction/AuctionDataStore.scala [24:48]


  def add(user: String, description: String, minBid: Float): Auction
  /** Deletes an auction, returning its value. */
  def delete(id: Long): Option[Auction]
  /** Returns all live auctions. */
  def get(id: Long): Option[Auction]
  /** Returns all live auctions. */
  def list(): Seq[Auction]
  /** Creates a new bid on a specific auction. */
  def bid(id: Long, user: String, bid: Float): Option[Auction]


/** Lame, synchronous in-memory implementation. */
class LocalAuctionDataStore extends AuctionDataStore:
  println("Starting in-memory auction datastore.")
  private var nextId = 1L
  private var auctions = List[Auction](Auction(5000, "seed item", "Josh", 0, Seq()))


  override def add(user: String, description: String, minBid: Float): Auction =
    synchronized {
      val auction = Auction(nextId, description, user, minBid, List())
      nextId += 1
      auctions = auction :: auctions
      auction
    }