Browse Source

Cleaned up a bit and added favorite/found setting logic from buttons

Víctor Hernández 4 years ago
parent
commit
ec4418bd4d

+ 12
- 12
Flowerdex/Flowerdex.xcodeproj/project.pbxproj View File

11
 		A51B4F772546674C002AFF05 /* FlowersResponseModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A51B4F762546674C002AFF05 /* FlowersResponseModel.swift */; };
11
 		A51B4F772546674C002AFF05 /* FlowersResponseModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A51B4F762546674C002AFF05 /* FlowersResponseModel.swift */; };
12
 		A51B4F7B25466A75002AFF05 /* flowers.json in Resources */ = {isa = PBXBuildFile; fileRef = A51B4F7A25466A75002AFF05 /* flowers.json */; };
12
 		A51B4F7B25466A75002AFF05 /* flowers.json in Resources */ = {isa = PBXBuildFile; fileRef = A51B4F7A25466A75002AFF05 /* flowers.json */; };
13
 		A52FB5C42546C2EA000AD235 /* rawResponse.json in Resources */ = {isa = PBXBuildFile; fileRef = A52FB5C32546C2EA000AD235 /* rawResponse.json */; };
13
 		A52FB5C42546C2EA000AD235 /* rawResponse.json in Resources */ = {isa = PBXBuildFile; fileRef = A52FB5C32546C2EA000AD235 /* rawResponse.json */; };
14
-		A5711B8B255CE03000E727BB /* FlowerItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5711B8A255CE03000E727BB /* FlowerItem.swift */; };
14
+		A5711B8B255CE03000E727BB /* Flower.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5711B8A255CE03000E727BB /* Flower.swift */; };
15
 		A5711B8E255CE53900E727BB /* DummyData.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5711B8D255CE53900E727BB /* DummyData.swift */; };
15
 		A5711B8E255CE53900E727BB /* DummyData.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5711B8D255CE53900E727BB /* DummyData.swift */; };
16
 		A58640BA258F30AD00F626AB /* LoginView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A58640B9258F30AD00F626AB /* LoginView.swift */; };
16
 		A58640BA258F30AD00F626AB /* LoginView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A58640B9258F30AD00F626AB /* LoginView.swift */; };
17
 		A58640BE258F30F200F626AB /* RegisterView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A58640BD258F30F200F626AB /* RegisterView.swift */; };
17
 		A58640BE258F30F200F626AB /* RegisterView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A58640BD258F30F200F626AB /* RegisterView.swift */; };
20
 		A59A27452545568A0052319F /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A59A27442545568A0052319F /* Assets.xcassets */; };
20
 		A59A27452545568A0052319F /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A59A27442545568A0052319F /* Assets.xcassets */; };
21
 		A59A27482545568A0052319F /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A59A27472545568A0052319F /* Preview Assets.xcassets */; };
21
 		A59A27482545568A0052319F /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A59A27472545568A0052319F /* Preview Assets.xcassets */; };
22
 		A5AF3F5C2545FDEB0035AC9A /* FlowerCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5AF3F5B2545FDEB0035AC9A /* FlowerCard.swift */; };
22
 		A5AF3F5C2545FDEB0035AC9A /* FlowerCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5AF3F5B2545FDEB0035AC9A /* FlowerCard.swift */; };
23
-		A5EA2F24258FEC2300699182 /* UserService.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5EA2F23258FEC2300699182 /* UserService.swift */; };
23
+		A5EA2F24258FEC2300699182 /* AuthenticationService.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5EA2F23258FEC2300699182 /* AuthenticationService.swift */; };
24
 		A5EA2F28258FEC3D00699182 /* FlowerService.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5EA2F27258FEC3D00699182 /* FlowerService.swift */; };
24
 		A5EA2F28258FEC3D00699182 /* FlowerService.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5EA2F27258FEC3D00699182 /* FlowerService.swift */; };
25
 		A5EA2F2C258FF0BD00699182 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5EA2F2B258FF0BD00699182 /* Constants.swift */; };
