Skip to content

Commit

Permalink
#51: [refactor] The SwiftDiscogsApp target compiles!
Browse files Browse the repository at this point in the history
  • Loading branch information
jrtibbetts committed Aug 13, 2022
1 parent ed250ad commit 3c91134
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 49 deletions.
14 changes: 12 additions & 2 deletions SwiftDiscogs.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
96226AFB2069FF3D000EEC50 /* DiscogsArtistViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96226AF62069F578000EEC50 /* DiscogsArtistViewController.swift */; };
96226AFD2069FF3D000EEC50 /* DiscogsArtistModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 969ADA6D2068A7D300A8BDD0 /* DiscogsArtistModel.swift */; };
96226AFE2069FF3D000EEC50 /* DiscogsSearchViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9603690E205A1C7200D24CE7 /* DiscogsSearchViewController.swift */; };
962833382898E33E00F7ABA2 /* Medi8 in Frameworks */ = {isa = PBXBuildFile; productRef = 962833372898E33E00F7ABA2 /* Medi8 */; };
963282B2222CBAD90090B29F /* SectionedModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 963282B1222CBAD90090B29F /* SectionedModel.swift */; };
963282B9222CD7E40090B29F /* MasterReleaseViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 963282B8222CD7E40090B29F /* MasterReleaseViewController.swift */; };
963282BD222F82A10090B29F /* TrackTableCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 963282BC222F82A10090B29F /* TrackTableCell.swift */; };
Expand Down Expand Up @@ -515,6 +516,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
962833382898E33E00F7ABA2 /* Medi8 in Frameworks */,
968102072272BA20003E6D82 /* SwiftDiscogs.framework in Frameworks */,
96E7CE4B25EB64EE00EBC43E /* UIKit.framework in Frameworks */,
);
Expand Down Expand Up @@ -1143,6 +1145,7 @@
);
name = SwiftDiscogsApp;
packageProductDependencies = (
962833372898E33E00F7ABA2 /* Medi8 */,
);
productName = SwiftDiscogsApp;
productReference = 960368DA205A012B00D24CE7 /* SwiftDiscogsApp.app */;
Expand Down Expand Up @@ -1816,6 +1819,7 @@
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 3MY7LL9G36;
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
INFOPLIST_FILE = SwiftDiscogsApp/Info.plist;
Expand All @@ -1837,6 +1841,7 @@
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 3MY7LL9G36;
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
INFOPLIST_FILE = SwiftDiscogsApp/Info.plist;
Expand Down Expand Up @@ -2405,13 +2410,18 @@
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/jrtibbetts/JSONClient";
requirement = {
kind = upToNextMinorVersion;
minimumVersion = 3.0.0;
branch = main;
kind = branch;
};
};
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
962833372898E33E00F7ABA2 /* Medi8 */ = {
isa = XCSwiftPackageProductDependency;
package = 969EBFB425EA2F940008DE91 /* XCRemoteSwiftPackageReference "Medi8" */;
productName = Medi8;
};
969EBFB825EA2FD00008DE91 /* JSONClient */ = {
isa = XCSwiftPackageProductDependency;
package = 969EBFB725EA2FD00008DE91 /* XCRemoteSwiftPackageReference "JSONClient" */;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/jrtibbetts/JSONClient",
"state" : {
"branch" : "28-replace-promisekit-with-async-await",
"revision" : "111fa2050dc17cec670445389c728183ca336f41"
"branch" : "main",
"revision" : "ca1e1883972b85a6720bc829c86839d87553305c"
}
},
{
Expand Down
22 changes: 13 additions & 9 deletions SwiftDiscogsApp/Artist/DiscogsArtistViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ public class DiscogsArtistViewController: UIViewController {
public var artistSearchResult: SearchResult? {
didSet {
if let artistId = artistSearchResult?.id {
artist = try? await DiscogsManager.discogs.artist(identifier: artistId)
Task {
artist = try await DiscogsManager.discogs.artist(identifier: artistId)
}
}
}
}
Expand Down Expand Up @@ -77,9 +79,11 @@ public class DiscogsArtistViewController: UIViewController {
func fetchArtist(named artistName: String) {
Task {
do {
let results = try async DiscogsManager.discogs.search(forArtist: artistName)
.filter { $0.type == "artist" } {
handleArtistResults(results)
try await DiscogsManager.discogs.search(forArtist: artistName)
.results?
.filter { $0.type == "artist" }
.forEach {
handleArtistResults([$0])
}
} catch {
presentAlert(for: error)
Expand Down Expand Up @@ -135,13 +139,13 @@ public class DiscogsArtistViewController: UIViewController {
return
}

DiscogsManager.discogs.releases(forArtist: artistId).done { [weak self] (summaries) in
self?.artistModel.releases = summaries.releases?.filter { $0.type == "master"
Task {
let summaries = try await DiscogsManager.discogs.releases(forArtist: artistId)

artistModel.releases = summaries.releases?.filter { $0.type == "master"
&& $0.role == "Main"
&& $0.mainRelease != nil }
self?.artistView.refresh()
}.catch { _ in
// HANDLE THE ERROR
artistView.refresh()
}
}

Expand Down
5 changes: 2 additions & 3 deletions SwiftDiscogsApp/Release/ReleaseVersionViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ class ReleaseVersionViewController: BaseReleaseViewController {
releaseVersionDisplay?.releaseVersion = releaseVersion

if let releaseID = releaseVersion?.id {
_ = DiscogsManager.discogs.release(identifier: releaseID).done { [weak self] (release) in
self?.release = release
}.catch { _ in
Task {
release = try await DiscogsManager.discogs.release(identifier: releaseID)
}
}
}
Expand Down
22 changes: 10 additions & 12 deletions SwiftDiscogsApp/Search/DiscogsSearchViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,18 @@ class DiscogsSearchViewController: CollectionAndTableViewController,
return
}

DiscogsManager.discogs.search(for: searchTerms, type: "Artist").done { [weak self] (searchResults) in
guard let self = self else {
return
}

self.results = searchResults.results?.filter { $0.type == "artist" }
Task {
do {
let searchResults = try await DiscogsManager.discogs.search(for: searchTerms, type: "Artist")
results = searchResults.results?.filter { $0.type == "artist" }

if self.results?.count == 1 {
self.searchView?.selectItem(at: IndexPath(item: 0, section: 0))
if results?.count == 1 {
searchView?.selectItem(at: IndexPath(item: 0, section: 0))
}
} catch {
results = nil
presentAlert(for: error)
}

}.catch { [weak self] (error) in
self?.results = nil
self?.presentAlert(for: error)
}
}

Expand Down
43 changes: 22 additions & 21 deletions SwiftDiscogsApp/Third-Party Services/Discogs/DiscogsService.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright © 2019 Poikile Creations. All rights reserved.

import CoreData
import JSONClient
import Stylobate
import SwiftDiscogs
import UIKit
Expand All @@ -26,12 +27,11 @@ class DiscogsService: ThirdPartyService, AuthenticatedService, ImportableService
and we're getting closer every day. (www.discogs.com/about)
"""

DiscogsManager.discogs.userIdentity().then { [weak self] (userIdentity) async -> UserProfile in
self?.handle(userIdentity: userIdentity)
return DiscogsManager.discogs.userProfile(userName: userIdentity.username)
}.done { [weak self] (userProfile) in
self?.userProfile = userProfile
}.cauterize()
Task {
let userIdentity = try await DiscogsManager.discogs.userIdentity()
handle(userIdentity: userIdentity)
userProfile = try await DiscogsManager.discogs.userProfile(userName: userIdentity.username)
}
}

// MARK: - AuthenticatedService
Expand Down Expand Up @@ -79,16 +79,17 @@ class DiscogsService: ThirdPartyService, AuthenticatedService, ImportableService

authenticationDelegate?.willSignIn(toService: self)

let promise = DiscogsManager.discogs.authorize(presentingViewController: viewController,
callbackUrlString: AppDelegate.shared.callbackUrl.absoluteString)
promise.then { _ in
return DiscogsManager.discogs.userIdentity()
}.done { [weak self] (userIdentity) in
self?.handle(userIdentity: userIdentity)
}.catch { [weak self] (error) in
self?.isSignedIn = false
self?.authenticationDelegate?.signIn(toService: self, failedWithError: error)
viewController.presentAlert(for: error, title: L10n.discogsSignInFailed)
Task {
do {
_ = try await (DiscogsManager.discogs as? OAuth1JSONClient)?.authorize(callbackUrl: AppDelegate.shared.callbackUrl,
presentOver: viewController.view)
let userIdentity = try await DiscogsManager.discogs.userIdentity()
handle(userIdentity: userIdentity)
} catch {
isSignedIn = false
authenticationDelegate?.signIn(toService: self, failedWithError: error)
await viewController.presentAlert(for: error, title: L10n.discogsSignInFailed)
}
}
}

Expand Down Expand Up @@ -116,7 +117,7 @@ class DiscogsService: ThirdPartyService, AuthenticatedService, ImportableService

// MARK: Functions

// func importData() {
func importData() {
// let context = AppDelegate.shared.medi8Context
//
// if let username = userName {
Expand All @@ -143,12 +144,12 @@ class DiscogsService: ThirdPartyService, AuthenticatedService, ImportableService
// }
// }
// }
// }
//
// func stopImportingData() {
}

func stopImportingData() {
// importDelegate?.willFinishImporting(fromService: self)
// isImporting = false
// importDelegate?.didFinishImporting(fromService: self)
// }
}

}

0 comments on commit 3c91134

Please sign in to comment.