temporarily hardcoding backend room and session

This commit is contained in:
efim 2023-04-26 08:56:51 +04:00
parent 6c1220b544
commit 1f28a03d47
6 changed files with 17 additions and 49 deletions

View File

@ -39,31 +39,6 @@ trait Auth[F[_]] {
}
object Auth {
def pureBadStub = new Auth[IO] {
override def authUser =
Kleisli((req: Request[IO]) =>
OptionT.liftF(
IO(println(s"authUser: $req")) >> IO(
PlayerID(14) -> RoomID("testroom")
)
)
)
override def joinRoom(
roomName: String,
roomPassword: String,
nickName: String,
nickPassword: String
) =
IO(
println(
s"> access room for $roomName $roomPassword $nickName, to return stub 111"
)
) >> IO.pure(Right(ResponseCookie("authcookieName", "1")))
override def deleteSession(sessionId: Long): IO[Unit] =
IO(s"got request to leave for $sessionId")
}
type SessionsMap = Map[Long, (RoomID, PlayerID)]
class SimpleAuth[F[_]: Sync](
@ -118,8 +93,6 @@ object Auth {
def make[F[_]: Sync](roomsService: RoomService[F]): F[Auth[F]] =
for {
sessionsMap <- Ref.of[F, SessionsMap](
Map(1L -> (RoomID("testroom"), PlayerID(1L)))
)
sessionsMap <- Ref.of[F, SessionsMap](TestModels.testSessions)
} yield new SimpleAuth(sessionsMap, roomsService)
}

View File

@ -14,7 +14,8 @@ object BackendApp extends IOApp {
val wiring = for {
roomService <- Resource.eval(RoomService.make[IO])
httpService = MyHttpService.create(Auth.pureBadStub)
auth <- Resource.eval(Auth.make(roomService))
httpService = MyHttpService.create(auth)
server <- EmberServerBuilder
.default[IO]
.withHost(host)

View File

@ -34,7 +34,7 @@ object MyHttpService {
case WebSocketFrame.Text(text, _) => Sync[IO].delay(println(text))
case other => Sync[IO].delay(println(other))
}
wsb.build(send, receive)
IO(println(s"got ws request from $playerId in $roomId")) >> wsb.build(send, receive)
}
case GET -> Root / "vote" / vote as (playerId, roomId) => {
// TODO forward these to the service implementation
@ -60,7 +60,8 @@ object MyHttpService {
data.roomName,
data.password,
data.nickname,
data.nickPassword)
data.nickPassword
)
resp <- authResult match {
case Left(error) =>
Forbidden(error)

View File

@ -91,6 +91,6 @@ class InMemoryRoomService[F[_]: Sync](stateRef: Ref[F, Map[RoomID, Room]]) exten
}
object RoomService {
def make[F[_]: Sync]: F[RoomService[F]] = {
Ref.of[F, Map[RoomID, Room]](Map.empty).map(new InMemoryRoomService[F](_))
Ref.of[F, Map[RoomID, Room]](TestModels.testRooms).map(new InMemoryRoomService[F](_))
}
}

View File

@ -8,26 +8,20 @@ object TestModels {
val birdy = Player("birdy", PlayerID(11))
val horsey = Player("horsey", PlayerID(12))
val testRoom = {
RoomStateView(
players = List(me, birdy, pony),
me = me.id,
allowedCards = List("xs", "s", "m", "l", "xl"),
round = RoundState.Voting(myCard = Some("s"), alreadyVoted = List(me, pony)),
canCloseRound = true
)
}
val testOpenedRoom = {
RoomStateView(
val testRoomBackend = Room(
id = RoomID("testroom"),
players = List(me, birdy, pony, horsey),
me = me.id,
owner = me.id,
password = "password",
allowedCards = List("xs", "s", "m", "l", "xl"),
round = RoundState.Viewing(
round = RoundState.Viewing(
List(me.id -> "xs", pony.id -> "l", birdy.id -> "s", horsey.id -> "m")
),
canCloseRound = true
)
}
playersPasswords = Map.empty // nickname into password
)
val testSessions = Map(1L -> (testRoomBackend.id, me.id))
val testRooms = Map(testRoomBackend.id -> testRoomBackend)
val testChangesList = List(
RoomStateView(

View File

@ -25,7 +25,6 @@ object Main {
)
// TODO is this ok for state creation? link with auth component and use in another?
val appStateSignal = Var(AppState(Some(TestModels.me.id))).signal
val staticStateSignal = Var(TestModels.testRoom).signal
import io.laminext.websocket.circe.WebSocket._
import io.laminext.websocket.circe.webSocketReceiveBuilderSyntax