25
 		A5EA2F2C258FF0BD00699182 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5EA2F2B258FF0BD00699182 /* Constants.swift */; };
26
 		A5EA2F32258FF58200699182 /* Responses.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5EA2F31258FF58200699182 /* Responses.swift */; };
26
 		A5EA2F32258FF58200699182 /* Responses.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5EA2F31258FF58200699182 /* Responses.swift */; };
31
 		A5EE38AC257772200014D0BE /* FiltersSheet.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5EE38AB257772200014D0BE /* FiltersSheet.swift */; };
31
 		A5EE38AC257772200014D0BE /* FiltersSheet.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5EE38AB257772200014D0BE /* FiltersSheet.swift */; };
32
 		A5EE38B0257818520014D0BE /* FlowersList.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5EE38AF257818520014D0BE /* FlowersList.swift */; };
32
 		A5EE38B0257818520014D0BE /* FlowersList.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5EE38AF257818520014D0BE /* FlowersList.swift */; };
33
 		A5EE38B3257818BE0014D0BE /* StatusIcons.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5EE38B2257818BE0014D0BE /* StatusIcons.swift */; };
33
 		A5EE38B3257818BE0014D0BE /* StatusIcons.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5EE38B2257818BE0014D0BE /* StatusIcons.swift */; };
34
-		A5F0D2FC258F3D2200AF735C /* UserModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5F0D2FB258F3D2200AF735C /* UserModel.swift */; };
34
+		A5F0D2FC258F3D2200AF735C /* User.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5F0D2FB258F3D2200AF735C /* User.swift */; };
35
 		A5F3271A25460C0B003BCE0F /* FlowerDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5F3271925460C0B003BCE0F /* FlowerDetailView.swift */; };
35
 		A5F3271A25460C0B003BCE0F /* FlowerDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5F3271925460C0B003BCE0F /* FlowerDetailView.swift */; };
36
 /* End PBXBuildFile section */
36
 /* End PBXBuildFile section */
37
 
37
 
