Skip to content

Commit 8110f65

Browse files
committed
Created Assets & improved Chapter 16
1 parent df2e4ad commit 8110f65

File tree

15 files changed

+22
-35
lines changed

15 files changed

+22
-35
lines changed

Assets/01.jpg

561 KB
Loading

Assets/02.jpg

547 KB
Loading

Assets/03.jpg

831 KB
Loading

Assets/04.jpg

798 KB
Loading

Assets/05.jpg

761 KB
Loading

Chapter 16/MyProjectClient/iOS/Sources/AppDelegate.swift

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ extension AppDelegate: UIApplicationDelegate {
2929
return .init(name: "Default Configuration",
3030
sessionRole: connectingSceneSession.role)
3131
}
32+
//...
3233

3334
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
3435
let token = deviceToken.map { String(format: "%02.2hhx", $0) }.joined()

Chapter 16/MyProjectClient/iOS/Sources/Modules/Account/AccountInteractor.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ extension AccountInteractor: AccountInteractorPresenterInterface {
2121
.mapError { $0 as Error }
2222
.eraseToAnyPublisher()
2323
}
24-
24+
//...
2525
func register(deviceToken: String, bearerToken: String) -> AnyPublisher<Void, Error> {
2626
self.services.api.register(deviceToken: deviceToken, bearerToken: bearerToken)
2727
.mapError { $0 as Error }

Chapter 16/MyProjectClient/iOS/Sources/Modules/Account/AccountPresenter.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ extension AccountPresenter: AccountPresenterViewInterface {
6464
UserDefaults.standard.synchronize()
6565
self.view.displayLogin()
6666
}
67-
67+
//...
6868
func registerUserDevice(_ block: @escaping (() -> Void)) {
6969
guard
7070
let bearerToken = UserDefaults.standard.string(forKey: "user-token"),

Chapter 16/MyProjectClient/iOS/Sources/Services/Api/MyProject/MyProjectApiService.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ final class MyProjectApiService: ApiServiceInterface {
8080
}
8181
.eraseToAnyPublisher()
8282
}
83-
83+
//...
8484
func register(deviceToken: String, bearerToken: String) -> AnyPublisher<Void, HTTP.Error> {
8585
struct Body: Codable {
8686
let token: String

Chapter 16/myProject/Sources/App/Extensions/Environment+App.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ extension Environment {
1818
static let siwaTeamId = Self.get("SIWA_TEAM_ID")!
1919
static let siwaJWKId = Self.get("SIWA_JWK_ID")!
2020
static let siwaKey = Self.get("SIWA_KEY")!.base64Decoded()!
21-
//...
21+
2222
static let apnsKeyId = Self.get("APNS_KEY_ID")!
2323
static let apnsTeamId = Self.get("APNS_TEAM_ID")!
2424
static let apnsTopic = Self.get("APNS_TOPIC")!

Chapter 16/myProject/Sources/App/Modules/User/Controllers/UserAdminController.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ struct UserAdminController {
2525
userId: userId,
2626
status: status,
2727
users: $0)
28-
return req.view.render("User/Frontend/Push", context)
28+
return req.view.render("User/Admin/Push", context)
2929
}
3030
}
3131

3232
func pushView(req: Request) throws -> EventLoopFuture<View> {
3333
self.renderPushView(req)
3434
}
35-
35+
3636
func push(req: Request) throws -> EventLoopFuture<View> {
3737
struct Input: Decodable {
3838
let title: String

Chapter 16/myProject/Sources/App/Modules/User/Controllers/UserApiController.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ struct UserApiController {
2424
UserTokenModel.create(on: req.db, for: user.id!).map { $0.getContent }
2525
}
2626
}
27-
27+
//...
2828
func registerDevice(req: Request) throws -> EventLoopFuture<HTTPStatus> {
2929
guard let user = req.auth.get(UserModel.self) else {
3030
throw Abort(.unauthorized)

Chapter 16/myProject/Sources/App/Modules/User/UserRouter.swift

+13-20
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,26 @@ struct UserRouter: ViperRouter {
99

1010
func boot(routes: RoutesBuilder, app: Application) throws {
1111
routes.get("sign-in", use: self.frontendController.loginView)
12-
13-
routes.grouped(UserModelCredentialsAuthenticator())
14-
.post("sign-in", use: self.frontendController.login)
15-
16-
routes.grouped(UserModelSessionAuthenticator())
17-
.get("logout", use: self.frontendController.logout)
18-
19-
let publicApi = routes.grouped("api", "user")
20-
let privateApi = publicApi.grouped([
21-
UserTokenModel.authenticator(),
22-
UserModel.guardMiddleware(),
23-
])
24-
25-
publicApi.grouped(UserModelCredentialsAuthenticator())
26-
.post("login", use: self.apiController.login)
27-
28-
//...
12+
routes.grouped(UserModelCredentialsAuthenticator()).post("sign-in", use: self.frontendController.login)
13+
routes.grouped(UserModelSessionAuthenticator()).get("logout", use: self.frontendController.logout)
2914
routes.post("redirect", use: self.frontendController.signInWithApple)
30-
publicApi.post("sign-in-with-apple", use: self.apiController.signInWithApple)
31-
privateApi.post("devices", use: self.apiController.registerDevice)
32-
15+
3316
let protected = routes.grouped([
3417
UserModelSessionAuthenticator(),
3518
UserModel.redirectMiddleware(path: "/")
3619
])
3720
let user = protected.grouped("admin", "user")
3821
user.get("push", use: self.adminController.pushView)
3922
user.post("push", use: self.adminController.push)
23+
24+
let publicApi = routes.grouped("api", "user")
25+
let privateApi = publicApi.grouped([
26+
UserTokenModel.authenticator(),
27+
UserModel.guardMiddleware(),
28+
])
29+
30+
publicApi.grouped(UserModelCredentialsAuthenticator()).post("login", use: self.apiController.login)
31+
publicApi.post("sign-in-with-apple", use: self.apiController.signInWithApple)
32+
privateApi.post("devices", use: self.apiController.registerDevice)
4033
}
4134
}

Chapter 16/myProject/Sources/App/Modules/User/Views/Frontend/Push.leaf renamed to Chapter 16/myProject/Sources/App/Modules/User/Views/Admin/Push.leaf

-7
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,15 @@
44
<h2>Push notification</h2>
55
</div>
66

7-
8-
97
<form id="push-form" class="wrapper" method="post" action="/admin/user/push" enctype="multipart/form-data">
10-
118
<section>
129
<label for="title">Title</label>
1310
<input id="title" type="text" name="title" value="#(title)" class="field">
1411
</section>
15-
1612
<section>
1713
<label for="message">Message</label>
1814
<input id="message" type="text" name="message" value="#(message)" class="field">
1915
</section>
20-
2116
<section>
2217
<label for="userId">User</label>
2318
<select name="userId">
@@ -34,8 +29,6 @@
3429
<section>
3530
#(status)
3631
</section>
37-
3832
</form>
39-
4033
#endexport
4134
#endextend

Chapter 16/myProject/Sources/App/configure.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public func configure(_ app: Application) throws {
1818
teamIdentifier: Environment.apnsTeamId
1919
),
2020
topic: Environment.apnsTopic,
21-
environment: .sandbox
21+
environment: .production
2222
)
2323

2424
let configuration = PostgresConfiguration(

0 commit comments

Comments
 (0)