ReadOne
public final class ReadOne<T> : ReadEndpoint where T : CorvusModel
A class that provides functionality to read objects of a generic type
T
conforming to CorvusModel
and identified by a route parameter.
-
The return type of the
.handler()
.Declaration
Swift
public typealias QuerySubject = T
-
Represents the type of
CorvusModel
to be read.Declaration
Swift
public let target: ReadTarget<QuerySubject>
-
The default
operationType
is GET.Declaration
Swift
public var operationType: OperationType { get }
-
Initializes the component with a given path parameter.
Declaration
Swift
public init( _ id: PathComponent, _ target: ReadTarget<QuerySubject> = .existing)
Parameters
id
A
PathComponent
which represents the ID of the itemtarget
A
ReadTarget
which controls where to query the item from that is to be deleted. -
A method to find an item by an ID supplied in the
Request
.Throws
AnAbort
error if the item is not found.Declaration
Swift
public func query(_ req: Request) throws -> QueryBuilder<QuerySubject>
Parameters
req
An incoming
Request
.Return Value
A
QueryBuilder
, which represents aFluent
query after having found the object with the supplied ID. -
A method to return an object found in the
.query()
from the database, depending on thetarget
.Throws
AnAbort
error if the item is not found.Declaration
Swift
public func handler(_ req: Request) throws -> EventLoopFuture<QuerySubject>
Parameters
req
An incoming
Request
.Return Value
The found object.