import { Elysia } from "elysia";
import { GamesService, gamesServiceImpl } from "./service";
import { Effect, Either } from "effect";
export const gamesController = new Elysia().get(
"/:slug",
({ params: { slug }, status }) => {
return Effect.runPromise(
Effect.gen(function* () {
const gamesService = yield* GamesService;
const value = gamesService.getOne(slug);
const failureOrSuccess = yield* Effect.either(value);
return Either.match(failureOrSuccess, {
onLeft: (error) => {
switch (error._tag) {
case "GameNotFoundError":
return status(404, "Game not found");
case "DBError":
return status(500, "Internal error");
}
},
onRight: (value) => value,
});
}).pipe(Effect.provideService(GamesService, gamesServiceImpl)),
);
},
);
import { Elysia } from "elysia";
import { GamesService, gamesServiceImpl } from "./service";
import { Effect, Either } from "effect";
export const gamesController = new Elysia().get(
"/:slug",
({ params: { slug }, status }) => {
return Effect.runPromise(
Effect.gen(function* () {
const gamesService = yield* GamesService;
const value = gamesService.getOne(slug);
const failureOrSuccess = yield* Effect.either(value);
return Either.match(failureOrSuccess, {
onLeft: (error) => {
switch (error._tag) {
case "GameNotFoundError":
return status(404, "Game not found");
case "DBError":
return status(500, "Internal error");
}
},
onRight: (value) => value,
});
}).pipe(Effect.provideService(GamesService, gamesServiceImpl)),
);
},
);