Skip to content

Commit

Permalink
add remove get favorite users
Browse files Browse the repository at this point in the history
  • Loading branch information
grenos committed Apr 9, 2020
1 parent 1cb3b2b commit 1ceef14
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
Binary file not shown.
4 changes: 4 additions & 0 deletions GHFollowers/Screens/FavoriteListVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ class FavoriteListVC: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .systemBlue

PersistanceManager.retrieveFavorites { (result) in
print(result)
}
}

}
45 changes: 38 additions & 7 deletions GHFollowers/Screens/FollowerListVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,6 @@ class FollowerListVC: UIViewController {
navigationItem.rightBarButtonItem = addButton
}

@objc func addToFavorites() {
dismiss(animated: true)
}



func configureCollectionView() {
// init collection view
Expand Down Expand Up @@ -117,8 +112,6 @@ class FollowerListVC: UIViewController {
}




func configureSearchController() {
let searchController = UISearchController()

Expand All @@ -137,6 +130,44 @@ class FollowerListVC: UIViewController {



// MARK: Add to Favorites Calls
@objc func addToFavorites() {

// make network call with username to retreive the user avatar (shit code design)
// showloading
showLoadingView()
NetworkManager.shared.getUserInfo(for: username) { [weak self] result in
guard let self = self else { return }
self.dismissLoadingView()

switch result {

// success return the user
case .success(let user):
let favorite = Follower(login: user.login, avatarUrl: user.avatarUrl)

PersistanceManager.updateWith(favorite: favorite, actionType: .add) { [weak self ] error in
guard let self = self else { return }
// check to see if we have recieved and error
guard let error = error else {
// if error was nil ( no error)
self.presentGFAlertOnMainThread(title: "Success!", message: "User was successfully added to the favorite list! 🥳", buttonTitle: "Horray!")
return
}

self.presentGFAlertOnMainThread(title: "Somethig went wrong!", message: error.rawValue, buttonTitle: "Ok")
}

case .failure(let error):
self.presentGFAlertOnMainThread(title: "Something went wrong", message: error.rawValue, buttonTitle: "Ok")
}
}
}





// MARK: API call
func getFollowers(username: String, page: Int) {
// api call for followers
Expand Down

0 comments on commit 1ceef14

Please sign in to comment.