From 4496e089bca542fc98bfad0e005469211e7cbc1e Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Sun, 8 Feb 2015 20:06:39 +0100 Subject: Implement current sales listing --- app/controllers/Sale.scala | 37 +++++++++++++++++++++++++++++ app/models/Views.scala | 12 +++++++--- conf/routes | 55 ++++++++++++++++++++++---------------------- res/sql/orcl_all.sql | 4 ++++ res/sql/pg_all.sql | 4 ++++ res/sql/views/orcl_sales.sql | 2 ++ res/sql/views/pg_sales.sql | 2 ++ 7 files changed, 86 insertions(+), 30 deletions(-) create mode 100644 app/controllers/Sale.scala diff --git a/app/controllers/Sale.scala b/app/controllers/Sale.scala new file mode 100644 index 0000000..b5e4622 --- /dev/null +++ b/app/controllers/Sale.scala @@ -0,0 +1,37 @@ +package controllers + +import play.api._ +import play.api.data._ +import play.api.data.Forms._ +import play.api.mvc._ + +import play.api.db.slick._ +import play.api.db.slick.Config.driver.simple._ +import play.api.Play.current + +import scala.concurrent.Future + +import models._ + + +object Sale extends Controller { + + def sales = Auth { implicit request => + DB.withSession { implicit session => + val currentDateTime = new java.sql.Timestamp((new java.util.Date).getTime) + val sales = Views.Sales.filter(_.endDate > currentDateTime).sortBy(_.endDate.asc).run + + Ok(views.html.pages.sales.currentSales(sales)) + } + } + + def sell(itemUuid: String) = TODO + + + def item(itemUuid: String) = TODO + + def bids(itemUuid: String) = TODO + + def bidSubmit(itemUuid: String) = TODO + +} diff --git a/app/models/Views.scala b/app/models/Views.scala index 438c1d3..154ca86 100644 --- a/app/models/Views.scala +++ b/app/models/Views.scala @@ -48,25 +48,29 @@ trait Views { /** Entity class storing rows of table Sales * @param itemUuid Database column item_uuid DBType(varchar), Length(36,true), Default(None) + * @param itemName Database column item_name DBType(varchar), Length(20,true), Default(None) * @param sellerUuid Database column seller_uuid DBType(varchar), Length(36,true), Default(None) * @param startDate Database column start_date DBType(timestamptz), Default(None) * @param endDate Database column end_date DBType(timestamptz), Default(None) * @param bestBidUuid Database column best_bid_uuid DBType(varchar), Length(36,true), Default(None) * @param bestBidderUuid Database column best_bidder_uuid DBType(varchar), Length(36,true), Default(None) + * @param initialPrice Database column initial_price DBType(numeric), Default(None) * @param bestOffer Database column best_offer DBType(numeric), Default(None) * @param charges Database column charges DBType(numeric), Default(None) */ - case class Sale(itemUuid: Option[String] = None, sellerUuid: Option[String] = None, startDate: Option[java.sql.Timestamp] = None, endDate: Option[java.sql.Timestamp] = None, bestBidUuid: Option[String] = None, bestBidderUuid: Option[String] = None, bestOffer: Option[scala.math.BigDecimal] = None, charges: Option[scala.math.BigDecimal] = None) + case class Sale(itemUuid: Option[String] = None, itemName: Option[String] = None, sellerUuid: Option[String] = None, startDate: Option[java.sql.Timestamp] = None, endDate: Option[java.sql.Timestamp] = None, bestBidUuid: Option[String] = None, bestBidderUuid: Option[String] = None, initialPrice: Option[scala.math.BigDecimal] = None, bestOffer: Option[scala.math.BigDecimal] = None, charges: Option[scala.math.BigDecimal] = None) /** GetResult implicit for fetching Sale objects using plain SQL queries */ implicit def GetResultSale(implicit e0: GR[Option[String]], e1: GR[Option[java.sql.Timestamp]], e2: GR[Option[scala.math.BigDecimal]]): GR[Sale] = GR{ prs => import prs._ - Sale.tupled((< (Sale.tupled, Sale.unapply) + def * = (itemUuid, itemName, sellerUuid, startDate, endDate, bestBidUuid, bestBidderUuid, initialPrice, bestOffer, charges) <> (Sale.tupled, Sale.unapply) /** Database column item_uuid DBType(varchar), Length(36,true), Default(None) */ val itemUuid: Column[Option[String]] = column[Option[String]]("item_uuid", O.Length(36,varying=true), O.Default(None)) + /** Database column item_name DBType(varchar), Length(20,true), Default(None) */ + val itemName: Column[Option[String]] = column[Option[String]]("item_name", O.Length(20,varying=true), O.Default(None)) /** Database column seller_uuid DBType(varchar), Length(36,true), Default(None) */ val sellerUuid: Column[Option[String]] = column[Option[String]]("seller_uuid", O.Length(36,varying=true), O.Default(None)) /** Database column start_date DBType(timestamptz), Default(None) */ @@ -77,6 +81,8 @@ trait Views { val bestBidUuid: Column[Option[String]] = column[Option[String]]("best_bid_uuid", O.Length(36,varying=true), O.Default(None)) /** Database column best_bidder_uuid DBType(varchar), Length(36,true), Default(None) */ val bestBidderUuid: Column[Option[String]] = column[Option[String]]("best_bidder_uuid", O.Length(36,varying=true), O.Default(None)) + /** Database column initial_price DBType(numeric), Default(None) */ + val initialPrice: Column[Option[scala.math.BigDecimal]] = column[Option[scala.math.BigDecimal]]("initial_price", O.Default(None)) /** Database column best_offer DBType(numeric), Default(None) */ val bestOffer: Column[Option[scala.math.BigDecimal]] = column[Option[scala.math.BigDecimal]]("best_offer", O.Default(None)) /** Database column charges DBType(numeric), Default(None) */ diff --git a/conf/routes b/conf/routes index d9d1cb1..06081d1 100644 --- a/conf/routes +++ b/conf/routes @@ -4,45 +4,46 @@ # Home page -GET / controllers.Application.index -GET /terms controllers.Application.terms -GET /privacy controllers.Application.privacy +GET / controllers.Application.index +GET /terms controllers.Application.terms +GET /privacy controllers.Application.privacy # User account -GET /login controllers.Authentication.login -POST /login controllers.Authentication.loginSubmit +GET /login controllers.Authentication.login +POST /login controllers.Authentication.loginSubmit -GET /logout controllers.Authentication.logout +GET /logout controllers.Authentication.logout -GET /signup controllers.Profile.signup -POST /signup controllers.Profile.signupSubmit +GET /signup controllers.Profile.signup +POST /signup controllers.Profile.signupSubmit #GET /profile controllers.Application.index #POST /profile controllers.Application.index -# -## Internal wallet and transactions (Pépal) -GET /account controllers.Account.summary -# + +# Internal wallet and transactions (Pépal) +GET /account controllers.Account.summary + #GET /deposit controllers.Application.index #POST /deposit controllers.Application.index -# + #GET /withdraw controllers.Application.index #POST /withdraw controllers.Application.index -# -## Items and sales (eBé) -#GET /sales/:page controllers.Application.index -# -#GET /item/:uuid controllers.Application.index -# -#GET /item/:uuid/bids controllers.Application.index -#POST /item/:uuid/bids controllers.Application.index -# -#GET /sell controllers.Application.index -#GET /sell/:uuid controllers.Application.index -#POST /sell controllers.Application.index + +# Items and sales (eBé) +GET /sales controllers.Sale.sales + +GET /item/:uuid controllers.Sale.item(uuid) + +GET /item/:uuid/bids controllers.Sale.bids(uuid) +POST /item/:uuid/bids controllers.Sale.bids(uuid) + +GET /sell controllers.Sale.sell(itemUuid = null) +GET /sell/:uuid controllers.Sale.sell(uuid) +POST /sell controllers.Sale.sell(itemUuid = null) +POST /sell/:uuid controllers.Sale.sell(uuid) # Cheat console -POST /console controllers.Console.console +POST /console controllers.Console.console # Map static resources from the /public folder to the /assets URL path -GET /assets/*file controllers.Assets.at(path="/public", file) +GET /assets/*file controllers.Assets.at(path="/public", file) diff --git a/res/sql/orcl_all.sql b/res/sql/orcl_all.sql index 08015f4..b3b4072 100644 --- a/res/sql/orcl_all.sql +++ b/res/sql/orcl_all.sql @@ -173,11 +173,13 @@ CREATE OR REPLACE VIEW sales AS SELECT items.uuid AS item_uuid, + items.item_name AS item_name, items.user_uuid AS seller_uuid, items.start_date AS start_date, items.end_date AS end_date, best_bids.uuid AS best_bid_uuid, best_bids.user_uuid AS best_bidder_uuid, + items.initial_price AS initial_price, best_bids.offer AS best_offer, COALESCE(charges.fee, 0) + COALESCE(charges.rate, 0) * best_bids.offer AS charges @@ -218,6 +220,8 @@ CREATE OR REPLACE VIEW sales AS GROUP BY charges.start_date, charges.end_date ) charges ON items.end_date BETWEEN charges.start_date AND charges.end_date; + + CREATE OR REPLACE VIEW accounts AS SELECT diff --git a/res/sql/pg_all.sql b/res/sql/pg_all.sql index 5d763e0..cecb7ed 100644 --- a/res/sql/pg_all.sql +++ b/res/sql/pg_all.sql @@ -164,11 +164,13 @@ CREATE OR REPLACE VIEW sales AS SELECT items.uuid AS item_uuid, + items.item_name AS item_name, items.user_uuid AS seller_uuid, items.start_date AS start_date, items.end_date AS end_date, best_bids.uuid AS best_bid_uuid, best_bids.user_uuid AS best_bidder_uuid, + items.initial_price AS initial_price, best_bids.offer AS best_offer, COALESCE(charges.fee, 0) + COALESCE(charges.rate, 0) * best_bids.offer AS charges @@ -192,6 +194,8 @@ CREATE OR REPLACE VIEW sales AS GROUP BY charges.start_date, charges.end_date ) charges ON items.end_date BETWEEN charges.start_date AND charges.end_date; + + CREATE OR REPLACE VIEW accounts AS SELECT diff --git a/res/sql/views/orcl_sales.sql b/res/sql/views/orcl_sales.sql index 851d17e..b585819 100644 --- a/res/sql/views/orcl_sales.sql +++ b/res/sql/views/orcl_sales.sql @@ -2,11 +2,13 @@ CREATE OR REPLACE VIEW sales AS SELECT items.uuid AS item_uuid, + items.item_name AS item_name, items.user_uuid AS seller_uuid, items.start_date AS start_date, items.end_date AS end_date, best_bids.uuid AS best_bid_uuid, best_bids.user_uuid AS best_bidder_uuid, + items.initial_price AS initial_price, best_bids.offer AS best_offer, COALESCE(charges.fee, 0) + COALESCE(charges.rate, 0) * best_bids.offer AS charges diff --git a/res/sql/views/pg_sales.sql b/res/sql/views/pg_sales.sql index f36d8e7..f1705f1 100644 --- a/res/sql/views/pg_sales.sql +++ b/res/sql/views/pg_sales.sql @@ -2,11 +2,13 @@ CREATE OR REPLACE VIEW sales AS SELECT items.uuid AS item_uuid, + items.item_name AS item_name, items.user_uuid AS seller_uuid, items.start_date AS start_date, items.end_date AS end_date, best_bids.uuid AS best_bid_uuid, best_bids.user_uuid AS best_bidder_uuid, + items.initial_price AS initial_price, best_bids.offer AS best_offer, COALESCE(charges.fee, 0) + COALESCE(charges.rate, 0) * best_bids.offer AS charges -- cgit v1.2.3