mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-09-19 20:25:31 +00:00
Added create event request
This commit is contained in:
@@ -35,26 +35,44 @@ class SignUpController: NSObject {
|
||||
|
||||
weak var delegate: SignUpControllerDelegate?
|
||||
|
||||
fileprivate let requestManager = SignUpRequestManager(baseURLString: "https://dev.sapsailing.com")
|
||||
fileprivate let requestManager = SignUpRequestManager(baseURLString: "https://ubilabstest.sapsailing.com")
|
||||
|
||||
func loginWithViewController(_ controller: UIViewController) {
|
||||
do {
|
||||
let userName = try Keychain.userName.readPassword()
|
||||
let password = try Keychain.userPassword.readPassword()
|
||||
requestManager.postHello(userName: userName, password: password, success: { (principal, authenticated, remembered) in
|
||||
|
||||
}) { (error, message) in
|
||||
|
||||
requestManager.postHello(success: { (principal, authenticated, remembered) in
|
||||
|
||||
// Test create event
|
||||
self.requestManager.postCreateEvent(success: {
|
||||
}, failure: { (error, message) in
|
||||
})
|
||||
|
||||
}) { (error, message) in
|
||||
do {
|
||||
let userName = try Keychain.userName.readPassword()
|
||||
let password = try Keychain.userPassword.readPassword()
|
||||
self.requestManager.postAccessToken(userName: userName, password: password, success: { (userName, accessToken) in
|
||||
do {
|
||||
try Keychain.userName.savePassword(userName)
|
||||
try Keychain.userAccessToken.savePassword(accessToken)
|
||||
} catch {
|
||||
self.showAlert(forError: error, andMessage: message, withViewController: controller)
|
||||
}
|
||||
}, failure: { (error, message) in
|
||||
self.loginWithViewControllerFailure(controller)
|
||||
})
|
||||
} catch {
|
||||
self.loginWithViewControllerFailure(controller)
|
||||
}
|
||||
} catch {
|
||||
let storyboard = UIStoryboard(name: "SignUp", bundle: nil)
|
||||
let loginNC = storyboard.instantiateInitialViewController() as! UINavigationController
|
||||
let loginVC = loginNC.viewControllers[0] as! LoginViewController
|
||||
loginVC.signUpController = self
|
||||
controller.present(loginNC, animated: true, completion: nil)
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate func loginWithViewControllerFailure(_ controller: UIViewController) {
|
||||
let storyboard = UIStoryboard(name: "SignUp", bundle: nil)
|
||||
let loginNC = storyboard.instantiateInitialViewController() as! UINavigationController
|
||||
let loginVC = loginNC.viewControllers[0] as! LoginViewController
|
||||
loginVC.signUpController = self
|
||||
controller.present(loginNC, animated: true, completion: nil)
|
||||
}
|
||||
|
||||
func logoutWithViewController(_ controller: UIViewController) {
|
||||
do {
|
||||
try Keychain.userName.deleteItem()
|
||||
|
||||
@@ -97,6 +97,56 @@ class SignUpRequestManager: NSObject {
|
||||
failure(error, stringForError(error))
|
||||
}
|
||||
|
||||
// MARK: - CreateEvent
|
||||
|
||||
func postCreateEvent(
|
||||
success: @escaping () -> Void,
|
||||
failure: @escaping (_ error: Error, _ message: String?) -> Void)
|
||||
{
|
||||
let urlString = "/sailingserver/api/v1/events/createEvent"
|
||||
|
||||
var body = [String: AnyObject]()
|
||||
// body["eventname"] = "raimund" as AnyObject
|
||||
// body["eventdescription"] = "raimund" as AnyObject
|
||||
// body["startdate"] = "" as AnyObject
|
||||
// body["startdateasmillis"] = "" as AnyObject
|
||||
// body["enddate"] = "" as AnyObject
|
||||
// body["enddateasmillis"] = "" as AnyObject
|
||||
body["venuename"] = "hamburg" as AnyObject
|
||||
// body["venuelat"] = "" as AnyObject
|
||||
// body["venuelng"] = "" as AnyObject
|
||||
// body["ispublic"] = "" as AnyObject
|
||||
// body["officialwebsiteurl"] = "" as AnyObject
|
||||
// body["baseurl"] = "" as AnyObject
|
||||
// body["leaderboardgroupids"] = "" as AnyObject
|
||||
// body["createleaderboardgroup"] = "" as AnyObject
|
||||
body["createregatta"] = "true" as AnyObject
|
||||
body["boatclassname"] = "J80" as AnyObject
|
||||
// body["numberofraces"] = "" as AnyObject
|
||||
|
||||
manager.requestSerializer = AFHTTPRequestSerializer()
|
||||
manager.responseSerializer = AFHTTPResponseSerializer()
|
||||
|
||||
do {
|
||||
let accessToken = try Keychain.userAccessToken.readPassword()
|
||||
manager.requestSerializer.setValue("Bearer \(accessToken)", forHTTPHeaderField: "Authorization")
|
||||
} catch {
|
||||
|
||||
}
|
||||
|
||||
manager.post(urlString, parameters: body, success: { (requestOperation, responseObject) in
|
||||
debugPrint("\(responseObject)")
|
||||
success()
|
||||
}) { (requestOperation, error) in
|
||||
if let request = requestOperation?.request {
|
||||
debugPrint(request)
|
||||
}
|
||||
debugPrint(requestOperation)
|
||||
debugPrint(self.stringForError(error))
|
||||
failure(error, self.stringForError(error))
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - CreateUser
|
||||
|
||||
func postCreateUser(
|
||||
@@ -201,13 +251,10 @@ class SignUpRequestManager: NSObject {
|
||||
// MARK: - Hello
|
||||
|
||||
func postHello(
|
||||
userName: String,
|
||||
password: String,
|
||||
success: @escaping (_ principal: String, _ authenticated: Bool, _ remembered: Bool) -> Void,
|
||||
failure: @escaping (_ error: Error, _ message: String?) -> Void)
|
||||
{
|
||||
let urlString = "\(basePathString)/hello"
|
||||
manager.requestSerializer.setAuthorizationHeaderFieldWithUsername(userName, password: password)
|
||||
manager.post(urlString, parameters: nil, success: { (requestOperation, responseObject) in
|
||||
self.postHelloSuccess(responseObject: responseObject, success: success, failure: failure)
|
||||
}) { (requestOperation, error) in
|
||||
|
||||
Reference in New Issue
Block a user