(WIP) Creating auctions

This commit is contained in:
2026-07-17 23:24:33 +03:00
parent a004c1a97e
commit e7bf5c1460
2 changed files with 20 additions and 3 deletions
@@ -5,7 +5,7 @@ import jakarta.inject.{Inject, Singleton}
import models.AuthToken import models.AuthToken
import play.api.libs.json.* import play.api.libs.json.*
import play.api.libs.functional.syntax.* 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} import scala.concurrent.{ExecutionContext, Future}
@@ -22,7 +22,10 @@ implicit val tokenWrites: Writes[AuthToken] = (token: AuthToken) => Json.obj(
@Singleton @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 => def login() = Action.async(parse.json) { implicit request =>
val loginDataResult = request.body.validate[LoginData] val loginDataResult = request.body.validate[LoginData]
loginDataResult.fold( 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("") } authTokensDAO.destroy(request.token).map{ _ => Ok("") }
} }
} }
+14
View File
@@ -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;