From e7bf5c1460e1a1c83a408ffc8f383fb47146be09 Mon Sep 17 00:00:00 2001 From: Artemiy Solopov Date: Fri, 17 Jul 2026 23:24:33 +0300 Subject: [PATCH] (WIP) Creating auctions --- .../authentication/SessionsController.scala | 9 ++++++--- conf/evolutions/default/3.sql | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 conf/evolutions/default/3.sql diff --git a/app/controllers/authentication/SessionsController.scala b/app/controllers/authentication/SessionsController.scala index 56b130b..5ce9d30 100644 --- a/app/controllers/authentication/SessionsController.scala +++ b/app/controllers/authentication/SessionsController.scala @@ -5,7 +5,7 @@ import jakarta.inject.{Inject, Singleton} import models.AuthToken import play.api.libs.json.* import play.api.libs.functional.syntax.* -import play.api.mvc.{AbstractController, ControllerComponents} +import play.api.mvc.{AbstractController, Action, AnyContent, ControllerComponents} import scala.concurrent.{ExecutionContext, Future} @@ -22,7 +22,10 @@ implicit val tokenWrites: Writes[AuthToken] = (token: AuthToken) => Json.obj( @Singleton -class SessionsController @Inject()(controllerComponents: ControllerComponents, usersDAO: UsersDAO, authTokensDAO: AuthTokensDAO, implicit val ec: ExecutionContext) extends AbstractController(controllerComponents) { +class SessionsController @Inject()(controllerComponents: ControllerComponents, + usersDAO: UsersDAO, authTokensDAO: AuthTokensDAO, + authenticatedAction: AuthenticatedAction, + implicit val ec: ExecutionContext) extends AbstractController(controllerComponents) { def login() = Action.async(parse.json) { implicit request => val loginDataResult = request.body.validate[LoginData] loginDataResult.fold( @@ -41,7 +44,7 @@ class SessionsController @Inject()(controllerComponents: ControllerComponents, u ) } - def logout = Action.andThen(new AuthenticatedAction(authTokensDAO)).async { request => + def logout = (Action andThen authenticatedAction).async { request => authTokensDAO.destroy(request.token).map{ _ => Ok("") } } } diff --git a/conf/evolutions/default/3.sql b/conf/evolutions/default/3.sql new file mode 100644 index 0000000..856eb79 --- /dev/null +++ b/conf/evolutions/default/3.sql @@ -0,0 +1,14 @@ +-- !Ups +CREATE TABLE auctions +( + id BIGINT PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, + gid VARCHAR UNIQUE NOT NULL, + author_id BIGINT NOT NULL REFERENCES users (id) ON DELETE RESTRICT, + description VARCHAR, + starting_price DECIMAL(12, 3) NOT NULL, + current_bid DECIMAL(12, 3), + current_bidder_id BIGINT REFERENCES users (id) ON DELETE SET NULL +); + +-- !Downs +DROP TABLE auctions; \ No newline at end of file