Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions fakestagram.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -63,6 +65,8 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
0EA0E03F23F4CAE300F3E463 /* CreateLikeService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreateLikeService.swift; sourceTree = "<group>"; };
0ECA1F9723F50E180014023C /* CreateLikeServiceTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreateLikeServiceTest.swift; sourceTree = "<group>"; };
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 = "<group>"; };
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 = "<group>"; };
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 = "<group>"; };
Expand Down Expand Up @@ -154,6 +158,7 @@
children = (
E045844823762E10006574FA /* CreatePostService.swift */,
E0458456237725B9006574FA /* IndexService.swift */,
0EA0E03F23F4CAE300F3E463 /* CreateLikeService.swift */,
);
path = Services;
sourceTree = "<group>";
Expand Down Expand Up @@ -206,6 +211,7 @@
children = (
E0C93E952351472A00FD330C /* casettes */,
E084FAF0233A8735009AC50D /* RequestBuilderTests.swift */,
0ECA1F9723F50E180014023C /* CreateLikeServiceTest.swift */,
E0C93E932351435100FD330C /* RestClientTest.swift */,
E0458458237727D8006574FA /* CheckSumTest.swift */,
E084FAF2233A8735009AC50D /* Info.plist */,
Expand Down Expand Up @@ -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 */,
Expand All @@ -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 */,
Expand Down Expand Up @@ -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";
Expand All @@ -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;
Expand All @@ -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 = (
Expand All @@ -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 = (
Expand Down
2 changes: 1 addition & 1 deletion fakestagram/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Account>(client: Client.fakestagram, basePath: "/api/v1/accounts")
client.create(account) { account in
guard let account = account, let idx = account.id else { return }
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions fakestagram/Assets.xcassets/test_picture.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
1 change: 1 addition & 0 deletions fakestagram/Models/Author.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ import Foundation

struct Author: Codable {
let name: String
let id: String
}
2 changes: 2 additions & 0 deletions fakestagram/Models/Like.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@
import Foundation

struct Like: Codable {
let createdAt: String
let updatedAt: String
let author: Author
}
25 changes: 25 additions & 0 deletions fakestagram/Services/CreateLikeService.swift
Original file line number Diff line number Diff line change
@@ -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<Like>(data: data).async(result: {like in success(like?.createdAt)})
}
}


}
5 changes: 3 additions & 2 deletions fakestagram/ViewControllers/CameraViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions fakestagram/Views/PostCollectionViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import UIKit

class PostCollectionViewCell: UICollectionViewCell {
let service = CreateLikeService()

static let identifier: String = "PostCell"
public var post: Post? {
didSet {
Expand Down Expand Up @@ -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()
}



}
7 changes: 5 additions & 2 deletions fakestagram/Views/PostCollectionViewCell.xib
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="15400" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="15705" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15404"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15706"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
Expand Down Expand Up @@ -36,6 +36,9 @@
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="ata-8B-MoQ">
<rect key="frame" x="0.0" y="0.0" width="20.5" height="22"/>
<state key="normal" image="heart" catalog="system"/>
<connections>
<action selector="likeButton:" destination="gTV-IL-0wX" eventType="touchUpInside" id="Zpn-LN-nC0"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="8XJ-Ma-oEM">
<rect key="frame" x="23.5" y="0.0" width="22.5" height="22"/>
Expand Down
76 changes: 76 additions & 0 deletions fakestagramTests/CreateLikeServiceTest.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
//
// CreateLikeServiceTest.swift
// fakestagramTests
//
// Created by Jhovan Gallardo on 12/02/20.
// Copyright © 2020 3zcurdia. All rights reserved.
//

import XCTest
@testable import fakestagram

class CreateLikeServiceTest: XCTestCase {

var postId: Int = 0
var posts: [Post]? = []

func testInvalidLike() {
let likeSertvice = CreateLikeService()
XCTAssertNoThrow(likeSertvice.call(postId:"Invalid PostId"){_ in })
}


// La idea era verificar el número de likes en un post
// pero no se exactamente porque ningun servicio esta haciendo lo que deberia
func testCreateLike() {
// crea un post
let postService = CreatePostService()
postService.call(image: UIImage(named: "test_picture")!, title: "Prueba") {postId in self.postId = postId!}
// crea un like para el post creado
let likeSertvice = CreateLikeService()
likeSertvice.call(postId: String(self.postId)){_ in }
let indexService = IndexService()
indexService.call { [unowned self] data in
self.posts = data
}
guard let posts = self.posts else {return}
var likes = 0
// busca el post creado y obtiene su numero de likes
for post in posts {
if post.id == self.postId {
likes = post.likesCount
break
}
}
XCTAssertEqual(likes, 1)

}

// La idea era verificar el número de likes en un post
// pero no se exactamente porque ningun servicio esta haciendo lo que deberia
func testRepeatedLike() {
// crea un post
let postService = CreatePostService()
postService.call(image: UIImage(named: "test_picture")!, title: "Prueba") {postId in self.postId = postId!}
let likeSertvice = CreateLikeService()
// hace like dos veces sobre el post creado
likeSertvice.call(postId: String(self.postId)){_ in }
likeSertvice.call(postId: String(self.postId)){_ in }
let indexService = IndexService()
indexService.call { [unowned self] data in
self.posts = data
}
guard let posts = self.posts else {return}
var likes = 0
// busca el post creado y obtiene su numero de likes
for post in posts {
if post.id == self.postId {
likes = post.likesCount
break
}
}
XCTAssertEqual(likes, 1)
}


}