40
 		A51B4F762546674C002AFF05 /* FlowersResponseModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlowersResponseModel.swift; sourceTree = "<group>"; };
40
 		A51B4F762546674C002AFF05 /* FlowersResponseModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlowersResponseModel.swift; sourceTree = "<group>"; };
41
 		A51B4F7A25466A75002AFF05 /* flowers.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = flowers.json; sourceTree = "<group>"; };
41
 		A51B4F7A25466A75002AFF05 /* flowers.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = flowers.json; sourceTree = "<group>"; };
42
 		A52FB5C32546C2EA000AD235 /* rawResponse.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = rawResponse.json; sourceTree = "<group>"; };
42
 		A52FB5C32546C2EA000AD235 /* rawResponse.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = rawResponse.json; sourceTree = "<group>"; };
43
-		A5711B8A255CE03000E727BB /* FlowerItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlowerItem.swift; sourceTree = "<group>"; };
43
+		A5711B8A255CE03000E727BB /* Flower.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Flower.swift; sourceTree = "<group>"; };
44
 		A5711B8D255CE53900E727BB /* DummyData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DummyData.swift; sourceTree = "<group>"; };
44
 		A5711B8D255CE53900E727BB /* DummyData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DummyData.swift; sourceTree = "<group>"; };
45
 		A58640B9258F30AD00F626AB /* LoginView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginView.swift; sourceTree = "<group>"; };
45
 		A58640B9258F30AD00F626AB /* LoginView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginView.swift; sourceTree = "<group>"; };
46
 		A58640BD258F30F200F626AB /* RegisterView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RegisterView.swift; sourceTree = "<group>"; };
46
 		A58640BD258F30F200F626AB /* RegisterView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RegisterView.swift; sourceTree = "<group>"; };
51
 		A59A27472545568A0052319F /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
51
 		A59A27472545568A0052319F /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
52
 		A59A27492545568A0052319F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
52
 		A59A27492545568A0052319F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
53
 		A5AF3F5B2545FDEB0035AC9A /* FlowerCard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlowerCard.swift; sourceTree = "<group>"; };
53
 		A5AF3F5B2545FDEB0035AC9A /* FlowerCard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlowerCard.swift; sourceTree = "<group>"; };
54
-		A5EA2F23258FEC2300699182 /* UserService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserService.swift; sourceTree = "<group>"; };
54
+		A5EA2F23258FEC2300699182 /* AuthenticationService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthenticationService.swift; sourceTree = "<group>"; };
55
 		A5EA2F27258FEC3D00699182 /* FlowerService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlowerService.swift; sourceTree = "<group>"; };
55
 		A5EA2F27258FEC3D00699182 /* FlowerService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlowerService.swift; sourceTree = "<group>"; };
56
 		A5EA2F2B258FF0BD00699182 /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
56
 		A5EA2F2B258FF0BD00699182 /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
57
 		A5EA2F31258FF58200699182 /* Responses.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Responses.swift; sourceTree = "<group>"; };
57
 		A5EA2F31258FF58200699182 /* Responses.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Responses.swift; sourceTree = "<group>"; };
62
 		A5EE38AB257772200014D0BE /* FiltersSheet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FiltersSheet.swift; sourceTree = "<group>"; };
62
 		A5EE38AB257772200014D0BE /* FiltersSheet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FiltersSheet.swift; sourceTree = "<group>"; };
63
 		A5EE38AF257818520014D0BE /* FlowersList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlowersList.swift; sourceTree = "<group>"; };
63
 		A5EE38AF257818520014D0BE /* FlowersList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlowersList.swift; sourceTree = "<group>"; };
64
 		A5EE38B2257818BE0014D0BE /* StatusIcons.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusIcons.swift; sourceTree = "<group>"; };
64
 		A5EE38B2257818BE0014D0BE /* StatusIcons.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusIcons.swift; sourceTree = "<group>"; };
65
-		A5F0D2FB258F3D2200AF735C /* UserModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserModel.swift; sourceTree = "<group>"; };
65
+		A5F0D2FB258F3D2200AF735C /* User.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = User.swift; sourceTree = "<group>"; };
66
 		A5F3271925460C0B003BCE0F /* FlowerDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlowerDetailView.swift; sourceTree = "<group>"; };
66
 		A5F3271925460C0B003BCE0F /* FlowerDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlowerDetailView.swift; sourceTree = "<group>"; };
67
 /* End PBXFileReference section */
67
 /* End PBXFileReference section */
68
 
68
 
81
 			isa = PBXGroup;
81
 			isa = PBXGroup;
82
 			children = (
82
 			children = (
83
 				A51B4F762546674C002AFF05 /* FlowersResponseModel.swift */,
83
 				A51B4F762546674C002AFF05 /* FlowersResponseModel.swift */,
84
-				A5711B8A255CE03000E727BB /* FlowerItem.swift */,
84
+				A5711B8A255CE03000E727BB /* Flower.swift */,
85
 				A5EE3896257658400014D0BE /* Filters.swift */,
85
 				A5EE3896257658400014D0BE /* Filters.swift */,
86
 				A5EE389025763D3A0014D0BE /* AuthenticationModel.swift */,
86
 				A5EE389025763D3A0014D0BE /* AuthenticationModel.swift */,
87
-				A5F0D2FB258F3D2200AF735C /* UserModel.swift */,
87
+				A5F0D2FB258F3D2200AF735C /* User.swift */,
88
 			);
88
 			);
89
 			path = Model;
89
 			path = Model;
90
 			sourceTree = "<group>";
90
 			sourceTree = "<group>";
162
 			isa = PBXGroup;
162
 			isa = PBXGroup;
163
 			children = (
163
 			children = (
164
 				A50EEFCC255D175400545CFE /* ContentDataSource.swift */,
164
 				A50EEFCC255D175400545CFE /* ContentDataSource.swift */,
165
-				A5EA2F23258FEC2300699182 /* UserService.swift */,
165
+				A5EA2F23258FEC2300699182 /* AuthenticationService.swift */,
166
 				A5EA2F27258FEC3D00699182 /* FlowerService.swift */,
166
 				A5EA2F27258FEC3D00699182 /* FlowerService.swift */,
167
 				A5EE38A3257700230014D0BE /* ImageManager.swift */,
167
 				A5EE38A3257700230014D0BE /* ImageManager.swift */,
168
 			);
168
 			);
