From b4b15a7e80b4ed4faf53dfe2dcfce779508add0a Mon Sep 17 00:00:00 2001 From: jhovan Date: Sat, 23 Nov 2019 11:32:46 -0600 Subject: [PATCH 1/4] =?UTF-8?q?Se=20cambio=20el=20tipo=20de=20camara=20a?= =?UTF-8?q?=20uno=20m=C3=A1s=20general?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fakestagram.xcodeproj/project.pbxproj | 12 ++++++------ fakestagram/AppDelegate.swift | 2 +- .../ViewControllers/CameraViewController.swift | 5 +++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/fakestagram.xcodeproj/project.pbxproj b/fakestagram.xcodeproj/project.pbxproj index fd88dc7..04ce79d 100644 --- a/fakestagram.xcodeproj/project.pbxproj +++ b/fakestagram.xcodeproj/project.pbxproj @@ -689,13 +689,13 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CODE_SIGN_STYLE = Automatic; - DEVELOPMENT_TEAM = D3XL2U7DQC; + DEVELOPMENT_TEAM = Z27ZTUPSJC; INFOPLIST_FILE = fakestagram/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", ); - PRODUCT_BUNDLE_IDENTIFIER = com.3zcurdia.fakestagram; + PRODUCT_BUNDLE_IDENTIFIER = com.jhovan.fakestagram; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "fakestagram/fakestagram-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; @@ -711,13 +711,13 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CODE_SIGN_STYLE = Automatic; - DEVELOPMENT_TEAM = D3XL2U7DQC; + DEVELOPMENT_TEAM = Z27ZTUPSJC; INFOPLIST_FILE = fakestagram/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", ); - PRODUCT_BUNDLE_IDENTIFIER = com.3zcurdia.fakestagram; + PRODUCT_BUNDLE_IDENTIFIER = com.jhovan.fakestagram; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "fakestagram/fakestagram-Bridging-Header.h"; SWIFT_VERSION = 5.0; @@ -732,7 +732,7 @@ ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; BUNDLE_LOADER = "$(TEST_HOST)"; CODE_SIGN_STYLE = Automatic; - DEVELOPMENT_TEAM = D3XL2U7DQC; + DEVELOPMENT_TEAM = Z27ZTUPSJC; INFOPLIST_FILE = fakestagramTests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 13.0; LD_RUNPATH_SEARCH_PATHS = ( @@ -755,7 +755,7 @@ ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; BUNDLE_LOADER = "$(TEST_HOST)"; CODE_SIGN_STYLE = Automatic; - DEVELOPMENT_TEAM = D3XL2U7DQC; + DEVELOPMENT_TEAM = Z27ZTUPSJC; INFOPLIST_FILE = fakestagramTests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 13.0; LD_RUNPATH_SEARCH_PATHS = ( diff --git a/fakestagram/AppDelegate.swift b/fakestagram/AppDelegate.swift index 2660552..6be5d79 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: "José Gallardo", 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/ViewControllers/CameraViewController.swift b/fakestagram/ViewControllers/CameraViewController.swift index a7996c7..dfac05b 100644 --- a/fakestagram/ViewControllers/CameraViewController.swift +++ b/fakestagram/ViewControllers/CameraViewController.swift @@ -99,8 +99,9 @@ class CameraViewController: UIViewController { func setupCaptureSession() { session.beginConfiguration() - let device = AVCaptureDevice.default(.builtInDualCamera, - for: .video, position: .back)! + //let device = AVCaptureDevice.default(.builtInDualCamera, + let device = AVCaptureDevice.default(.builtInWideAngleCamera, + for: .video, position: .unspecified)! guard let videoDeviceInput = try? AVCaptureDeviceInput(device: device), session.canAddInput(videoDeviceInput) else { return } session.addInput(videoDeviceInput) From e3eb34e544f229cb17f0b82a4579e95015f3351a Mon Sep 17 00:00:00 2001 From: jhovan Date: Wed, 12 Feb 2020 18:32:12 -0600 Subject: [PATCH 2/4] Implement call method --- fakestagram.xcodeproj/project.pbxproj | 4 ++++ fakestagram/Services/CreateLikeService.swift | 23 ++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 fakestagram/Services/CreateLikeService.swift diff --git a/fakestagram.xcodeproj/project.pbxproj b/fakestagram.xcodeproj/project.pbxproj index 04ce79d..eb804d1 100644 --- a/fakestagram.xcodeproj/project.pbxproj +++ b/fakestagram.xcodeproj/project.pbxproj @@ -8,6 +8,7 @@ /* Begin PBXBuildFile section */ 05D8E963168944918FFCC7FF /* Pods_fakestagram.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FFAA8B9133CEE464C903FDF5 /* Pods_fakestagram.framework */; }; + 0EA0E04023F4CAE300F3E463 /* CreateLikeService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EA0E03F23F4CAE300F3E463 /* CreateLikeService.swift */; }; D3D164DC7444072103DE027D /* Pods_fakestagramTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E669E31C92D68155914FC99D /* Pods_fakestagramTests.framework */; }; E023A5542380859200B13B7D /* NotificationKeys.swift in Sources */ = {isa = PBXBuildFile; fileRef = E023A5532380859200B13B7D /* NotificationKeys.swift */; }; E038FCED233FC78600E28571 /* PostViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E038FCEC233FC78600E28571 /* PostViewController.swift */; }; @@ -63,6 +64,7 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 0EA0E03F23F4CAE300F3E463 /* CreateLikeService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreateLikeService.swift; sourceTree = ""; }; 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 = ""; }; @@ -154,6 +156,7 @@ children = ( E045844823762E10006574FA /* CreatePostService.swift */, E0458456237725B9006574FA /* IndexService.swift */, + 0EA0E03F23F4CAE300F3E463 /* CreateLikeService.swift */, ); path = Services; sourceTree = ""; @@ -520,6 +523,7 @@ E0E8B96C23481E1700DA9D1A /* HttpResponse.swift in Sources */, E045844F23765B0F006574FA /* ImageStore.swift in Sources */, E045844D23765677006574FA /* DataContainer.swift in Sources */, + 0EA0E04023F4CAE300F3E463 /* CreateLikeService.swift in Sources */, E0E8B9652348018200DA9D1A /* Credentials.swift in Sources */, E0E8B971234916D100DA9D1A /* RestClient.swift in Sources */, E084FADC233A8734009AC50D /* SceneDelegate.swift in Sources */, diff --git a/fakestagram/Services/CreateLikeService.swift b/fakestagram/Services/CreateLikeService.swift new file mode 100644 index 0000000..6639e3e --- /dev/null +++ b/fakestagram/Services/CreateLikeService.swift @@ -0,0 +1,23 @@ +// +// CreateLikeService.swift +// fakestagram +// +// Created by Jhovan Gallardo on 12/02/20. +// Copyright © 2020 3zcurdia. All rights reserved. +// + +import Foundation + + +class CreateLikeService { + + let client: Client = Client.fakestagram + + func call(postId: String, success: @escaping (Int?) -> Void) { + let basePath = "/api/v1/posts/\(postId)/like" + client.post(path: basePath, body: nil) { data in + CodableSerializer(data: data).async(result: success) + } + } + +} From be6fdeacbe0b5cc0915db5cea10814cfed04ab94 Mon Sep 17 00:00:00 2001 From: jhovan Date: Wed, 12 Feb 2020 22:37:19 -0600 Subject: [PATCH 3/4] Implement like feature --- fakestagram/Models/Author.swift | 1 + fakestagram/Models/Like.swift | 2 ++ fakestagram/Services/CreateLikeService.swift | 6 ++++-- fakestagram/Views/PostCollectionViewCell.swift | 15 +++++++++++++++ fakestagram/Views/PostCollectionViewCell.xib | 7 +++++-- 5 files changed, 27 insertions(+), 4 deletions(-) diff --git a/fakestagram/Models/Author.swift b/fakestagram/Models/Author.swift index 607dad2..68ba143 100644 --- a/fakestagram/Models/Author.swift +++ b/fakestagram/Models/Author.swift @@ -10,4 +10,5 @@ import Foundation struct Author: Codable { let name: String + let id: String } diff --git a/fakestagram/Models/Like.swift b/fakestagram/Models/Like.swift index 5b2ba6f..78cf12a 100644 --- a/fakestagram/Models/Like.swift +++ b/fakestagram/Models/Like.swift @@ -9,5 +9,7 @@ import Foundation struct Like: Codable { + let createdAt: String + let updatedAt: String let author: Author } diff --git a/fakestagram/Services/CreateLikeService.swift b/fakestagram/Services/CreateLikeService.swift index 6639e3e..a829fd8 100644 --- a/fakestagram/Services/CreateLikeService.swift +++ b/fakestagram/Services/CreateLikeService.swift @@ -11,13 +11,15 @@ import Foundation class CreateLikeService { + let client: Client = Client.fakestagram - func call(postId: String, success: @escaping (Int?) -> Void) { + func call(postId: String, success: @escaping (String?) -> Void) { let basePath = "/api/v1/posts/\(postId)/like" client.post(path: basePath, body: nil) { data in - CodableSerializer(data: data).async(result: success) + CodableSerializer(data: data).async(result: {like in success(like?.createdAt)}) } } + } diff --git a/fakestagram/Views/PostCollectionViewCell.swift b/fakestagram/Views/PostCollectionViewCell.swift index 1d5be7b..a1cdcf1 100644 --- a/fakestagram/Views/PostCollectionViewCell.swift +++ b/fakestagram/Views/PostCollectionViewCell.swift @@ -9,6 +9,8 @@ import UIKit class PostCollectionViewCell: UICollectionViewCell { + let service = CreateLikeService() + static let identifier: String = "PostCell" public var post: Post? { didSet { @@ -38,5 +40,18 @@ class PostCollectionViewCell: UICollectionViewCell { self.imageView.image = img } } + + @IBAction func likeButton(_ sender: Any) { + guard var post = self.post else { return } + guard let postId = post.id else {return} + print("Se presiono like en post: \(postId)") + service.call(postId: String(postId)){ creationDate in + print("Liked Successfully! \(creationDate ?? "")") + } + post.likesCount += 1 + self.likeCounter.text = post.likesCountText() + } + + } diff --git a/fakestagram/Views/PostCollectionViewCell.xib b/fakestagram/Views/PostCollectionViewCell.xib index afff929..3b2ad23 100644 --- a/fakestagram/Views/PostCollectionViewCell.xib +++ b/fakestagram/Views/PostCollectionViewCell.xib @@ -1,8 +1,8 @@ - + - + @@ -36,6 +36,9 @@