diff --git a/fakestagram.xcodeproj/project.pbxproj b/fakestagram.xcodeproj/project.pbxproj index fd88dc7..acafb1b 100644 --- a/fakestagram.xcodeproj/project.pbxproj +++ b/fakestagram.xcodeproj/project.pbxproj @@ -8,6 +8,8 @@ /* 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 */; }; + 0ECA1F9823F50E180014023C /* CreateLikeServiceTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ECA1F9723F50E180014023C /* CreateLikeServiceTest.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 +65,8 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 0EA0E03F23F4CAE300F3E463 /* CreateLikeService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreateLikeService.swift; sourceTree = ""; }; + 0ECA1F9723F50E180014023C /* CreateLikeServiceTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreateLikeServiceTest.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 +158,7 @@ children = ( E045844823762E10006574FA /* CreatePostService.swift */, E0458456237725B9006574FA /* IndexService.swift */, + 0EA0E03F23F4CAE300F3E463 /* CreateLikeService.swift */, ); path = Services; sourceTree = ""; @@ -206,6 +211,7 @@ children = ( E0C93E952351472A00FD330C /* casettes */, E084FAF0233A8735009AC50D /* RequestBuilderTests.swift */, + 0ECA1F9723F50E180014023C /* CreateLikeServiceTest.swift */, E0C93E932351435100FD330C /* RestClientTest.swift */, E0458458237727D8006574FA /* CheckSumTest.swift */, E084FAF2233A8735009AC50D /* Info.plist */, @@ -520,6 +526,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 */, @@ -530,6 +537,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 0ECA1F9823F50E180014023C /* CreateLikeServiceTest.swift in Sources */, E0C93E942351435100FD330C /* RestClientTest.swift in Sources */, E084FAF1233A8735009AC50D /* RequestBuilderTests.swift in Sources */, E0458459237727D8006574FA /* CheckSumTest.swift in Sources */, @@ -689,13 +697,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 +719,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 +740,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 +763,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/Assets.xcassets/test_picture.imageset/Black_from_a_camera.jpg b/fakestagram/Assets.xcassets/test_picture.imageset/Black_from_a_camera.jpg new file mode 100644 index 0000000..4523ed9 Binary files /dev/null and b/fakestagram/Assets.xcassets/test_picture.imageset/Black_from_a_camera.jpg differ diff --git a/fakestagram/Assets.xcassets/test_picture.imageset/Contents.json b/fakestagram/Assets.xcassets/test_picture.imageset/Contents.json new file mode 100644 index 0000000..ac638a0 --- /dev/null +++ b/fakestagram/Assets.xcassets/test_picture.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "Black_from_a_camera.jpg", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file 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 new file mode 100644 index 0000000..a829fd8 --- /dev/null +++ b/fakestagram/Services/CreateLikeService.swift @@ -0,0 +1,25 @@ +// +// 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 (String?) -> Void) { + let basePath = "/api/v1/posts/\(postId)/like" + client.post(path: basePath, body: nil) { data in + CodableSerializer(data: data).async(result: {like in success(like?.createdAt)}) + } + } + + +} 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) 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 @@