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
2 changes: 1 addition & 1 deletion Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 02c21c317ba9be4fdecdfff242f3fa20e9b269bd

COCOAPODS: 1.8.3
COCOAPODS: 1.8.4
12 changes: 8 additions & 4 deletions fakestagram.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
E0E8B971234916D100DA9D1A /* RestClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0E8B970234916D100DA9D1A /* RestClient.swift */; };
E0E8B974234918FF00DA9D1A /* Account.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0E8B973234918FF00DA9D1A /* Account.swift */; };
E0E8B9762349197100DA9D1A /* Post.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0E8B9752349197100DA9D1A /* Post.swift */; };
E13FE5C52389B5B5003BAA65 /* CreateLikeService.swift in Sources */ = {isa = PBXBuildFile; fileRef = E13FE5C42389B5B5003BAA65 /* CreateLikeService.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -114,6 +115,7 @@
E0E8B970234916D100DA9D1A /* RestClient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RestClient.swift; sourceTree = "<group>"; };
E0E8B973234918FF00DA9D1A /* Account.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Account.swift; sourceTree = "<group>"; };
E0E8B9752349197100DA9D1A /* Post.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Post.swift; sourceTree = "<group>"; };
E13FE5C42389B5B5003BAA65 /* CreateLikeService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreateLikeService.swift; sourceTree = "<group>"; };
E669E31C92D68155914FC99D /* Pods_fakestagramTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_fakestagramTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
FFAA8B9133CEE464C903FDF5 /* Pods_fakestagram.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_fakestagram.framework; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -154,6 +156,7 @@
children = (
E045844823762E10006574FA /* CreatePostService.swift */,
E0458456237725B9006574FA /* IndexService.swift */,
E13FE5C42389B5B5003BAA65 /* CreateLikeService.swift */,
);
path = Services;
sourceTree = "<group>";
Expand Down Expand Up @@ -520,6 +523,7 @@
E0E8B96C23481E1700DA9D1A /* HttpResponse.swift in Sources */,
E045844F23765B0F006574FA /* ImageStore.swift in Sources */,
E045844D23765677006574FA /* DataContainer.swift in Sources */,
E13FE5C52389B5B5003BAA65 /* CreateLikeService.swift in Sources */,
E0E8B9652348018200DA9D1A /* Credentials.swift in Sources */,
E0E8B971234916D100DA9D1A /* RestClient.swift in Sources */,
E084FADC233A8734009AC50D /* SceneDelegate.swift in Sources */,
Expand Down Expand Up @@ -689,13 +693,13 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = D3XL2U7DQC;
DEVELOPMENT_TEAM = RMQP856RM3;
INFOPLIST_FILE = fakestagram/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = com.3zcurdia.fakestagram;
PRODUCT_BUNDLE_IDENTIFIER = com.bruno.fakestagram;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "fakestagram/fakestagram-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
Expand All @@ -711,13 +715,13 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = D3XL2U7DQC;
DEVELOPMENT_TEAM = RMQP856RM3;
INFOPLIST_FILE = fakestagram/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = com.3zcurdia.fakestagram;
PRODUCT_BUNDLE_IDENTIFIER = com.bruno.fakestagram;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "fakestagram/fakestagram-Bridging-Header.h";
SWIFT_VERSION = 5.0;
Expand Down
8 changes: 6 additions & 2 deletions fakestagram/DataSource/RestClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ class RestClient<T: Codable> {
}

// eg. POST /posts/
func create(_ data: T, success: @escaping (T?) -> Void) {
func create(id: String? = nil, _ data: T, success: @escaping (T?) -> Void) {
var path = basePath
let payload = try? encoder.encode(data)
client.post(path: basePath, body: payload) { data in
if let uid = id {
path += "/\(uid)"
}
client.post(path: path, body: payload) { data in
CodableSerializer(data: data).async(result: success)
}
}
Expand Down
2 changes: 1 addition & 1 deletion fakestagram/Network/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Client {
debugPrint("Invalid request")
return
}

print(req.url)
session.dataTask(with: req) { (data, response, error) in
if let error = error {
debugPrint(error)
Expand Down
27 changes: 27 additions & 0 deletions fakestagram/Services/CreateLikeService.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// CreateLikeService.swift
// fakestagram
//
// Created by Bruno Torres on 23/11/19.
// Copyright © 2019 3zcurdia. All rights reserved.
//

import Foundation

struct CreateLike: Codable {
let id: String?
}

class CreateLikeService{
let clientLike = RestClient<CreateLike>(client: Client.fakestagram, basePath: "/api/v1/posts")

func createLike(id: String, success: @escaping (CreateLike?) -> Void){
let newLike = CreateLike(id: id)

clientLike.create(id: "\(id)/like", newLike, success: success)
print("------------------------")
clientLike.show(id: "\(id)/likes", success: success)
print("------------------------")
}

}
7 changes: 6 additions & 1 deletion fakestagram/Services/IndexService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@ import Foundation

class IndexService {
let client = RestClient<[Post]>(client: Client.fakestagram, basePath: "/api/v1/posts")

let clientLike = RestClient<[Like]>(client: Client.fakestagram, basePath: "/api/v1/posts")

func call(success: @escaping ([Post]?) -> Void) {
client.show(success: success)
}

func callLike(id: String,success: @escaping ([Like]?) -> Void) {
//clientLike.show(id: id,success: success)
}
}
2 changes: 1 addition & 1 deletion fakestagram/ViewControllers/CameraViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class CameraViewController: UIViewController {

func setupCaptureSession() {
session.beginConfiguration()
let device = AVCaptureDevice.default(.builtInDualCamera,
let device = AVCaptureDevice.default(.builtInWideAngleCamera,
for: .video, position: .back)!
guard let videoDeviceInput = try? AVCaptureDeviceInput(device: device),
session.canAddInput(videoDeviceInput) else { return }
Expand Down
19 changes: 18 additions & 1 deletion fakestagram/Views/PostCollectionViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ class PostCollectionViewCell: UICollectionViewCell {
@IBOutlet weak var likeBttn: UIButton!
@IBOutlet weak var commentBttn: UIButton!

let service = CreateLikeService()
let service2 = IndexService()

func reset() {
self.imageView.image = nil
self.likeCounter.text = ""
Expand All @@ -38,5 +41,19 @@ class PostCollectionViewCell: UICollectionViewCell {
self.imageView.image = img
}
}

@IBAction func likeButton(_ sender: UIButton) {
print("like")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dejas demasiados print para debug

if let id = post?.id{
service.createLike(id: "\(id)") { (like) in
print(like)
}
}

/*service2.callLike(id: "\(id)") { [unowned self] data in
print(data)

}*/

}

}
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="15701" 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="15703"/>
<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="Fkg-0r-yRP"/>
</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