temporarily hardcoding backend room and session
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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](_))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user