Skip to content

Commit 550ea96

Browse files
committed
working server
1 parent 175b457 commit 550ea96

File tree

14 files changed

+611
-21
lines changed

14 files changed

+611
-21
lines changed

Package.resolved

Lines changed: 203 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,18 @@ let package = Package(
88
],
99
dependencies: [
1010
// 💧 A server-side Swift web framework.
11-
.package(url: "https://github.com/vapor/vapor.git", from: "4.0.0"),
12-
.package(url: "https://github.com/vapor/leaf.git", from: "4.0.0"),
11+
.package(url: "https://github.com/vapor/vapor.git", .upToNextMajor(from: "4.62.0")),
12+
.package(url: "https://github.com/vapor/leaf.git", .upToNextMajor(from: "4.2.0")),
13+
.package(url: "https://github.com/parse-community/Parse-Swift.git",
14+
.upToNextMajor(from: "4.6.0"))
1315
],
1416
targets: [
1517
.target(
1618
name: "App",
1719
dependencies: [
1820
.product(name: "Leaf", package: "leaf"),
19-
.product(name: "Vapor", package: "vapor")
21+
.product(name: "Vapor", package: "vapor"),
22+
.product(name: "ParseSwift", package: "Parse-Swift")
2023
],
2124
swiftSettings: [
2225
// Enable better optimizations when building in Release configuration. Despite the use of
Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
//
2-
// File.swift
2+
// Parse+Vapor.swift
33
//
44
//
5-
// Created by Corey Baker on 6/20/22.
5+
// Created by Corey E. Baker on 6/20/22.
66
//
77

8-
import Foundation
8+
import Vapor
9+
import ParseSwift
10+
11+
extension ParseHookFunctionRequest: Content {}
12+
extension ParseHookTriggerRequest: Content {}
13+
extension ParseHookResponse: Content {}
14+
extension ParseFile: Content {}

Sources/App/Models/GameScore.swift

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,35 @@
11
//
2-
// File.swift
2+
// GameScore.swift
33
//
44
//
5-
// Created by Corey Baker on 6/21/22.
5+
// Created by Corey E. Baker on 6/21/22.
66
//
77

88
import Foundation
9+
import ParseSwift
10+
11+
/**
12+
An example `ParseObject`. This is for testing. You can
13+
remove when creating your application.
14+
*/
15+
struct GameScore: ParseObject {
16+
// These are required by ParseObject.
17+
var objectId: String?
18+
var createdAt: Date?
19+
var updatedAt: Date?
20+
var ACL: ParseACL?
21+
var originalData: Data?
22+
23+
// Your own properties.
24+
var points: Int?
25+
26+
// Implement your own version of merge.
27+
func merge(with object: Self) throws -> Self {
28+
var updated = try mergeParse(with: object)
29+
if updated.shouldRestoreKey(\.points,
30+
original: object) {
31+
updated.points = object.points
32+
}
33+
return updated
34+
}
35+
}

Sources/App/Models/HookFunction.swift

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
//
2-
// File.swift
2+
// HookFunction.swift
33
//
44
//
55
// Created by Corey Baker on 6/23/22.
66
//
77

88
import Foundation
99
import ParseSwift
10+
import Vapor
1011

1112
/**
1213
Parse Hook Functions can be created by conforming to
@@ -16,3 +17,61 @@ struct HookFunction: ParseHookFunctionable {
1617
var functionName: String?
1718
var url: URL?
1819
}
20+
21+
// MARK: RoutesBuilder
22+
extension RoutesBuilder {
23+
@discardableResult
24+
public func post<Response>(
25+
_ path: PathComponent...,
26+
name: String,
27+
use closure: @escaping (Request) async throws -> Response
28+
) -> Route
29+
where Response: AsyncResponseEncodable
30+
{
31+
do {
32+
let url = try buildServerPathname(path)
33+
let hookFunction = HookFunction(name: name,
34+
url: url)
35+
Task {
36+
do {
37+
_ = try await hookFunction.create()
38+
} catch {
39+
if !error.equalsTo(.invalidImageData) {
40+
print("Could not create \"\(hookFunction)\" function: \(error)")
41+
}
42+
}
43+
}
44+
} catch {
45+
print(error)
46+
}
47+
return self.post(path, use: closure)
48+
}
49+
50+
@discardableResult
51+
public func post<Response>(
52+
_ path: [PathComponent],
53+
name: String,
54+
triggerName: ParseHookTriggerType,
55+
use closure: @escaping (Request) async throws -> Response
56+
) -> Route
57+
where Response: AsyncResponseEncodable
58+
{
59+
do {
60+
let url = try buildServerPathname(path)
61+
let hookFunction = HookFunction(name: name,
62+
url: url)
63+
Task {
64+
do {
65+
_ = try await hookFunction.create()
66+
} catch {
67+
if !error.equalsTo(.invalidImageData) {
68+
print("Could not create \"\(hookFunction)\" function: \(error)")
69+
}
70+
}
71+
}
72+
} catch {
73+
print(error)
74+
}
75+
return self.post(path, use: closure)
76+
}
77+
}

0 commit comments

Comments
 (0)