Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
37 changed files
with
896 additions
and
673 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
Large diffs are not rendered by default.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
SwiftShop.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings
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,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>PreviewsEnabled</key> | ||
<false/> | ||
</dict> | ||
</plist> |
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,14 @@ | ||
// | ||
// AppConstants.swift | ||
// SwiftShop | ||
// | ||
// Created by Geordie Powers on 2019-12-01. | ||
// Copyright © 2019 Geordie Powers. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
struct AppConstants { | ||
static let DEFAULT_LIST_ID = "MAIN" | ||
static let DEFAULT_LIST_NAME = "Main List" | ||
} |
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,128 @@ | ||
// | ||
// AppDatabase.swift | ||
// SwiftShop | ||
// | ||
// Created by Geordie Powers on 2019-12-05. | ||
// Copyright © 2019 Geordie Powers. All rights reserved. | ||
// | ||
|
||
import GRDB | ||
|
||
struct AppDatabase { | ||
static func openDatabase(atPath path: String) throws -> DatabasePool { | ||
let dbPool = try DatabasePool(path: path) | ||
|
||
#if DEBUG | ||
try dbPool.erase() | ||
#endif | ||
|
||
try setupMigrations.migrate(dbPool) | ||
|
||
#if DEBUG | ||
try debugMigrations.migrate(dbPool) | ||
#endif | ||
|
||
return dbPool | ||
} | ||
} | ||
|
||
extension AppDatabase { | ||
static var setupMigrations: DatabaseMigrator { | ||
var migrator = DatabaseMigrator() | ||
|
||
migrator.registerMigration("createList") { db in | ||
try db.create(table: "listEntity") { t in | ||
t.autoIncrementedPrimaryKey("id") | ||
|
||
t.column("name", .text) | ||
.notNull() | ||
.collate(.localizedCaseInsensitiveCompare) | ||
} | ||
} | ||
|
||
migrator.registerMigration("createProduct") { db in | ||
try db.create(table: "productEntity") { t in | ||
t.autoIncrementedPrimaryKey("id") | ||
|
||
t.column("name", .text) | ||
.notNull() | ||
.collate(.localizedCaseInsensitiveCompare) | ||
|
||
t.column("price", .double) | ||
} | ||
} | ||
|
||
migrator.registerMigration("createProductStatus") { db in | ||
try db.create(table: "productStatusEntity") { t in | ||
t.autoIncrementedPrimaryKey("id") | ||
|
||
t.column("listId", .integer) | ||
.references("listEntity", onDelete: .cascade) | ||
t.column("productId", .integer) | ||
.references("productEntity", onDelete: .cascade) | ||
|
||
t.column("complete", .boolean) | ||
.notNull() | ||
.defaults(to: false) | ||
} | ||
} | ||
|
||
migrator.registerMigration("createTag") { db in | ||
try db.create(table: "tagEntity") { t in | ||
t.autoIncrementedPrimaryKey("id") | ||
|
||
t.column("name", .text) | ||
.notNull() | ||
.collate(.localizedCaseInsensitiveCompare) | ||
|
||
t.column("color", .text) | ||
} | ||
} | ||
|
||
migrator.registerMigration("createProductTag") { db in | ||
try db.create(table: "productTagEntity") { t in | ||
t.column("productId", .integer) | ||
.references("productEntity", onDelete: .cascade) | ||
t.column("tagId", .integer) | ||
.references("tagEntity", onDelete: .cascade) | ||
} | ||
} | ||
|
||
return migrator | ||
} | ||
|
||
static var debugMigrations: DatabaseMigrator { | ||
var migrator = DatabaseMigrator() | ||
|
||
migrator.registerMigration("createDevEntities") { db in | ||
var list = ListEntity(id: nil, name: AppConstants.DEFAULT_LIST_NAME) | ||
try list.insert(db) | ||
|
||
var product1 = ProductEntity(id: nil, name: "First product", price: 3.00) | ||
var product2 = ProductEntity(id: nil, name: "Second product", price: 2.00) | ||
var product3 = ProductEntity(id: nil, name: "Third product", price: 1.00) | ||
try product1.insert(db) | ||
try product2.insert(db) | ||
try product3.insert(db) | ||
|
||
var tag1 = TagEntity(id: nil, name: "BlueTag", color: "blue") | ||
var tag2 = TagEntity(id: nil, name: "GreenTag", color: "green") | ||
try tag1.insert(db) | ||
try tag2.insert(db) | ||
|
||
var productStatus1 = ProductStatusEntity(listId: list.id!, productId: product1.id!, complete: false) | ||
try productStatus1.insert(db) | ||
var productStatus2 = ProductStatusEntity(listId: list.id!, productId: product2.id!, complete: true) | ||
try productStatus2.insert(db) | ||
|
||
var productTag1 = ProductTagEntity(productId: product1.id!, tagId: tag1.id!) | ||
var productTag2 = ProductTagEntity(productId: product1.id!, tagId: tag2.id!) | ||
var productTag3 = ProductTagEntity(productId: product3.id!, tagId: tag2.id!) | ||
try productTag1.insert(db) | ||
try productTag2.insert(db) | ||
try productTag3.insert(db) | ||
} | ||
|
||
return migrator | ||
} | ||
} |
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,23 @@ | ||
// | ||
// AppModel.swift | ||
// SwiftShop | ||
// | ||
// Created by Geordie Powers on 2019-12-07. | ||
// Copyright © 2019 Geordie Powers. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
import Combine | ||
import GRDB | ||
import GRDBCombine | ||
|
||
struct AppModel { | ||
private let database: () -> DatabaseWriter | ||
|
||
init(database: @escaping () -> DatabaseWriter) { | ||
self.database = database | ||
} | ||
|
||
func products() -> ProductRepository { ProductRepository(database()) } | ||
func lists() -> ProductListRepository { ProductListRepository(database()) } | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.