-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CES-644] List tasks #57
Changes from 5 commits
f572ee2
2c533e6
a92f0dc
8db13bb
499671c
648843f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,6 @@ export const makeContainerMock = () => | |
mock({ | ||
items: { | ||
create: mockFn(), | ||
query: mockFn(), | ||
}, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { FeedResponse } from "@azure/cosmos"; | ||
import * as E from "fp-ts/lib/Either.js"; | ||
import { pipe } from "fp-ts/lib/function.js"; | ||
import * as t from "io-ts"; | ||
|
||
/** | ||
* Decode a list of resources, extracted from a FeedResponse, using a codec. | ||
* | ||
* @param codec the io-ts codec to use to decode the resources | ||
*/ | ||
export const decodeFromFeed = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thought: this function, and also other decode functions, might be in a separate package and could be used to parse what's coming from the CosmosDB server to a well-known domain type. |
||
<A, O>(codec: t.Type<A, O>) => | ||
<T extends FeedResponse<unknown>>(list: T) => | ||
pipe( | ||
list.resources, | ||
t.array(codec).decode, | ||
E.mapLeft( | ||
() => | ||
new Error(`Unable to parse the resources using codec ${codec.name}`), | ||
), | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import * as H from "@pagopa/handler-kit"; | ||
import { httpAzureFunction } from "@pagopa/handler-kit-azure-func"; | ||
import * as RTE from "fp-ts/lib/ReaderTaskEither.js"; | ||
import * as RA from "fp-ts/lib/ReadonlyArray.js"; | ||
import { flow, pipe } from "fp-ts/lib/function.js"; | ||
|
||
import { Capabilities } from "../../../domain/Capabilities.js"; | ||
import { listTasks } from "../../../domain/TaskRepository.js"; | ||
import { TaskItemList } from "../../../generated/definitions/internal/TaskItemList.js"; | ||
import { toHttpProblemJson, toTaskItemAPI } from "../../http/codec.js"; | ||
|
||
type Env = Pick<Capabilities, "taskRepository">; | ||
|
||
const makeHandlerKitHandler: H.Handler< | ||
H.HttpRequest, | ||
| H.HttpResponse<H.ProblemJson, H.HttpErrorStatusCode> | ||
| H.HttpResponse<TaskItemList>, | ||
Env | ||
> = H.of(() => | ||
pipe( | ||
RTE.ask<Env>(), | ||
// execute use case | ||
RTE.flatMap(listTasks), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: in this case, the this is wanted because the use case would be just a wrapper around the function already used, the |
||
// handle result and prepare response | ||
RTE.mapBoth(toHttpProblemJson, flow(RA.map(toTaskItemAPI), H.successJson)), | ||
RTE.orElseW(RTE.of), | ||
), | ||
); | ||
|
||
export const makeGetTasksHandler = httpAzureFunction(makeHandlerKitHandler); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* Do not edit this file it is auto-generated by io-utils / gen-api-models. | ||
* See https://github.com/pagopa/io-utils | ||
*/ | ||
/* eslint-disable */ | ||
|
||
import * as t from "io-ts"; | ||
import { TaskItem } from "./TaskItem.js"; | ||
|
||
export type TaskItemList = t.TypeOf<typeof TaskItemList>; | ||
export const TaskItemList = t.readonlyArray(TaskItem, "array of TaskItem"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: Currently, due to the goal of this playground, no pagination is available.
If we need that, we are going to update this function