-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathShiftDetailInteractor.swift
52 lines (47 loc) · 1.23 KB
/
ShiftDetailInteractor.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//
// ShiftDetailInteractor.swift
// Where2Help
//
// Created by Aaron Cruz on 4/8/16.
// Copyright © 2016 Where2Help. All rights reserved.
//
import Foundation
class ShiftDetailInteractor {
var handler: ShiftHandler!
var shift: Shift!
var event: Event!
func setup(handler: ShiftHandler, event: Event, shift: Shift) {
self.handler = handler
self.shift = shift
self.event = event
loadShift()
}
func toggleOptIn() {
if let user = UserManager.currentUser {
if shift.currentUserAssigned.boolValue {
APIClient.optOut(user, shift: self.shift, success: { (json) in
self.shift.currentUserAssigned = false
self.loadShift()
}) { (message) in
print("No good")
}
}
else {
APIClient.optIn(user, shift: self.shift, success: { (json) in
self.shift.currentUserAssigned = true
self.loadShift()
}) { (message) in
print("No good")
}
}
}
}
private func loadShift() {
let ePres = EventPresenter(event: event)
let sPres = ShiftPresenter(shift: shift)
handler.handleNewEvent(ePres)
handler.handleNewShift(sPres)
let geo = EventGeo(event: event)
handler.handleGeo(geo)
}
}