From 78544dc45386b9faa1f4df1d3fcdacad67893a61 Mon Sep 17 00:00:00 2001 From: lgachuz Date: Sat, 23 Nov 2019 13:53:20 -0600 Subject: [PATCH] Create like in photo --- Podfile.lock | 2 +- fakestagram.xcodeproj/project.pbxproj | 12 ++++-- fakestagram/AppDelegate.swift | 2 +- fakestagram/Services/CreateLikeService.swift | 40 +++++++++++++++++++ .../Views/PostCollectionViewCell.swift | 18 +++++++++ fakestagram/Views/PostCollectionViewCell.xib | 7 +++- 6 files changed, 73 insertions(+), 8 deletions(-) create mode 100644 fakestagram/Services/CreateLikeService.swift diff --git a/Podfile.lock b/Podfile.lock index 12505e8..b5bd883 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -17,4 +17,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: 02c21c317ba9be4fdecdfff242f3fa20e9b269bd -COCOAPODS: 1.8.3 +COCOAPODS: 1.8.4 diff --git a/fakestagram.xcodeproj/project.pbxproj b/fakestagram.xcodeproj/project.pbxproj index fd88dc7..9db9342 100644 --- a/fakestagram.xcodeproj/project.pbxproj +++ b/fakestagram.xcodeproj/project.pbxproj @@ -9,6 +9,7 @@ /* Begin PBXBuildFile section */ 05D8E963168944918FFCC7FF /* Pods_fakestagram.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FFAA8B9133CEE464C903FDF5 /* Pods_fakestagram.framework */; }; D3D164DC7444072103DE027D /* Pods_fakestagramTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E669E31C92D68155914FC99D /* Pods_fakestagramTests.framework */; }; + D41C4B892389B50800B4FD2E /* CreateLikeService.swift in Sources */ = {isa = PBXBuildFile; fileRef = D41C4B882389B50800B4FD2E /* CreateLikeService.swift */; }; E023A5542380859200B13B7D /* NotificationKeys.swift in Sources */ = {isa = PBXBuildFile; fileRef = E023A5532380859200B13B7D /* NotificationKeys.swift */; }; E038FCED233FC78600E28571 /* PostViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E038FCEC233FC78600E28571 /* PostViewController.swift */; }; E045844923762E10006574FA /* CreatePostService.swift in Sources */ = {isa = PBXBuildFile; fileRef = E045844823762E10006574FA /* CreatePostService.swift */; }; @@ -66,6 +67,7 @@ 5E0AE2BFBF9C8D81E583E1BE /* Pods-fakestagramTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-fakestagramTests.release.xcconfig"; path = "Target Support Files/Pods-fakestagramTests/Pods-fakestagramTests.release.xcconfig"; sourceTree = ""; }; 66342726A6BCEEEF6289B1AA /* Pods-fakestagramTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-fakestagramTests.debug.xcconfig"; path = "Target Support Files/Pods-fakestagramTests/Pods-fakestagramTests.debug.xcconfig"; sourceTree = ""; }; CCC6C6EA9D17CA169951A745 /* Pods-fakestagram.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-fakestagram.release.xcconfig"; path = "Target Support Files/Pods-fakestagram/Pods-fakestagram.release.xcconfig"; sourceTree = ""; }; + D41C4B882389B50800B4FD2E /* CreateLikeService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreateLikeService.swift; sourceTree = ""; }; DB68F7FEC717545506064663 /* Pods-fakestagram.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-fakestagram.debug.xcconfig"; path = "Target Support Files/Pods-fakestagram/Pods-fakestagram.debug.xcconfig"; sourceTree = ""; }; E023A5532380859200B13B7D /* NotificationKeys.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationKeys.swift; sourceTree = ""; }; E038FCEC233FC78600E28571 /* PostViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostViewController.swift; sourceTree = ""; }; @@ -154,6 +156,7 @@ children = ( E045844823762E10006574FA /* CreatePostService.swift */, E0458456237725B9006574FA /* IndexService.swift */, + D41C4B882389B50800B4FD2E /* CreateLikeService.swift */, ); path = Services; sourceTree = ""; @@ -520,6 +523,7 @@ E0E8B96C23481E1700DA9D1A /* HttpResponse.swift in Sources */, E045844F23765B0F006574FA /* ImageStore.swift in Sources */, E045844D23765677006574FA /* DataContainer.swift in Sources */, + D41C4B892389B50800B4FD2E /* CreateLikeService.swift in Sources */, E0E8B9652348018200DA9D1A /* Credentials.swift in Sources */, E0E8B971234916D100DA9D1A /* RestClient.swift in Sources */, E084FADC233A8734009AC50D /* SceneDelegate.swift in Sources */, @@ -689,13 +693,13 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CODE_SIGN_STYLE = Automatic; - DEVELOPMENT_TEAM = D3XL2U7DQC; + DEVELOPMENT_TEAM = UF4G86QXSG; INFOPLIST_FILE = fakestagram/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", ); - PRODUCT_BUNDLE_IDENTIFIER = com.3zcurdia.fakestagram; + PRODUCT_BUNDLE_IDENTIFIER = com.3zcurdia.fakestagrampoi; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "fakestagram/fakestagram-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; @@ -711,13 +715,13 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CODE_SIGN_STYLE = Automatic; - DEVELOPMENT_TEAM = D3XL2U7DQC; + DEVELOPMENT_TEAM = UF4G86QXSG; INFOPLIST_FILE = fakestagram/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", ); - PRODUCT_BUNDLE_IDENTIFIER = com.3zcurdia.fakestagram; + PRODUCT_BUNDLE_IDENTIFIER = com.3zcurdia.fakestagrampoi; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "fakestagram/fakestagram-Bridging-Header.h"; SWIFT_VERSION = 5.0; diff --git a/fakestagram/AppDelegate.swift b/fakestagram/AppDelegate.swift index 2660552..4b142c3 100644 --- a/fakestagram/AppDelegate.swift +++ b/fakestagram/AppDelegate.swift @@ -35,7 +35,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { func loadOrCreateAccount() { if Credentials.apiToken.get() != nil { return } - let account = Account(id: nil, name: "Juan Camaney", deviceNumber: UIDevice.identifier, deviceModel: UIDevice.modelName) + let account = Account(id: nil, name: "Luisito Comunica", deviceNumber: UIDevice.identifier, deviceModel: UIDevice.modelName) let client = RestClient(client: Client.fakestagram, basePath: "/api/v1/accounts") client.create(account) { account in guard let account = account, let idx = account.id else { return } diff --git a/fakestagram/Services/CreateLikeService.swift b/fakestagram/Services/CreateLikeService.swift new file mode 100644 index 0000000..5b84386 --- /dev/null +++ b/fakestagram/Services/CreateLikeService.swift @@ -0,0 +1,40 @@ +// +// CreateLikeService.swift +// fakestagram +// +// Created by Luis Alberto Gachuz Morales on 23/11/19. +// Copyright © 2019 3zcurdia. All rights reserved. +// + +import Foundation +import UIKit +import CoreLocation + +struct CreateLike: Codable { + let id: Int +} + +//protocol Geolocable { +// func update(coordinate: CLLocationCoordinate2D?) +//} + +class CreateLikeService { + + // let client = RestClient(client: Client.fakestagram, basePath: "/api/v1/like/") + + func call(id: Int, success: @escaping (Int?) -> Void) { + let newLike = CreateLike( + id:id + ) + + let client = RestClient(client: Client.fakestagram, basePath: "/api/v1/posts/ \(newLike.id)/like") + + print("LGMMMMMMMMMMMMMMMM \(newLike.id)") + + + client.create(newLike) { post in + NotificationCenter.default.post(name: NotificationKeys.didFinishPostCreation.value, object: nil) + success(post?.id) + } + } +} diff --git a/fakestagram/Views/PostCollectionViewCell.swift b/fakestagram/Views/PostCollectionViewCell.swift index 1d5be7b..1d14e42 100644 --- a/fakestagram/Views/PostCollectionViewCell.swift +++ b/fakestagram/Views/PostCollectionViewCell.swift @@ -15,6 +15,10 @@ class PostCollectionViewCell: UICollectionViewCell { updateView() } } + + let service = CreateLikeService() + + @IBOutlet weak var authorView: AuthorView! @IBOutlet weak var imageView: UIImageView! @IBOutlet weak var likeCounter: UILabel! @@ -38,5 +42,19 @@ class PostCollectionViewCell: UICollectionViewCell { self.imageView.image = img } } + + + @IBAction func onTapLike(_ sender: Any) { + print("like") + + + print(self.post?.id ?? 319) + + service.call(id: self.post?.id ?? 359) { postId in + print("Successful!") + + print(postId ?? -1) + } + } } diff --git a/fakestagram/Views/PostCollectionViewCell.xib b/fakestagram/Views/PostCollectionViewCell.xib index afff929..ef7bca3 100644 --- a/fakestagram/Views/PostCollectionViewCell.xib +++ b/fakestagram/Views/PostCollectionViewCell.xib @@ -1,8 +1,8 @@ - + - + @@ -36,6 +36,9 @@