This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Vapor | |
import MongoKitten | |
/// A single entry of a Todo list. | |
final class Todo: Content { | |
/// The unique identifier for this `Todo`. | |
var id: ObjectId? | |
/// A title describing what this `Todo` entails. | |
var title: String |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
struct WikipediaEntry { | |
let title: String | |
let summary: String | |
let link: URL? | |
} | |
struct WikipediaSearchResults: Decodable { | |
let term: String |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Vapor | |
import SwiftProtobuf | |
import Foundation | |
extension Request { | |
public func decodeMessage<M: SwiftProtobuf.Message>(_ type: M.Type = M.self) throws -> M { | |
let data = http.body.data ?? Data() | |
if http.contentType == MediaType.json { | |
return try M(jsonUTF8Data: data) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import FluentPostgreSQL | |
import Vapor | |
public func configure(_ config: inout Config, _ env: inout Environment, _ services: inout Services) throws { | |
// (1) Standard PostgreSQL setup | |
try services.register(FluentPostgreSQLProvider()) | |
let pgURL = Environment.get("DATABASE_URL") ?? "postgres://vapor:[email protected]:5432/vapor" | |
let pgConfig = PostgreSQLDatabaseConfig(url: pgURL)! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Vapor | |
import IkigaJSON | |
extension IkigaJSONDecoder: DataDecoder { | |
public func decode<D>(_ decodable: D.Type, from data: LosslessDataConvertible) throws -> D where D : Decodable { | |
return try self.decode(decodable, from: data.convertToData()) | |
} | |
} | |
extension IkigaJSONEncoder: DataEncoder { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import NIO | |
import Vapor | |
final class LongPollManager<T: Encodable> { | |
private var longPolls: [LongPoll<T>] = [] | |
private let queue = DispatchQueue(label: "LongPollManager-\(T.self)-Queue") | |
func add(_ longPoll: LongPoll<T>) { | |
queue.async { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Leaf | |
import Foundation | |
final class JSONTag: TagRenderer { | |
private let encoder = JSONEncoder() | |
func render(tag: TagContext) throws -> EventLoopFuture<TemplateData> { | |
try tag.requireNoBody() | |
try tag.requireParameterCount(1) | |
let json = try encoder.encode(tag.parameters[0]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Service | |
import Foundation | |
import SwiftSMTP | |
struct EmailSenderConfig: Service { | |
let fromEmail: String | |
let fromName: String | |
let smtpHostname: String | |
let smtpPort: Int | |
let smtpEmail: String |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Fluent | |
func fetchChildren<Parent, ParentID, Child: Model, Result>( | |
of parents: [Parent], | |
idKey: KeyPath<Parent, ParentID?>, | |
via reference: KeyPath<Child, ParentID>, | |
on conn: DatabaseConnectable, | |
combining: @escaping (Parent, [Child]) -> Result) -> Future<[Result]> where ParentID: Hashable & Encodable { | |
let parentIDs = parents.compactMap { $0[keyPath: idKey] } | |
let children = Child.query(on: conn) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
struct AppStoreReceiptValidationRequest: Encodable { | |
let receiptData: String | |
let password: String? | |
let excludeOldTransactions: Bool | |
private enum CodingKeys: String, CodingKey { | |
case receiptData = "receipt-data" | |
case password |