Skip to content
This repository has been archived by the owner on Jul 25, 2022. It is now read-only.

Commit

Permalink
Merge pull request #37 from Slugbotics/tebert/pending-invites
Browse files Browse the repository at this point in the history
Tebert/pending invites
  • Loading branch information
agavgavi authored Jun 2, 2021
2 parents 88cca58 + d333ac7 commit 784bd71
Show file tree
Hide file tree
Showing 14 changed files with 765 additions and 84 deletions.
24 changes: 24 additions & 0 deletions Sluggo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@
/* Begin PBXBuildFile section */
051AAB0B2630FD6500BCB9C7 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 051AAB0A2630FD6500BCB9C7 /* Constants.swift */; };
052258702636100B00B49CE4 /* LaunchViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0522586F2636100B00B49CE4 /* LaunchViewController.swift */; };
053A259F26645DDD0072A773 /* PendingInvitesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 053A259E26645DDD0072A773 /* PendingInvitesViewController.swift */; };
0541572326655FBA002A85F2 /* InviteManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0541572226655FBA002A85F2 /* InviteManager.swift */; };
0541572826659F2E002A85F2 /* InviteRecord.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0541572726659F2E002A85F2 /* InviteRecord.swift */; };
0541572D2665BD29002A85F2 /* AdminInviteViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0541572C2665BD29002A85F2 /* AdminInviteViewController.swift */; };
05588A12264DB61E000D8674 /* TeamMembers.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 05588A11264DB61E000D8674 /* TeamMembers.storyboard */; };
05D3BA1A2666B9F8008AE9D8 /* AdminInvite.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 05D3BA192666B9F8008AE9D8 /* AdminInvite.storyboard */; };
05D3BA272666DA3D008AE9D8 /* PendingInvites.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 05D3BA262666DA3D008AE9D8 /* PendingInvites.storyboard */; };
05DE0CD7264F11E400D69C61 /* MemberListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05DE0CD6264F11E400D69C61 /* MemberListViewController.swift */; };
2F2247AC262920AC006C6EE6 /* TokenRecord.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F2247AB262920AC006C6EE6 /* TokenRecord.swift */; };
2F3AD7A32627C86A00B61A97 /* UserRecord.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F3AD7A22627C86A00B61A97 /* UserRecord.swift */; };
Expand Down Expand Up @@ -101,7 +107,13 @@
/* Begin PBXFileReference section */
051AAB0A2630FD6500BCB9C7 /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
0522586F2636100B00B49CE4 /* LaunchViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LaunchViewController.swift; sourceTree = "<group>"; };
053A259E26645DDD0072A773 /* PendingInvitesViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PendingInvitesViewController.swift; sourceTree = "<group>"; };
0541572226655FBA002A85F2 /* InviteManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InviteManager.swift; sourceTree = "<group>"; };
0541572726659F2E002A85F2 /* InviteRecord.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InviteRecord.swift; sourceTree = "<group>"; };
0541572C2665BD29002A85F2 /* AdminInviteViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdminInviteViewController.swift; sourceTree = "<group>"; };
05588A11264DB61E000D8674 /* TeamMembers.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = TeamMembers.storyboard; sourceTree = "<group>"; };
05D3BA192666B9F8008AE9D8 /* AdminInvite.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = AdminInvite.storyboard; sourceTree = "<group>"; };
05D3BA262666DA3D008AE9D8 /* PendingInvites.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = PendingInvites.storyboard; sourceTree = "<group>"; };
05DE0CD6264F11E400D69C61 /* MemberListViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MemberListViewController.swift; sourceTree = "<group>"; };
2F2247AB262920AC006C6EE6 /* TokenRecord.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TokenRecord.swift; sourceTree = "<group>"; };
2F3AD7A22627C86A00B61A97 /* UserRecord.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserRecord.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -264,6 +276,7 @@
3A150A6626365A9A0052934B /* StatusRecord.swift */,
3A150A6B26365B670052934B /* TagRecord.swift */,
7DC54AE426437AB3000C8300 /* PinnedTicketRecord.swift */,
0541572726659F2E002A85F2 /* InviteRecord.swift */,
);
path = Codables;
sourceTree = "<group>";
Expand All @@ -278,6 +291,7 @@
5AB1C8EE262FE3210010F85E /* TagManager.swift */,
5AB1C908262FFF500010F85E /* UserManager.swift */,
5A25CFA6264B934400852035 /* StatusManager.swift */,
0541572226655FBA002A85F2 /* InviteManager.swift */,
);
path = Managers;
sourceTree = "<group>";
Expand All @@ -287,6 +301,7 @@
children = (
7D01B55B264FAAEE0009FA97 /* Admin.storyboard */,
3A90FBB8265F4E7900BE4F5D /* AdminTag.storyboard */,
05D3BA192666B9F8008AE9D8 /* AdminInvite.storyboard */,
);
path = Admin;
sourceTree = "<group>";
Expand Down Expand Up @@ -367,6 +382,7 @@
7D9963AB261EF3A4002338E7 /* Root.storyboard */,
7DC2A21626293F360002CEE6 /* Home.storyboard */,
7DC2A21B262943A70002CEE6 /* Sidebar.storyboard */,
05D3BA262666DA3D008AE9D8 /* PendingInvites.storyboard */,
5A9FF88826386D1400378550 /* Ticket.storyboard */,
7DEA17842639E7B5004E5A71 /* LaunchScreen.storyboard */,
3A150A76263CB5F70052934B /* TicketDetail.storyboard */,
Expand All @@ -385,6 +401,7 @@
7DC2A226262948800002CEE6 /* SluggoSidebarContainerViewController.swift */,
5A9FF88D26386D4700378550 /* TicketListController.swift */,
5A9C4C1B2640BC4E00B270AB /* TeamTableViewController.swift */,
053A259E26645DDD0072A773 /* PendingInvitesViewController.swift */,
5A9C4C202641113D00B270AB /* TeamSelectorContainerViewController.swift */,
7D23834A264119050091C7E8 /* HomeTableViewController.swift */,
5A25CFAB264B966300852035 /* TicketFilterTableViewController.swift */,
Expand All @@ -395,6 +412,7 @@
3A90FBB426531AC600BE4F5D /* AdminUserRolesTableViewController.swift */,
7DF6CBA8265F9A8E0013CAEA /* SluggoNavigationController.swift */,
3A90FBBA265F4FAB00BE4F5D /* AdminTagViewController.swift */,
0541572C2665BD29002A85F2 /* AdminInviteViewController.swift */,
);
path = "View Controllers";
sourceTree = "<group>";
Expand Down Expand Up @@ -519,8 +537,10 @@
7DEA17852639E7B5004E5A71 /* LaunchScreen.storyboard in Resources */,
7D01B55C264FAAEE0009FA97 /* Admin.storyboard in Resources */,
3A150A77263CB5F70052934B /* TicketDetail.storyboard in Resources */,
05D3BA1A2666B9F8008AE9D8 /* AdminInvite.storyboard in Resources */,
7DC2A21726293F360002CEE6 /* Home.storyboard in Resources */,
7DC2A21C262943A70002CEE6 /* Sidebar.storyboard in Resources */,
05D3BA272666DA3D008AE9D8 /* PendingInvites.storyboard in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -567,9 +587,11 @@
files = (
5A9C4C212641113D00B270AB /* TeamSelectorContainerViewController.swift in Sources */,
5A79FFE6262E563F00D04320 /* LoginViewController.swift in Sources */,
0541572326655FBA002A85F2 /* InviteManager.swift in Sources */,
5AB1C8FC262FF1690010F85E /* TicketRecord.swift in Sources */,
3A90FBB32651D76900BE4F5D /* TicketTabTableViewController.swift in Sources */,
5A25CFDF264BCF2C00852035 /* TicketFilterParameters.swift in Sources */,
0541572826659F2E002A85F2 /* InviteRecord.swift in Sources */,
5A25CFE7264BD73D00852035 /* TicketFilterTableViewCell.swift in Sources */,
7D1DA6B7262B866D00E7C12D /* SidebarData.swift in Sources */,
3A90FBB526531AC600BE4F5D /* AdminUserRolesTableViewController.swift in Sources */,
Expand Down Expand Up @@ -604,13 +626,15 @@
5AB1C8F7262FE3520010F85E /* AppIdentity.swift in Sources */,
7D9963A6261EF3A4002338E7 /* AppDelegate.swift in Sources */,
5A673570263BF2D200C4C778 /* UIColor.swift in Sources */,
0541572D2665BD29002A85F2 /* AdminInviteViewController.swift in Sources */,
3A150A6C26365B670052934B /* TagRecord.swift in Sources */,
5A25CFB1264B9A9300852035 /* Methods.swift in Sources */,
7D778C06264A374C00D4061A /* ViewControllerExtensions.swift in Sources */,
7D23834B264119050091C7E8 /* HomeTableViewController.swift in Sources */,
5AB1C8EF262FE3210010F85E /* TagManager.swift in Sources */,
5A9FF88E26386D4700378550 /* TicketListController.swift in Sources */,
5AB1C8E5262FE2E60010F85E /* TicketManager.swift in Sources */,
053A259F26645DDD0072A773 /* PendingInvitesViewController.swift in Sources */,
2F3AD7A82627C89B00B61A97 /* MemberRecord.swift in Sources */,
5AB1C8DD262FE2DD0010F85E /* TeamManager.swift in Sources */,
5A00A045263A34CC0085C8C6 /* TicketTableViewCell.swift in Sources */,
Expand Down
25 changes: 25 additions & 0 deletions Sluggo/Models/Codables/InviteRecord.swift
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
}
102 changes: 102 additions & 0 deletions Sluggo/Models/Managers/InviteManager.swift
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)
}
}
Loading

0 comments on commit 784bd71

Please sign in to comment.