mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-09-20 20:55:31 +00:00
Hide trainings requests behind a training controller
This commit is contained in:
@@ -347,6 +347,7 @@
|
|||||||
C8739E181D2BF2DC00A89F3C /* BaseData.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8739E171D2BF2DC00A89F3C /* BaseData.swift */; };
|
C8739E181D2BF2DC00A89F3C /* BaseData.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8739E171D2BF2DC00A89F3C /* BaseData.swift */; };
|
||||||
C8739E1C1D2D5F1700A89F3C /* LocationData.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8739E1B1D2D5F1700A89F3C /* LocationData.swift */; };
|
C8739E1C1D2D5F1700A89F3C /* LocationData.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8739E1B1D2D5F1700A89F3C /* LocationData.swift */; };
|
||||||
C87A74E11F4EE570003DE396 /* TrainingRequestManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = C87A74E01F4EE570003DE396 /* TrainingRequestManager.swift */; };
|
C87A74E11F4EE570003DE396 /* TrainingRequestManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = C87A74E01F4EE570003DE396 /* TrainingRequestManager.swift */; };
|
||||||
|
C87A74E31F4F0E34003DE396 /* TrainingController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C87A74E21F4F0E34003DE396 /* TrainingController.swift */; };
|
||||||
C89C5FC51D06A289002AAAD2 /* GradientView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C89C5FC41D06A289002AAAD2 /* GradientView.swift */; };
|
C89C5FC51D06A289002AAAD2 /* GradientView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C89C5FC41D06A289002AAAD2 /* GradientView.swift */; };
|
||||||
C89C5FCA1D06CECD002AAAD2 /* TrackingViewStatusCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = C89C5FC91D06CECD002AAAD2 /* TrackingViewStatusCell.swift */; };
|
C89C5FCA1D06CECD002AAAD2 /* TrackingViewStatusCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = C89C5FC91D06CECD002AAAD2 /* TrackingViewStatusCell.swift */; };
|
||||||
C89C5FCC1D06CF0C002AAAD2 /* TrackingViewGPSAccuracyCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = C89C5FCB1D06CF0C002AAAD2 /* TrackingViewGPSAccuracyCell.swift */; };
|
C89C5FCC1D06CF0C002AAAD2 /* TrackingViewGPSAccuracyCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = C89C5FCB1D06CF0C002AAAD2 /* TrackingViewGPSAccuracyCell.swift */; };
|
||||||
@@ -748,6 +749,7 @@
|
|||||||
C8739E171D2BF2DC00A89F3C /* BaseData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BaseData.swift; sourceTree = "<group>"; };
|
C8739E171D2BF2DC00A89F3C /* BaseData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BaseData.swift; sourceTree = "<group>"; };
|
||||||
C8739E1B1D2D5F1700A89F3C /* LocationData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LocationData.swift; sourceTree = "<group>"; };
|
C8739E1B1D2D5F1700A89F3C /* LocationData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LocationData.swift; sourceTree = "<group>"; };
|
||||||
C87A74E01F4EE570003DE396 /* TrainingRequestManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TrainingRequestManager.swift; sourceTree = "<group>"; };
|
C87A74E01F4EE570003DE396 /* TrainingRequestManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TrainingRequestManager.swift; sourceTree = "<group>"; };
|
||||||
|
C87A74E21F4F0E34003DE396 /* TrainingController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TrainingController.swift; sourceTree = "<group>"; };
|
||||||
C89C5FC41D06A289002AAAD2 /* GradientView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GradientView.swift; sourceTree = "<group>"; };
|
C89C5FC41D06A289002AAAD2 /* GradientView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GradientView.swift; sourceTree = "<group>"; };
|
||||||
C89C5FC91D06CECD002AAAD2 /* TrackingViewStatusCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TrackingViewStatusCell.swift; sourceTree = "<group>"; };
|
C89C5FC91D06CECD002AAAD2 /* TrackingViewStatusCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TrackingViewStatusCell.swift; sourceTree = "<group>"; };
|
||||||
C89C5FCB1D06CF0C002AAAD2 /* TrackingViewGPSAccuracyCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TrackingViewGPSAccuracyCell.swift; sourceTree = "<group>"; };
|
C89C5FCB1D06CF0C002AAAD2 /* TrackingViewGPSAccuracyCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TrackingViewGPSAccuracyCell.swift; sourceTree = "<group>"; };
|
||||||
@@ -903,6 +905,7 @@
|
|||||||
C8739E0E1D2BEE7900A89F3C /* SessionController.swift */,
|
C8739E0E1D2BEE7900A89F3C /* SessionController.swift */,
|
||||||
C8739E101D2BF13200A89F3C /* Data */,
|
C8739E101D2BF13200A89F3C /* Data */,
|
||||||
C85DB82D1F31D804009559CE /* SignUpController.swift */,
|
C85DB82D1F31D804009559CE /* SignUpController.swift */,
|
||||||
|
C87A74E21F4F0E34003DE396 /* TrainingController.swift */,
|
||||||
);
|
);
|
||||||
name = DataController;
|
name = DataController;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@@ -1989,6 +1992,7 @@
|
|||||||
C843D4831EBC54A300250F01 /* CheckIn+CoreDataProperties.swift in Sources */,
|
C843D4831EBC54A300250F01 /* CheckIn+CoreDataProperties.swift in Sources */,
|
||||||
C8F71EEC1D8691F700826DE4 /* UIButton+AFNetworking.m in Sources */,
|
C8F71EEC1D8691F700826DE4 /* UIButton+AFNetworking.m in Sources */,
|
||||||
C867BD0B1F4B0290007E78E0 /* CreateTrainingViewController.swift in Sources */,
|
C867BD0B1F4B0290007E78E0 /* CreateTrainingViewController.swift in Sources */,
|
||||||
|
C87A74E31F4F0E34003DE396 /* TrainingController.swift in Sources */,
|
||||||
C8F1B1E11D488B6D004C3379 /* Translation.swift in Sources */,
|
C8F1B1E11D488B6D004C3379 /* Translation.swift in Sources */,
|
||||||
C8F71EE81D8691F700826DE4 /* TSMarkdownParser.m in Sources */,
|
C8F71EE81D8691F700826DE4 /* TSMarkdownParser.m in Sources */,
|
||||||
C8739E061D2AA2A500A89F3C /* GPSFix+CoreDataProperties.swift in Sources */,
|
C8739E061D2AA2A500A89F3C /* GPSFix+CoreDataProperties.swift in Sources */,
|
||||||
|
|||||||
@@ -35,22 +35,22 @@ class SignUpController: NSObject {
|
|||||||
|
|
||||||
weak var delegate: SignUpControllerDelegate?
|
weak var delegate: SignUpControllerDelegate?
|
||||||
|
|
||||||
fileprivate let requestManager = SignUpRequestManager(baseURLString: "https://ubilabstest.sapsailing.com")
|
fileprivate let requestManager: SignUpRequestManager
|
||||||
|
|
||||||
|
init(baseURLString: String) {
|
||||||
|
requestManager = SignUpRequestManager(baseURLString: baseURLString)
|
||||||
|
super.init()
|
||||||
|
}
|
||||||
|
|
||||||
func loginWithViewController(_ controller: UIViewController) {
|
func loginWithViewController(_ controller: UIViewController) {
|
||||||
requestManager.postHello(success: { (principal, authenticated, remembered) in
|
requestManager.postHello(success: { (principal, authenticated, remembered) in
|
||||||
|
// Login success
|
||||||
// Test create event
|
|
||||||
let trainingRequestManager = TrainingRequestManager(baseURLString: self.requestManager.baseURLString)
|
|
||||||
trainingRequestManager.postCreateEvent(success: {
|
|
||||||
}, failure: { (error, message) in
|
|
||||||
})
|
|
||||||
|
|
||||||
}) { (error, message) in
|
}) { (error, message) in
|
||||||
do {
|
do {
|
||||||
let userName = try Keychain.userName.readPassword()
|
let userName = try Keychain.userName.readPassword()
|
||||||
let password = try Keychain.userPassword.readPassword()
|
let password = try Keychain.userPassword.readPassword()
|
||||||
self.requestManager.postAccessToken(userName: userName, password: password, success: { (userName, accessToken) in
|
self.requestManager.postAccessToken(userName: userName, password: password, success: { (userName, accessToken) in
|
||||||
|
// Login success, save access token
|
||||||
do {
|
do {
|
||||||
try Keychain.userName.savePassword(userName)
|
try Keychain.userName.savePassword(userName)
|
||||||
try Keychain.userAccessToken.savePassword(accessToken)
|
try Keychain.userAccessToken.savePassword(accessToken)
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
//
|
||||||
|
// TrainingController.swift
|
||||||
|
// SAPTracker
|
||||||
|
//
|
||||||
|
// Created by Raimund Wege on 24.08.17.
|
||||||
|
// Copyright © 2017 com.sap.sailing. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
import UIKit
|
||||||
|
|
||||||
|
class TrainingController: NSObject {
|
||||||
|
|
||||||
|
let requestManager: TrainingRequestManager
|
||||||
|
|
||||||
|
init(baseURLString: String) {
|
||||||
|
requestManager = TrainingRequestManager(baseURLString: baseURLString)
|
||||||
|
super.init()
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - CreateEvent
|
||||||
|
|
||||||
|
func createEvent(boatClassName: String) {
|
||||||
|
requestManager.postCreateEvent(boatClassName: boatClassName, success: {
|
||||||
|
|
||||||
|
}, failure: { (error, message) in
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -8,6 +8,12 @@
|
|||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
|
enum TrainingRequestManagerError: Error {
|
||||||
|
case checkInDataIsIncomplete
|
||||||
|
case communicationFailed
|
||||||
|
case postCreateEventFailed
|
||||||
|
}
|
||||||
|
|
||||||
class TrainingRequestManager: NSObject {
|
class TrainingRequestManager: NSObject {
|
||||||
|
|
||||||
fileprivate let basePathString = "/sailingserver/api/v1"
|
fileprivate let basePathString = "/sailingserver/api/v1"
|
||||||
@@ -29,11 +35,11 @@ class TrainingRequestManager: NSObject {
|
|||||||
// MARK: - CreateEvent
|
// MARK: - CreateEvent
|
||||||
|
|
||||||
func postCreateEvent(
|
func postCreateEvent(
|
||||||
|
boatClassName: String,
|
||||||
success: @escaping () -> Void,
|
success: @escaping () -> Void,
|
||||||
failure: @escaping (_ error: Error, _ message: String?) -> Void)
|
failure: @escaping (_ error: Error, _ message: String?) -> Void)
|
||||||
{
|
{
|
||||||
let urlString = "/sailingserver/api/v1/events/createEvent"
|
let urlString = "/sailingserver/api/v1/events/createEvent"
|
||||||
|
|
||||||
var body = [String: AnyObject]()
|
var body = [String: AnyObject]()
|
||||||
// body["eventname"] = "raimund" as AnyObject
|
// body["eventname"] = "raimund" as AnyObject
|
||||||
// body["eventdescription"] = "raimund" as AnyObject
|
// body["eventdescription"] = "raimund" as AnyObject
|
||||||
@@ -50,18 +56,31 @@ class TrainingRequestManager: NSObject {
|
|||||||
// body["leaderboardgroupids"] = "" as AnyObject
|
// body["leaderboardgroupids"] = "" as AnyObject
|
||||||
// body["createleaderboardgroup"] = "" as AnyObject
|
// body["createleaderboardgroup"] = "" as AnyObject
|
||||||
body["createregatta"] = "true" as AnyObject
|
body["createregatta"] = "true" as AnyObject
|
||||||
body["boatclassname"] = "J80" as AnyObject
|
body["boatclassname"] = boatClassName as AnyObject
|
||||||
// body["numberofraces"] = "" as AnyObject
|
// body["numberofraces"] = "" as AnyObject
|
||||||
|
|
||||||
manager.post(urlString, parameters: body, success: { (requestOperation, responseObject) in
|
manager.post(urlString, parameters: body, success: { (requestOperation, responseObject) in
|
||||||
success()
|
self.postCreateEventSuccess(responseObject: responseObject, success: success)
|
||||||
}) { (requestOperation, error) in
|
}) { (requestOperation, error) in
|
||||||
failure(error, self.stringForError(error))
|
self.postCreateEventFailure(error: error, failure: failure)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fileprivate func postCreateEventSuccess(responseObject: Any, success: () -> Void) {
|
||||||
|
logInfo(name: "\(#function)", info: responseObjectToString(responseObject: responseObject))
|
||||||
|
success()
|
||||||
|
}
|
||||||
|
|
||||||
|
fileprivate func postCreateEventFailure(error: Error, failure: (_ error: Error, _ message: String?) -> Void) {
|
||||||
|
logError(name: "\(#function)", error: error)
|
||||||
|
failure(TrainingRequestManagerError.postCreateEventFailed, stringForError(error))
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - Helper
|
// MARK: - Helper
|
||||||
|
|
||||||
|
fileprivate func responseObjectToString(responseObject: Any?) -> String {
|
||||||
|
return (responseObject as? String) ?? "response object is empty or cannot be casted"
|
||||||
|
}
|
||||||
|
|
||||||
fileprivate func stringForError(_ error: Error) -> String? {
|
fileprivate func stringForError(_ error: Error) -> String? {
|
||||||
guard let data = ((error as NSError).userInfo[AFNetworkingOperationFailingURLResponseDataErrorKey] as? NSData) else { return nil }
|
guard let data = ((error as NSError).userInfo[AFNetworkingOperationFailingURLResponseDataErrorKey] as? NSData) else { return nil }
|
||||||
return String(data: data as Data, encoding: String.Encoding.utf8)
|
return String(data: data as Data, encoding: String.Encoding.utf8)
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ class TrainingTableViewController: UIViewController {
|
|||||||
// MARK: - Properties
|
// MARK: - Properties
|
||||||
|
|
||||||
fileprivate lazy var signUpController: SignUpController = {
|
fileprivate lazy var signUpController: SignUpController = {
|
||||||
let signUpController = SignUpController()
|
let signUpController = SignUpController(baseURLString: "https://ubilabstest.sapsailing.com")
|
||||||
signUpController.delegate = self
|
signUpController.delegate = self
|
||||||
return signUpController
|
return signUpController
|
||||||
}()
|
}()
|
||||||
|
|||||||
Reference in New Issue
Block a user