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: 12 additions & 0 deletions fakestagram.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

/* Begin PBXBuildFile section */
05D8E963168944918FFCC7FF /* Pods_fakestagram.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FFAA8B9133CEE464C903FDF5 /* Pods_fakestagram.framework */; };
98A0E6D32389B32B005349A8 /* PostDetailController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98A0E6D22389B32B005349A8 /* PostDetailController.swift */; };
98A0E6D52389BC54005349A8 /* CommentsService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98A0E6D42389BC54005349A8 /* CommentsService.swift */; };
98F533E123EB3AF500C4994F /* CommentTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98F533E023EB3AF500C4994F /* CommentTableViewCell.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 @@ -65,6 +68,9 @@
/* Begin PBXFileReference section */
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>"; };
98A0E6D22389B32B005349A8 /* PostDetailController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostDetailController.swift; sourceTree = "<group>"; };
98A0E6D42389BC54005349A8 /* CommentsService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommentsService.swift; sourceTree = "<group>"; };
98F533E023EB3AF500C4994F /* CommentTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommentTableViewCell.swift; 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>"; };
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 = "<group>"; };
E023A5532380859200B13B7D /* NotificationKeys.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationKeys.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -154,6 +160,7 @@
children = (
E045844823762E10006574FA /* CreatePostService.swift */,
E0458456237725B9006574FA /* IndexService.swift */,
98A0E6D42389BC54005349A8 /* CommentsService.swift */,
);
path = Services;
sourceTree = "<group>";
Expand Down Expand Up @@ -231,6 +238,7 @@
E0C93E9F23523B7C00FD330C /* ShowPostViewController.swift */,
E0C93EA023523B7C00FD330C /* ShowPostViewController.xib */,
E0C93EA32352452900FD330C /* AuthorView.swift */,
98F533E023EB3AF500C4994F /* CommentTableViewCell.swift */,
);
path = Views;
sourceTree = "<group>";
Expand All @@ -241,6 +249,7 @@
E0A9ED50235A782F00A0527E /* PostsViewController.swift */,
E038FCEC233FC78600E28571 /* PostViewController.swift */,
E0E25462235B675100C55767 /* CameraViewController.swift */,
98A0E6D22389B32B005349A8 /* PostDetailController.swift */,
);
path = ViewControllers;
sourceTree = "<group>";
Expand Down Expand Up @@ -514,12 +523,15 @@
E0E8B96E2348203B00DA9D1A /* RequestBuilder.swift in Sources */,
E0E8B9682348036D00DA9D1A /* Client.swift in Sources */,
E0A9ED51235A782F00A0527E /* PostsViewController.swift in Sources */,
98A0E6D52389BC54005349A8 /* CommentsService.swift in Sources */,
98F533E123EB3AF500C4994F /* CommentTableViewCell.swift in Sources */,
E045844923762E10006574FA /* CreatePostService.swift in Sources */,
E0C93EA62352454E00FD330C /* Author.swift in Sources */,
E0A9ED54235A7FF300A0527E /* PostCollectionViewCell.swift in Sources */,
E0E8B96C23481E1700DA9D1A /* HttpResponse.swift in Sources */,
E045844F23765B0F006574FA /* ImageStore.swift in Sources */,
E045844D23765677006574FA /* DataContainer.swift in Sources */,
98A0E6D32389B32B005349A8 /* PostDetailController.swift in Sources */,
E0E8B9652348018200DA9D1A /* Credentials.swift in Sources */,
E0E8B971234916D100DA9D1A /* RestClient.swift in Sources */,
E084FADC233A8734009AC50D /* SceneDelegate.swift in Sources */,
Expand Down
35 changes: 27 additions & 8 deletions fakestagram/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="15505" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="If5-ZY-Hbn">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15509"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15510"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="collection view cell content view" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Posts-->
<!--Posts View Controller-->
<scene sceneID="lO2-2D-4VX">
<objects>
<viewController id="meV-Lo-Xew" customClass="PostsViewController" customModule="fakestagram" customModuleProvider="target" sceneMemberID="viewController">
Expand All @@ -17,7 +17,7 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<collectionView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" dataMode="prototypes" translatesAutoresizingMaskIntoConstraints="NO" id="GUj-0c-2jm">
<rect key="frame" x="0.0" y="84" width="414" height="729"/>
<rect key="frame" x="0.0" y="128" width="414" height="685"/>
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<collectionViewFlowLayout key="collectionViewLayout" automaticEstimatedItemSize="YES" minimumLineSpacing="10" minimumInteritemSpacing="10" id="X3D-S2-gdp">
<size key="itemSize" width="50" height="50"/>
Expand Down Expand Up @@ -46,14 +46,14 @@
</constraints>
<viewLayoutGuide key="safeArea" id="0CG-4P-XO3"/>
</view>
<tabBarItem key="tabBarItem" title="Posts" image="approval" id="SFK-Ca-EVC"/>
<navigationItem key="navigationItem" id="RA2-1a-8XS"/>
<connections>
<outlet property="postsCollection" destination="GUj-0c-2jm" id="gbo-Zg-ToX"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="RVi-7j-73s" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-788.40579710144937" y="813.61607142857144"/>
<point key="canvasLocation" x="121.73913043478262" y="813.61607142857144"/>
</scene>
<!--Create-->
<scene sceneID="U2O-nr-Rge">
Expand Down Expand Up @@ -99,7 +99,7 @@
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="fHk-vx-Qau" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-97.101449275362327" y="813.61607142857144"/>
<point key="canvasLocation" x="813.04347826086962" y="813.61607142857144"/>
</scene>
<!--Profile-->
<scene sceneID="tAT-aD-rp5">
Expand All @@ -115,7 +115,7 @@
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="QYl-l8-chu" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="641" y="814"/>
<point key="canvasLocation" x="1550.7246376811595" y="813.61607142857144"/>
</scene>
<!--Tab Bar Controller-->
<scene sceneID="Cdf-t9-xtw">
Expand All @@ -128,7 +128,7 @@
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</tabBar>
<connections>
<segue destination="meV-Lo-Xew" kind="relationship" relationship="viewControllers" id="h5r-ai-b30"/>
<segue destination="816-N3-Nm9" kind="relationship" relationship="viewControllers" id="h5r-ai-b30"/>
<segue destination="Tt7-wh-Hav" kind="relationship" relationship="viewControllers" id="api-1x-Rn2"/>
<segue destination="ZJW-ti-eoH" kind="relationship" relationship="viewControllers" id="dvS-MI-idI"/>
</connections>
Expand All @@ -137,6 +137,25 @@
</objects>
<point key="canvasLocation" x="-97.101449275362327" y="96.428571428571431"/>
</scene>
<!--Posts-->
<scene sceneID="KB4-M7-XRC">
<objects>
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="816-N3-Nm9" sceneMemberID="viewController">
<tabBarItem key="tabBarItem" title="Posts" image="approval" id="SFK-Ca-EVC"/>
<toolbarItems/>
<navigationBar key="navigationBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="ihC-x4-Aso">
<rect key="frame" x="0.0" y="44" width="414" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<nil name="viewControllers"/>
<connections>
<segue destination="meV-Lo-Xew" kind="relationship" relationship="rootViewController" id="Vcq-PC-vgH"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="W3x-o4-lhX" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-788.40579710144937" y="813.61607142857144"/>
</scene>
</scenes>
<resources>
<image name="approval" width="30" height="30"/>
Expand Down
17 changes: 17 additions & 0 deletions fakestagram/Services/CommentsService.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// GetCommentsService.swift
// fakestagram
//
// Created by Ma. de Lourdes Chaparro Candiani on 11/23/19.
// Copyright © 2019 3zcurdia. All rights reserved.
//

