app.get(
"/:presentationId",
sValidator(
"param",
Schema.standardSchemaV1(
Schema.Struct({
presentationId: Schema.String,
}),
),
),
async (c) => {
const presentationId = c.req.valid("param").presentationId;
const result = await Effect.runPromiseExit(
Effect.gen(function* () {
const questionsService = yield* QuestionsService;
return yield* questionsService.getPageInfo(presentationId);
}).pipe(
Effect.provide(QuestionsServiceLive.pipe(Layer.provide(DatabaseLive))),
),
);
const value = getValueOrThrowHonoError(result, (error) => {
Match.type<typeof error>().pipe(
Match.tag("QuestionNotFoundError", (error) => {
throw new HTTPException(404, {
cause: error.cause,
message: `Question with id ${error.questionId} not found`,
});
}),
Match.orElse(() => {
throw new HTTPException(500, {
cause: error.cause,
message: error.message,
});
}),
)(error);
});
return c.json(value);
},
);
app.get(
"/:presentationId",
sValidator(
"param",
Schema.standardSchemaV1(
Schema.Struct({
presentationId: Schema.String,
}),
),
),
async (c) => {
const presentationId = c.req.valid("param").presentationId;
const result = await Effect.runPromiseExit(
Effect.gen(function* () {
const questionsService = yield* QuestionsService;
return yield* questionsService.getPageInfo(presentationId);
}).pipe(
Effect.provide(QuestionsServiceLive.pipe(Layer.provide(DatabaseLive))),
),
);
const value = getValueOrThrowHonoError(result, (error) => {
Match.type<typeof error>().pipe(
Match.tag("QuestionNotFoundError", (error) => {
throw new HTTPException(404, {
cause: error.cause,
message: `Question with id ${error.questionId} not found`,
});
}),
Match.orElse(() => {
throw new HTTPException(500, {
cause: error.cause,
message: error.message,
});
}),
)(error);
});
return c.json(value);
},
);