temporarily hardcoding backend room and session
This commit is contained in:
parent
6c1220b544
commit
1f28a03d47
|
@ -39,31 +39,6 @@ trait Auth[F[_]] {
|
||||||
}
|
}
|
||||||
|
|
||||||
object Auth {
|
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)]
|
type SessionsMap = Map[Long, (RoomID, PlayerID)]
|
||||||
|
|
||||||
class SimpleAuth[F[_]: Sync](
|
class SimpleAuth[F[_]: Sync](
|
||||||
|
@ -118,8 +93,6 @@ object Auth {
|
||||||
|
|
||||||
def make[F[_]: Sync](roomsService: RoomService[F]): F[Auth[F]] =
|
def make[F[_]: Sync](roomsService: RoomService[F]): F[Auth[F]] =
|
||||||
for {
|
for {
|
||||||
sessionsMap <- Ref.of[F, SessionsMap](
|
sessionsMap <- Ref.of[F, SessionsMap](TestModels.testSessions)
|
||||||
Map(1L -> (RoomID("testroom"), PlayerID(1L)))
|
|
||||||
)
|
|
||||||
} yield new SimpleAuth(sessionsMap, roomsService)
|
} yield new SimpleAuth(sessionsMap, roomsService)
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,8 @@ object BackendApp extends IOApp {
|
||||||
|
|
||||||
val wiring = for {
|
val wiring = for {
|
||||||
roomService <- Resource.eval(RoomService.make[IO])
|
roomService <- Resource.eval(RoomService.make[IO])
|
||||||
httpService = MyHttpService.create(Auth.pureBadStub)
|
auth <- Resource.eval(Auth.make(roomService))
|
||||||
|
httpService = MyHttpService.create(auth)
|
||||||
server <- EmberServerBuilder
|
server <- EmberServerBuilder
|
||||||
.default[IO]
|
.default[IO]
|
||||||
.withHost(host)
|
.withHost(host)
|
||||||
|
|
|
@ -34,7 +34,7 @@ object MyHttpService {
|
||||||
case WebSocketFrame.Text(text, _) => Sync[IO].delay(println(text))
|
case WebSocketFrame.Text(text, _) => Sync[IO].delay(println(text))
|
||||||
case other => Sync[IO].delay(println(other))
|
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) => {
|
case GET -> Root / "vote" / vote as (playerId, roomId) => {
|
||||||
// TODO forward these to the service implementation
|
// TODO forward these to the service implementation
|
||||||
|
@ -60,7 +60,8 @@ object MyHttpService {
|
||||||
data.roomName,
|
data.roomName,
|
||||||
data.password,
|
data.password,
|
||||||
data.nickname,
|
data.nickname,
|
||||||
data.nickPassword)
|
data.nickPassword
|
||||||
|
)
|
||||||
resp <- authResult match {
|
resp <- authResult match {
|
||||||
case Left(error) =>
|
case Left(error) =>
|
||||||
Forbidden(error)
|
Forbidden(error)
|
||||||
|
|
|
@ -91,6 +91,6 @@ class InMemoryRoomService[F[_]: Sync](stateRef: Ref[F, Map[RoomID, Room]]) exten
|
||||||
}
|
}
|
||||||
object RoomService {
|
object RoomService {
|
||||||
def make[F[_]: Sync]: F[RoomService[F]] = {
|
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](_))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,26 +8,20 @@ object TestModels {
|
||||||
val birdy = Player("birdy", PlayerID(11))
|
val birdy = Player("birdy", PlayerID(11))
|
||||||
val horsey = Player("horsey", PlayerID(12))
|
val horsey = Player("horsey", PlayerID(12))
|
||||||
|
|
||||||
val testRoom = {
|
val testRoomBackend = Room(
|
||||||
RoomStateView(
|
id = RoomID("testroom"),
|
||||||
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(
|
|
||||||
players = List(me, birdy, pony, horsey),
|
players = List(me, birdy, pony, horsey),
|
||||||
me = me.id,
|
owner = me.id,
|
||||||
|
password = "password",
|
||||||
allowedCards = List("xs", "s", "m", "l", "xl"),
|
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")
|
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(
|
val testChangesList = List(
|
||||||
RoomStateView(
|
RoomStateView(
|
||||||
|
|
|
@ -25,7 +25,6 @@ object Main {
|
||||||
)
|
)
|
||||||
// TODO is this ok for state creation? link with auth component and use in another?
|
// 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 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.WebSocket._
|
||||||
import io.laminext.websocket.circe.webSocketReceiveBuilderSyntax
|
import io.laminext.websocket.circe.webSocketReceiveBuilderSyntax
|
||||||
|
|
Loading…
Reference in New Issue