import Foundation

class CommentsService {

func getComments(postId: Int, success: @escaping ([Comment]?) -> Void) {
let client = RestClient<[Comment]>(client: Client.fakestagram, basePath: "/api/v1/posts/\(postId)/comments")
client.show(success: success)
}
}
107 changes: 107 additions & 0 deletions fakestagram/ViewControllers/PostDetailController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
//
// PostDetailController.swift
// fakestagram
//
// Created by Ma. de Lourdes Chaparro Candiani on 11/23/19.
// Copyright © 2019 3zcurdia. All rights reserved.
//

import UIKit

class PostDetailController: UIViewController, UITableViewDelegate, UITableViewDataSource {

var postData: Post!
let commentsService = CommentsService()
let cellIdentifier = "commentCell"

var comments: [Comment]? {
didSet {
self.commentsTable.reloadData()
}
}

let postImage: UIImageView = {
let imgView = UIImageView()
imgView.translatesAutoresizingMaskIntoConstraints = false
imgView.contentMode = .scaleAspectFit
return imgView
}()

let postTitle: UILabel = {
let titleLabel = UILabel()
titleLabel.translatesAutoresizingMaskIntoConstraints = false
titleLabel.textColor = .white
titleLabel.font = UIFont(name: "System Semibold", size: 25)
return titleLabel
}()

let likesCounter: UILabel = {
let likesLabel = UILabel()
likesLabel.translatesAutoresizingMaskIntoConstraints = false
likesLabel.textColor = .white
likesLabel.font = UIFont(name: "System", size: 25)
return likesLabel
}()

let commentsTable: UITableView = {
let comments = UITableView()
comments.translatesAutoresizingMaskIntoConstraints = false
return comments
}()

override func viewDidLoad() {
super.viewDidLoad()

view.addSubview(postImage)
view.addSubview(postTitle)
view.addSubview(likesCounter)
view.addSubview(commentsTable)

postImage.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
postImage.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
postImage.topAnchor.constraint(equalTo: view.topAnchor, constant: 80).isActive = true
postImage.heightAnchor.constraint(equalToConstant: 400).isActive = true

postTitle.topAnchor.constraint(equalTo: postImage.bottomAnchor, constant: 10).isActive = true
postTitle.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
postTitle.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
postTitle.heightAnchor.constraint(equalToConstant: 30).isActive = true


likesCounter.topAnchor.constraint(equalTo: postTitle.bottomAnchor).isActive = true
likesCounter.leftAnchor.constraint(equalTo: postTitle.leftAnchor).isActive = true
likesCounter.heightAnchor.constraint(equalToConstant: 30).isActive = true
likesCounter.widthAnchor.constraint(equalToConstant: 250).isActive = true

commentsTable.topAnchor.constraint(equalTo: likesCounter.bottomAnchor, constant: 10).isActive = true
commentsTable.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
commentsTable.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
commentsTable.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
commentsTable.register(CommentTableViewCell.self, forCellReuseIdentifier: cellIdentifier)
commentsTable.dataSource = self
commentsTable.delegate = self

postTitle.text = postData.title
likesCounter.text = postData.likesCountText()
postData.load { img in
self.postImage.image = img
}

commentsService.getComments(postId: postData.id!) { data in
self.comments = data
}
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return comments?.count ?? 0
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = commentsTable.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath)
guard let comments = self.comments else {return cell}
cell.textLabel?.text = comments[indexPath.row].content
cell.detailTextLabel?.text = comments[indexPath.row].author!.name
return cell
}

}
6 changes: 6 additions & 0 deletions fakestagram/ViewControllers/PostsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,10 @@ class PostsViewController: UIViewController, UICollectionViewDelegate, UICollect
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: self.view.frame.width, height: 650)
}

func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) {
let postDetail = PostDetailController()
postDetail.postData = posts![indexPath.item]
navigationController?.pushViewController(postDetail, animated: true)
}
}
21 changes: 21 additions & 0 deletions fakestagram/Views/CommentTableViewCell.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// CommentTableViewCell.swift
// fakestagram
//
// Created by Ma. de Lourdes Chaparro Candiani on 05/02/20.
// Copyright © 2020 3zcurdia. All rights reserved.
//

import UIKit

class CommentTableViewCell: UITableViewCell {

override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: .subtitle, reuseIdentifier: reuseIdentifier)
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

}
1 change: 1 addition & 0 deletions fakestagram/Views/ShowPostViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class ShowPostViewController: UIViewController {
func onTapShowComments(_ sender: Any) {
print("to show comment")
}


/*
// MARK: - Navigation
Expand Down