270
 				A5EE38B0257818520014D0BE /* FlowersList.swift in Sources */,
270
 				A5EE38B0257818520014D0BE /* FlowersList.swift in Sources */,
271
 				A51B4F772546674C002AFF05 /* FlowersResponseModel.swift in Sources */,
271
 				A51B4F772546674C002AFF05 /* FlowersResponseModel.swift in Sources */,
272
 				A5EE3897257658400014D0BE /* Filters.swift in Sources */,
272
 				A5EE3897257658400014D0BE /* Filters.swift in Sources */,
273
-				A5711B8B255CE03000E727BB /* FlowerItem.swift in Sources */,
273
+				A5711B8B255CE03000E727BB /* Flower.swift in Sources */,
274
 				A59A2741254556880052319F /* FlowerdexApp.swift in Sources */,
274
 				A59A2741254556880052319F /* FlowerdexApp.swift in Sources */,
275
 				A5EA2F32258FF58200699182 /* Responses.swift in Sources */,
275
 				A5EA2F32258FF58200699182 /* Responses.swift in Sources */,
276
 				A58640BE258F30F200F626AB /* RegisterView.swift in Sources */,
276
 				A58640BE258F30F200F626AB /* RegisterView.swift in Sources */,
279
 				A58640BA258F30AD00F626AB /* LoginView.swift in Sources */,
279
 				A58640BA258F30AD00F626AB /* LoginView.swift in Sources */,
280
 				A5AF3F5C2545FDEB0035AC9A /* FlowerCard.swift in Sources */,
280
 				A5AF3F5C2545FDEB0035AC9A /* FlowerCard.swift in Sources */,
281
 				A5EE38B3257818BE0014D0BE /* StatusIcons.swift in Sources */,
281
 				A5EE38B3257818BE0014D0BE /* StatusIcons.swift in Sources */,
282
-				A5EA2F24258FEC2300699182 /* UserService.swift in Sources */,
282
+				A5EA2F24258FEC2300699182 /* AuthenticationService.swift in Sources */,
283
 				A5711B8E255CE53900E727BB /* DummyData.swift in Sources */,
283
 				A5711B8E255CE53900E727BB /* DummyData.swift in Sources */,
284
-				A5F0D2FC258F3D2200AF735C /* UserModel.swift in Sources */,
284
+				A5F0D2FC258F3D2200AF735C /* User.swift in Sources */,
285
 				A5EE38AC257772200014D0BE /* FiltersSheet.swift in Sources */,
285
 				A5EE38AC257772200014D0BE /* FiltersSheet.swift in Sources */,
286
 				A5EA2F28258FEC3D00699182 /* FlowerService.swift in Sources */,
286
 				A5EA2F28258FEC3D00699182 /* FlowerService.swift in Sources */,
287
 			);
287
 			);

BIN
Flowerdex/Flowerdex.xcodeproj/project.xcworkspace/xcuserdata/victor.hernandez.xcuserdatad/UserInterfaceState.xcuserstate View File


Flowerdex/Flowerdex/Model/FlowerItem.swift → Flowerdex/Flowerdex/Model/Flower.swift View File

1
 //
1
 //
2
-//  FlowerItem.swift
2
+//  Flower.swift
3
 //  Flowerdex
3
 //  Flowerdex
4
 //
4
 //
5
 //  Created by Víctor A. Hernández on 11/11/20.
5
 //  Created by Víctor A. Hernández on 11/11/20.
7
 
7
 
8
 import Foundation
8
 import Foundation
9
 
9
 
