Skip to content

Commit

Permalink
Add Publisher metadata to Book
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewBennet committed Feb 17, 2019
1 parent ad4803a commit e0e511e
Show file tree
Hide file tree
Showing 12 changed files with 386 additions and 319 deletions.
6 changes: 4 additions & 2 deletions ReadingList/Api/GoogleBooks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,9 @@ class GoogleBooksParser {
if let code = fetchResult["volumeInfo"]["language"].string, Language.byIsoCode[code] != nil {
result.languageCode = code
}
// "Published Date" refers to *this* edition; there doesn't seem to be a way to get the first publication date :(
//result.publishedDate = fetchResult["volumeInfo","publishedDate"].string?.toDateViaFormat("yyyy-MM-dd")

// Note: "Published Date" refers to *this* edition; there doesn't seem to be a way to get the first publication date
result.publisher = fetchResult["volumeInfo", "publisher"].string

result.hasSmallImage = fetchResult["volumeInfo", "imageLinks", "small"].string != nil
result.hasThumbnailImage = fetchResult["volumeInfo", "imageLinks", "thumbnail"].string != nil
Expand Down Expand Up @@ -212,6 +213,7 @@ class FetchResult {
var authors = [Author]()
var isbn13: ISBN13?
var description: String?
var publisher: String?
var subjects = [String]()
var languageCode: String?
var publishedDate: Date?
Expand Down
1 change: 1 addition & 0 deletions ReadingList/Data/BookCSVExport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class BookCSVExport {
CsvColumn<Book>(header: "Authors") { $0.authors.map { $0.lastNameCommaFirstName }.joined(separator: "; ") },
CsvColumn<Book>(header: "Page Count") { $0.pageCount == nil ? nil : String(describing: $0.pageCount!) },
CsvColumn<Book>(header: "Publication Date") { $0.publicationDate?.string(withDateFormat: "yyyy-MM-dd") },
CsvColumn<Book>(header: "Publisher") { $0.publisher },
CsvColumn<Book>(header: "Description") { $0.bookDescription },
CsvColumn<Book>(header: "Subjects") { $0.subjects.map { $0.name }.joined(separator: "; ") },
CsvColumn<Book>(header: "Language Code") { $0.languageCode },
Expand Down
1 change: 1 addition & 0 deletions ReadingList/Data/BookCSVImporter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ private class BookCSVParserDelegate: CSVParserDelegate {
book.currentPage = Int32(values["Current Page"])
book.notes = values["Notes"]?.replacingOccurrences(of: "\r\n", with: "\n")
book.publicationDate = Date(iso: values["Publication Date"])
book.publisher = values["Publisher"]
book.bookDescription = values["Description"]?.replacingOccurrences(of: "\r\n", with: "\n")
if let started = Date(iso: values["Started Reading"]) {
if let finished = Date(iso: values["Finished Reading"]) {
Expand Down
332 changes: 169 additions & 163 deletions ReadingList/Debug/examplebooks.csv

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions ReadingList/LaunchManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ class LaunchManager {
alert.addAction(UIAlertAction(title: "Delete Store", style: .destructive) { _ in
NSPersistentStoreCoordinator().destroyAndDeleteStore(at: URL.applicationSupport.appendingPathComponent(PersistentStoreManager.storeFileName))
self.initialisePersistentStore()
self.storeMigrationFailed = false
})
#endif

Expand Down
2 changes: 2 additions & 0 deletions ReadingList/Models/Book.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Book: NSManagedObject {
@NSManaged var title: String
@NSManaged private(set) var authorSort: String
@NSManaged var publicationDate: Date?
@NSManaged var publisher: String?
@NSManaged var bookDescription: String?
@NSManaged var coverImage: Data?
@NSManaged var notes: String?
Expand Down Expand Up @@ -154,6 +155,7 @@ extension Book {
coverImage = fetchResult.coverImage
pageCount = fetchResult.pageCount
publicationDate = fetchResult.publishedDate
publisher = fetchResult.publisher
isbn13 = fetchResult.isbn13?.int
languageCode = fetchResult.languageCode
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<attribute name="notes" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="pageCount" optional="YES" attributeType="Integer 32" minValueString="0" usesScalarValueType="YES" syncable="YES"/>
<attribute name="publicationDate" optional="YES" attributeType="Date" usesScalarValueType="NO" syncable="YES"/>
<attribute name="publisher" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="rating" optional="YES" attributeType="Integer 16" minValueString="1" maxValueString="5" usesScalarValueType="YES" syncable="YES"/>
<attribute name="readState" attributeType="Integer 16" defaultValueString="2" usesScalarValueType="YES" syncable="YES"/>
<attribute name="sort" optional="YES" attributeType="Integer 32" usesScalarValueType="YES" syncable="YES"/>
Expand Down Expand Up @@ -71,7 +72,7 @@
</fetchIndex>
</entity>
<elements>
<element name="Book" positionX="-63" positionY="-18" width="128" height="345"/>
<element name="Book" positionX="-63" positionY="-18" width="128" height="360"/>
<element name="List" positionX="-54" positionY="117" width="128" height="90"/>
<element name="Subject" positionX="-63" positionY="90" width="128" height="75"/>
</elements>
Expand Down
Loading

0 comments on commit e0e511e

Please sign in to comment.