ObjectId.parser() instand -> UUID.parser()
addame2 opened this issue · 1 comments
addame2 commented
ObjectId is from mongo db
public let wordsRouter = OneOf {
Route(.case(WordsRoute.words)) {
Path { "words2" }
}
Route(.case(WordsRoute.word)) {
Path { "words2" }
Path { Parse(.string) } // this how do it parse this like UUID.parser() *
wordRouter
}
}
func wordHandher(
request: Request,
wordID: String,
route: WordRoute
) async throws -> AsyncResponseEncodable {
switch route {
case .fetch:
guard let id = ObjectId.init(wordID) // * so I can remove this line
else {
struct BadObjectId: Error {}
throw BadObjectId()
}
return WordResponse(_id: id, englishWord: "english Word", englishDefinition: "English Definition", isReadFromNotification: false, isReadFromView: false, level: .beginner, url: router.url(for: .words(.word(id.hexString, .fetch))))
}
stephencelis commented
Hi @addame2, because this is not a bug and more of a feature request or question about usage, I'm going to convert it to a discussion.
Can you provide examples or links to the exact format you want to parse, and the exact data type you want to parse to? For example, what MongoDB library are you using? With that info, folks can try to help you cook up an appropriate parser.