10
-struct FlowerItem: Hashable, Codable, Identifiable {
10
+struct Flower: Hashable, Codable, Identifiable {
11
     let id: Int
11
     let id: Int
12
     let common_name: String?
12
     let common_name: String?
13
     var commonName: String {
13
     var commonName: String {

+ 1
- 1
Flowerdex/Flowerdex/Model/FlowersResponseModel.swift View File

8
 import Foundation
8
 import Foundation
9
 
9
 
10
 struct FlowersResponseModel: Hashable, Codable {
10
 struct FlowersResponseModel: Hashable, Codable {
11
-    let data: [FlowerItem]?
11
+    let data: [Flower]?
12
     let links: Dictionary<String, String>?
12
     let links: Dictionary<String, String>?
13
     let meta: Dictionary<String, Int>?
13
     let meta: Dictionary<String, Int>?
14
     let error: String?
14
     let error: String?

Flowerdex/Flowerdex/Model/UserModel.swift → Flowerdex/Flowerdex/Model/User.swift View File

1
 //
1
 //
2
-//  UserModel.swift
2
+//  User.swift
3
 //  Flowerdex
3
 //  Flowerdex
4
 //
4
 //
5
 //  Created by Víctor A. Hernández on 12/20/20.
5
 //  Created by Víctor A. Hernández on 12/20/20.

+ 1
- 1
Flowerdex/Flowerdex/Resources/DummyData.swift View File

7
 
7
 
8
 import Foundation
8
 import Foundation
9
 
9
 
10
-let dummyFlowers: [FlowerItem] = load("flowers.json")
10
+let dummyFlowers: [Flower] = load("flowers.json")
11
 
11
 
12
 func load<T: Decodable>(_ filename: String) -> T {
12
 func load<T: Decodable>(_ filename: String) -> T {
13
     let data: Data
13
     let data: Data

+ 833
- 598
Flowerdex/Flowerdex/Resources/flowers.json
File diff suppressed because it is too large
View File


Flowerdex/Flowerdex/Services/UserService.swift → Flowerdex/Flowerdex/Services/AuthenticationService.swift View File

1
 //
1
 //
2
-//  UserService.swift
2
+//  AuthenticationService.swift
3
 //  Flowerdex
3
 //  Flowerdex
4
 //
4
 //
5
 //  Created by Víctor A. Hernández on 12/20/20.
5
 //  Created by Víctor A. Hernández on 12/20/20.

+ 1
- 1
Flowerdex/Flowerdex/Services/ContentDataSource.swift View File

11
 
11
 
12
 /*
12
 /*
13
 class ContentDataSource: ObservableObject {
13
 class ContentDataSource: ObservableObject {
14
-  @Published var items = [FlowerItem]() // ListItem
14
+  @Published var items = [Flower]() // ListItem
15
   @Published var isLoadingPage = false
15
   @Published var isLoadingPage = false
16
   private var currentPage = 1
16
   private var currentPage = 1
17
   private var canLoadMorePages = true
17
   private var canLoadMorePages = true

+ 81
- 4
Flowerdex/Flowerdex/Services/FlowerService.swift View File

10
 class FlowerService: ObservableObject {
10
 class FlowerService: ObservableObject {
11
     
11
     
12
     @Published var response: Response = .unfetched
12
     @Published var response: Response = .unfetched
13
-    @Published var items = [FlowerItem]()
13
+    @Published var items = [Flower]()
14
     
14
     
15
     
15
     
16
     private func getQueryParameters(_ filters: Filters) -> [URLQueryItem] {
16
     private func getQueryParameters(_ filters: Filters) -> [URLQueryItem] {
47
         components.scheme = Constants.Services.apiScheme
47
         components.scheme = Constants.Services.apiScheme
48
         components.host = Constants.Services.apiHost
48
         components.host = Constants.Services.apiHost
49
         components.path = apiPath
49
         components.path = apiPath
50
-        components.queryItems = [
51
-            URLQueryItem(name: "user_id", value: "\(User.current.id!)"),
52
-        ]
50
+        if apiPath == Constants.Services.apiGetFlowersPath {
51
+            components.queryItems = [
52
+                URLQueryItem(name: "user_id", value: "\(User.current.id!)"),
53
+            ]
54
+        }
53
         return components
55
         return components
54
     }
56
     }
55
     
57
     
111
         
113
         
112
     }
114
     }
113
     
115
     
116
+    
117
+    func wishlistOrHistorySkeletonRequest(_ flowerID: Int, remove: Bool, wishlist: Bool) {
118
+        
119
+        // Construct Body
120
+        let jsonObject : [String: Int] = [
121
+            "user_id": User.current.id!,
122
+            "flower_id": flowerID
123
+        ]
124
+        
125
+        guard let jsonData = try? JSONEncoder().encode(jsonObject) else {
126
+            print("Failed to encode JSON for \(flowerID)")
127
+            return
128
+        }
129
+        
130
+        print(String(data: jsonData, encoding: .utf8)!)
131
+        
132
+        // Construct URL
133
+        var path: String
134
+        if remove {
135
+            if wishlist {
136
+                path = Constants.Services.apiRemoveFavoritePath
137
+            } else {
138
+                path = Constants.Services.apiRemoveFoundPath
139
+            }
140
+        } else {
141
+            if wishlist {
142
+                path = Constants.Services.apiPutFavoritePath
143
+            } else {
144
+                path = Constants.Services.apiPutFoundPath
145
+            }
146
+        }
147
+        
148
+        print((remove ? "removing " : "putting ") + (wishlist ? "favorite" : "found"))
149
+        let components = getBaseURLComponent(path)
150
+        
151
+        var request = URLRequest(url: components.url!)
152
+        request.httpMethod = "POST"
153
+        request.httpBody = jsonData
154
+        
155
+        // Send POST request
156
+        URLSession.shared.dataTask(with: request) { data, response, error in
157
+            print(response ?? "No response")
158
+            if let httpResponse = response as? HTTPURLResponse {
159
+                DispatchQueue.main.async {
160
+                    if httpResponse.statusCode == 200 {
161
+                        // alert that we removed favorite
162
+                        print("Success!")
163
+                    } else {
164
+                        // alert that we couldn't remove favorite
165
+                        print("Error! \(httpResponse.statusCode)")
166
+                    }
167
+                }
168
+            }
169
+        }.resume()
170
+    }
171
+    
172
+    
173
+    func removeFavorite(_ flowerID: Int) {
174
+        wishlistOrHistorySkeletonRequest(flowerID, remove: true, wishlist: true)
175
+    }
176
+    
177
+
178
+    func putFavorite(_ flowerID: Int) {
179
+        wishlistOrHistorySkeletonRequest(flowerID, remove: false, wishlist: true)
180
+    }
181
+    
182
+    
183
+    func removeFound(_ flowerID: Int) {
184
+        wishlistOrHistorySkeletonRequest(flowerID, remove: true, wishlist: false)
185
+    }
186
+
187
+    func putFound(_ flowerID: Int) {
188
+        wishlistOrHistorySkeletonRequest(flowerID, remove: false, wishlist: false)
189
+    }
190
+    
114
 }
191
 }

+ 4
- 0
Flowerdex/Flowerdex/Supporting/Constants.swift View File

20
         static let apiGetFlowersPath = "/~victor.hernandez17/flowerdex/listFlowers.php"
20
         static let apiGetFlowersPath = "/~victor.hernandez17/flowerdex/listFlowers.php"
21
         static let apiLoginPath = "/~victor.hernandez17/flowerdex/login.php"
21
         static let apiLoginPath = "/~victor.hernandez17/flowerdex/login.php"
22
         static let apiRegistrationPath = "/~victor.hernandez17/flowerdex/signup.php"
22
         static let apiRegistrationPath = "/~victor.hernandez17/flowerdex/signup.php"
23
+        static let apiPutFavoritePath = "/~victor.hernandez17/flowerdex/putFavoriteFlower.php"
24
+        static let apiRemoveFavoritePath = "/~victor.hernandez17/flowerdex/removeFavoriteFlower.php"
25
+        static let apiPutFoundPath = "/~victor.hernandez17/flowerdex/putFoundFlower.php"
26
+        static let apiRemoveFoundPath = "/~victor.hernandez17/flowerdex/removeFoundFlower.php"
23
     }
27
     }
24
     
28
     
25
     struct Colors {
29
     struct Colors {

+ 21
- 11
Flowerdex/Flowerdex/View/Discover Page/FlowerCard.swift View File

9
 
9
 
10
 struct FlowerCard: View {
10
 struct FlowerCard: View {
11
     
11
     
12
-    var flower: FlowerItem
12
+    var flower: Flower
13
     @ObservedObject var imageManager = ImageManager()
13
     @ObservedObject var imageManager = ImageManager()
14
     var size: CGFloat = 150
14
     var size: CGFloat = 150
15
     @Environment(\.colorScheme) var colorScheme
15
     @Environment(\.colorScheme) var colorScheme
24
                     .aspectRatio(contentMode: .fill)
24
                     .aspectRatio(contentMode: .fill)
25
                     .frame(width: self.size, height: self.size)
25
                     .frame(width: self.size, height: self.size)
26
                     .background(colorScheme == .dark ? Constants.Colors.darkGrayColor : Color.white)
26
                     .background(colorScheme == .dark ? Constants.Colors.darkGrayColor : Color.white)
27
-                CardDescription(commonName: self.flower.commonName, genus: self.flower.genus, family: self.flower.family, size: self.size, isFavorite: self.flower.isFavorite)
27
+                CardDescription(flower: flower, size: size, isFavoriteLocal: flower.isFavorite)
28
             }
28
             }
29
             
29
             
30
         }
30
         }
40
 
40
 
41
 struct CardDescription: View {
41
 struct CardDescription: View {
42
     
42
     
43
-    var commonName: String
44
-    var genus: String
45
-    var family: String
43
+    var flower: Flower
46
     var size: CGFloat
44
     var size: CGFloat
47
-    var isFavorite: Bool
45
+    @State var isFavoriteLocal: Bool
46
+    @EnvironmentObject var fModel: FlowerService
48
     @Environment(\.colorScheme) var colorScheme
47
     @Environment(\.colorScheme) var colorScheme
49
     
48
     
50
     var body: some View {
49
     var body: some View {
51
         VStack(alignment: .leading) {
50
         VStack(alignment: .leading) {
52
-            Text(self.commonName.capitalized)
51
+            Text(self.flower.commonName.capitalized)
53
                 .font(.headline)
52
                 .font(.headline)
54
             Spacer()
53
             Spacer()
55
             HStack {
54
             HStack {
56
-                Text(self.genus + " > " + self.family)
55
+                Text(self.flower.genus + " > " + self.flower.family)
57
                     .font(.caption)
56
                     .font(.caption)
58
                 Spacer()
57
                 Spacer()
59
-                Button(action: {print("hello")}) { // 
60
-                    if self.isFavorite {
58
+                Button(action: {
59
+                    
60
+                    // Depending on past value
61
+                    if self.isFavoriteLocal {
62
+                        fModel.removeFavorite(self.flower.id)
63
+                    } else {
64
+                        fModel.putFavorite(self.flower.id)
65
+                    }
66
+                    
67
+                    // Change value after request
68
+                    self.isFavoriteLocal.toggle()
69
+                    
70
+                }) {
71
+                    if self.isFavoriteLocal {
61
                         Image(systemName: "star.fill")
72
                         Image(systemName: "star.fill")
62
                             .foregroundColor(.yellow)
73
                             .foregroundColor(.yellow)
63
                     } else {
74
                     } else {
64
                         Image(systemName: "star")
75
                         Image(systemName: "star")
65
                             .foregroundColor(.black)
76
                             .foregroundColor(.black)
66
                     }
77
                     }
67
-                    
68
                 }
78
                 }
69
             }
79
             }
70
         }
80
         }

+ 19
- 7
Flowerdex/Flowerdex/View/Discover Page/FlowerDetailView.swift View File

9
 
9
 
10
 struct FlowerDetailView: View {
10
 struct FlowerDetailView: View {
11
     
11
     
12
-    var flower: FlowerItem
12
+    var flower: Flower
13
+    @State var hasBeenFoundLocal: Bool
13
     @ObservedObject var imageManager = ImageManager()
14
     @ObservedObject var imageManager = ImageManager()
14
-//    @ObservedObject var foundManager = FoundManager()
15
+    @EnvironmentObject var fModel: FlowerService
15
     var size: CGFloat = 300
16
     var size: CGFloat = 300
16
     
17
     
17
     var body: some View {
18
     var body: some View {
21
                     .font(.title)
22
                     .font(.title)
22
                     .fontWeight(/*@START_MENU_TOKEN@*/.semibold/*@END_MENU_TOKEN@*/)
23
                     .fontWeight(/*@START_MENU_TOKEN@*/.semibold/*@END_MENU_TOKEN@*/)
23
                     .foregroundColor(Constants.Colors.blueGray)
24
                     .foregroundColor(Constants.Colors.blueGray)
24
-                    
25
                 //                .frame(width: .infinity, alignment: .center)
25
                 //                .frame(width: .infinity, alignment: .center)
26
                 Spacer()
26
                 Spacer()
27
-                Button(action: {print("hello")}) { //self.hasBeenFound.toggle()
28
-                    if self.flower.hasBeenFound {
27
+                Button(action: {
28
+                    
29
+                    // Depending on past value
30
+                    if self.hasBeenFoundLocal {
31
+                        fModel.removeFound(self.flower.id)
32
+                    } else {
33
+                        fModel.putFound(self.flower.id)
34
+                    }
35
+                    
36
+                    // Change value after request
37
+                    self.hasBeenFoundLocal.toggle()
38
+                    
39
+                }) {
40
+                    if self.hasBeenFoundLocal {
29
                         Image(systemName: "eye")
41
                         Image(systemName: "eye")
30
                             .font(.title)
42
                             .font(.title)
31
                             .foregroundColor(Constants.Colors.rausch)
43
                             .foregroundColor(Constants.Colors.rausch)
59
 
71
 
60
 // TODO: account for text overflow
72
 // TODO: account for text overflow
61
 struct FlowerInformationPane: View {
73
 struct FlowerInformationPane: View {
62
-    var flower: FlowerItem
74
+    var flower: Flower
63
     var body: some View {
75
     var body: some View {
64
         HStack {
76
         HStack {
65
             VStack(alignment: .leading, spacing: nil) {
77
             VStack(alignment: .leading, spacing: nil) {
95
 
107
 
96
 struct FlowerDetailView_Previews: PreviewProvider {
108
 struct FlowerDetailView_Previews: PreviewProvider {
97
     static var previews: some View {
109
     static var previews: some View {
98
-        FlowerDetailView(flower: dummyFlowers[0])
110
+        FlowerDetailView(flower: dummyFlowers[0], hasBeenFoundLocal: true)
99
     }
111
     }
100
 }
112
 }

+ 2
- 2
Flowerdex/Flowerdex/View/Discover Page/FlowersList.swift View File

8
 import SwiftUI
8
 import SwiftUI
9
 
9
 
10
 struct FlowersList: View {
10
 struct FlowersList: View {
11
-    var flowerList: [FlowerItem]
11
+    var flowerList: [Flower]
12
     var body: some View {
12
     var body: some View {
13
         if flowerList.count == 0 {
13
         if flowerList.count == 0 {
14
             // TODO: make this centered vertically within parent ScrollView
14
             // TODO: make this centered vertically within parent ScrollView
16
         } else {
16
         } else {
17
             LazyVStack {
17
             LazyVStack {
18
                 ForEach(flowerList) { flower in
18
                 ForEach(flowerList) { flower in
19
-                    NavigationLink(destination: FlowerDetailView(flower: flower)) {
19
+                    NavigationLink(destination: FlowerDetailView(flower: flower, hasBeenFoundLocal: flower.hasBeenFound)) {
20
                         FlowerCard(flower: flower)
20
                         FlowerCard(flower: flower)
21
                     }
21
                     }
22
                     .foregroundColor(Constants.Colors.blueGray)
22
                     .foregroundColor(Constants.Colors.blueGray)