This repository has been archived by the owner on Jul 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from Slugbotics/tebert/pending-invites
Tebert/pending invites
- Loading branch information
Showing
14 changed files
with
765 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// InviteRecord.swift | ||
// Sluggo | ||
// | ||
// Created by Troy Ebert on 5/31/21. | ||
// | ||
|
||
import Foundation | ||
import NullCodable | ||
|
||
// swiftlint:disable identifier_name | ||
struct UserInviteRecord: Codable { | ||
var id: Int | ||
var team: TeamRecord | ||
} | ||
|
||
struct TeamInviteRecord: Codable { | ||
var id: Int | ||
var user_email: String | ||
var team: TeamRecord | ||
} | ||
|
||
struct WriteTeamInviteRecord: Codable { | ||
var user_email: String | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// | ||
// InviteManager.swift | ||
// Sluggo | ||
// | ||
// Created by Troy on 5/31/21. | ||
// | ||
|
||
import Foundation | ||
|
||
// MARK: User Invite Manager | ||
class InviteManager { | ||
|
||
static let urlBase = "api/users/invites/" | ||
private var identity: AppIdentity | ||
|
||
init(identity: AppIdentity) { | ||
self.identity = identity | ||
} | ||
|
||
func getUserInvites(completionHandler: @escaping (Result<[UserInviteRecord], Error>) -> Void) { | ||
|
||
let urlString = identity.baseAddress + InviteManager.urlBase | ||
let requestBuilder = URLRequestBuilder(url: URL(string: urlString)!) | ||
.setIdentity(identity: identity) | ||
.setMethod(method: .GET) | ||
|
||
JsonLoader.executeCodableRequest(request: requestBuilder.getRequest(), completionHandler: completionHandler) | ||
} | ||
|
||
public func acceptUserInvite(invite: UserInviteRecord, completionHandler: @escaping(Result<Void, Error>) -> Void) { | ||
|
||
let urlString = identity.baseAddress + InviteManager.urlBase + "\(invite.id)/" | ||
let requestBuilder = URLRequestBuilder(url: URL(string: urlString)!) | ||
.setMethod(method: .PUT) | ||
.setIdentity(identity: self.identity) | ||
|
||
JsonLoader.executeEmptyRequest(request: requestBuilder.getRequest(), completionHandler: completionHandler) | ||
|
||
} | ||
|
||
public func rejectUserInvite(invite: UserInviteRecord, completionHandler: @escaping(Result<Void, Error>) -> Void) { | ||
|
||
let urlString = identity.baseAddress + InviteManager.urlBase + "\(invite.id)/" | ||
let requestBuilder = URLRequestBuilder(url: URL(string: urlString)!) | ||
.setMethod(method: .DELETE) | ||
.setIdentity(identity: self.identity) | ||
|
||
JsonLoader.executeEmptyRequest(request: requestBuilder.getRequest(), completionHandler: completionHandler) | ||
|
||
} | ||
} | ||
|
||
// MARK: Team Invite Manager | ||
class TeamInviteManager: TeamPaginatedListable { | ||
|
||
static let urlBase = "api/users/invites/" | ||
private var identity: AppIdentity | ||
|
||
init(identity: AppIdentity) { | ||
self.identity = identity | ||
} | ||
|
||
func listFromTeams(page: Int, completionHandler: @escaping | ||
(Result<PaginatedList<TeamInviteRecord>, Error>) -> Void) { | ||
|
||
let urlString = identity.baseAddress + TeamManager.urlBase + "\(identity.team!.id)/" + "invites/" | ||
let requestBuilder = URLRequestBuilder(url: URL(string: urlString)!) | ||
.setIdentity(identity: identity) | ||
.setMethod(method: .GET) | ||
|
||
JsonLoader.executeCodableRequest(request: requestBuilder.getRequest(), completionHandler: completionHandler) | ||
} | ||
|
||
func addTeamInvite(invite: WriteTeamInviteRecord, completionHandler: @escaping(Result<Void, Error>) -> Void) { | ||
|
||
let urlString = identity.baseAddress + TeamManager.urlBase + "\(identity.team!.id)/" + "invites/" | ||
|
||
guard let body = JsonLoader.encode(object: invite) else { | ||
let errorMessage = "Failed to serialize ticket JSON for addTeamInvite in InviteManager" | ||
completionHandler(.failure(Exception.runtimeError(message: errorMessage))) | ||
return | ||
} | ||
|
||
let requestBuilder = URLRequestBuilder(url: URL(string: urlString)!) | ||
.setIdentity(identity: identity) | ||
.setData(data: body) | ||
.setMethod(method: .POST) | ||
|
||
JsonLoader.executeEmptyRequest(request: requestBuilder.getRequest(), completionHandler: completionHandler) | ||
} | ||
|
||
func deleteTeamInvite(invite: TeamInviteRecord, completionHandler: @escaping(Result<Void, Error>) -> Void) { | ||
|
||
let urlString = identity.baseAddress + TeamManager.urlBase + | ||
"\(identity.team!.id)/" + "invites/" + "\(invite.id)/" | ||
let requestBuilder = URLRequestBuilder(url: URL(string: urlString)!) | ||
.setIdentity(identity: identity) | ||
.setMethod(method: .DELETE) | ||
|
||
JsonLoader.executeEmptyRequest(request: requestBuilder.getRequest(), completionHandler: completionHandler) | ||
} | ||
} |
Oops, something went wrong.